在 RSpec 测试中,是否有任何方法,按照惯例或代码,让 rails 在测试运行之前启动?我正在尝试为使用 chrome 的 selenium 测试设置一个测试框架,现在我只是因为缺少正在运行的服务器而受阻。
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/integration
或 spec/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 测试运行。
关于ruby-on-rails - 在 rspec 测试之前启动 rails?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8290106/