为什么我得到“不推荐在全局范围内包含 Capybara::DSL!"; [英] Why do I get "including Capybara::DSL in the global scope is not recommended!"

查看:19
本文介绍了为什么我得到“不推荐在全局范围内包含 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 这样的水豚方法将不起作用.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆