如何将RSpec / Capybara测试放在spec / requests目录之外?

时间:2012-08-15 21:18:33

标签: ruby-on-rails capybara rspec2

出于某种原因,我的团队不希望我们的验收测试存在于spec / requests目录中。相反,他们希望将它们放在一个名为accepted的新目录中,该目录存在于spec目录结构之外。所以,我的第一个问题是,使用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目录中,而没有一些非常强大的参数来备份为什么这是唯一的选择。

1 个答案:

答案 0 :(得分:0)

我做过类似的事情,我在spec/acceptance中使用了我的规范,用:acceptance => true标记了它们,并使用单独的rake任务rake spec:acceptance

运行它们

查看这个要点 - https://gist.github.com/3858851

希望有所帮助