为什么我为什么“不建议在全局范围内包含Capybara :: DSL!” [英] Why do I get "including Capybara::DSL in the global scope is not recommended!"
本文介绍了为什么我为什么“不建议在全局范围内包含Capybara :: DSL!”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每次我运行一个规范,即使该规范通过,例如
Everytime I run a spec, even if the spec passes, e.g.
$ rspec spec/integration/view_homepage_spec.rb
including Capybara::DSL in the global scope is not recommended!
.
Finished in 0.6174 seconds
1 example, 0 failures
Randomized with seed 14130
$
我的Gemfile具有:
My Gemfile has:
group :test, :development do
gem 'rspec-rails'
gem 'capybara'
end
我的spec_helper有:
My spec_helper has:
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara'
include Capybara::DSL
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
config.order = "random"
end
如果我注释掉 include capybara :: DSL
,然后像 visit
这样的capybara方法不起作用。
If I comment out the include Capybara::DSL
then my capybara methods like visit
don't work.
推荐答案
因为不建议在全局范围内包含 Capybara :: DSL
。
Because including Capybara::DSL
in the global scope is not recommended.
此在系统中全局包含许多方法,这些方法可能会干扰您自己的代码。
This includes many methods globally in the system, which could interfere with your own code.
这是正确的方法:
RSpec.configure do |config|
config.include Capybara::DSL, :type => :feature
end
这篇关于为什么我为什么“不建议在全局范围内包含Capybara :: DSL!”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文