出于某种原因,我的团队不希望我们的验收测试存在于 spec/requests 目录中。相反,他们希望将它们放置在规范目录结构之外的一个名为接受的新目录中。所以,我的第一个问题是,使用 RSpec、Capybara 和 capybara-webkit,这是否可能?
这是我的acceptance_spec_helper.rb 文件
require 'rubygems'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'
require 'capybara/rails'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
# Capybara.javascript_driver = :webkit
RSpec.configure do |config|
config.include RSpec::Rails::RequestExampleGroup, :type => :request, :example_group => {
:file_path => config.escaped_path(%w[acceptance])
}
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
end
但是,看起来应用程序实际上并不是为了进行测试而运行的。
并且请不要只是说将测试放回 spec/requests 目录而没有一些非常有力的论据来支持为什么这是唯一的选择。