在rspec测试之前启动rails



在RSpec测试中是否有任何方法,通过约定或代码,在测试运行之前启动rails ?我正在尝试为使用chrome的硒测试设置一个测试框架,现在我只受到缺乏运行服务器的阻碍。

require 'spec_helper'
describe 'The first tab' do
  before(:each) do
    @driver = Selenium::WebDriver.for :chrome
  end
  it 'Shows the list' do
    @driver.navigate.to 'index.html'
  end
end

我是RSpec的新手,所以我不确定我将如何创建一套测试,所有的运行,而rails服务器正在运行

您应该使用Capybara来测试这些内容。它在内部使用selenium-webdriver提供JavaScript测试支持。

使用Capybara,您将此测试放在spec/integrationspec/requests文件夹中,并像这样写:

require 'spec_helper'
describe 'The first tab' do
  it "shows the list", :js => true do
    visit list_path
  end
end

通过将:js => true放在示例的名称之后,Capybara将知道将其作为JavaScript测试运行

只要运行rails server并在测试完成时终止进程。

最新更新