Rails 5.1使用RSpec配置内置系统测试
看完RailsConf video on ActionDispatch::systemTestCase之后,我很兴奋将它整合到我的当前应用程序中。目前,我们的测试套件安装使用以下:Rails 5.1使用RSpec配置内置系统测试
- rspec
- factory_girl
-
capybara
# for feature specs
-
database_cleaner
# for feature specs, mostly for testing js
-
selenium-webdriver
# for feature specs
-
capybara-webkit
# for feature specs
我们目前的配置很难得到配置,但我们最终得到了它的工作,主要归功于Avdi Grimm的一篇文章,标题为:Configuring database_cleaner with Rails, RSpec, Capybara, and Selenium。
我的希望是使用rails 5.1
中发布的rails的内置系统测试。由于导轨现已系统测试内置的:所有我需要担心的配置如下:
rspec
factory_girl
这是因为ActionDispatch::systemTestCase
需要照顾capybara
,database_cleaner
,并且已经为selenium
驱动程序进行了配置。
例如:目前我feature specs
写像这样(水豚RSpec的上下文中):
#spec/features/blogs/creating_blogs_spec.rb
require "rails_helper"
RSpec.feature "Logged in User can create a blog" do
before do
create(:logged_in_user)
end
scenario "successfully", js: true do
...
end
end
所以这是一个典型的集成/功能/系统规范可能是什么样子的配置测试套件与rspec
,database_cleaner
,factory_girl
和capybara
。我想将其转换为使用ActionDispatch::systemTestCase
。
但是,我想在RSpec
的范围内使用ActionDispatch::systemTestCase
。
上面的RailsConf上的视频显示ActionDispatch :: systemTestCase如何运作的轨道的默认测试套件布局(例如:minitest与位于test
目录测试)的范围内,但它并没有讨论如何使用ActionDispatch :: systemTestCase在RSpec的范围内。
我找不到任何资源可以使用RSpec对轨道的内置系统测试进行配置,包括在system testing section of the rails guides之内。这可能吗?
2017年10月更新:
Rspec-rails 3.7现在完全兼容系统测试。
基本上,这是所有你必须添加到您的spec_helper.rb
:
RSpec.configure do |config|
config.before(:each, type: :system) do
driven_by :rack_test
end
config.before(:each, type: :system, js: true) do
driven_by :selenium_chrome_headless
end
end
https://medium.com/table-xi/a-quick-guide-to-rails-system-tests-in-rspec-b6e9e8a8b5f6
根据RailsConf Talk:Teaching RSpec to Play nice with Rails,从rspec-rails 3.6.0
开始,它是而不是与rails的系统测试集成兼容。
看起来,兼容性正在通过this pull request进行处理。