Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get "including Capybara::DSL in the global scope is not recommended!"

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

$ 

My Gemfile has:

group :test, :development do
  gem 'rspec-rails'
  gem 'capybara'
end

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

If I comment out the include Capybara::DSL then my capybara methods like visit don't work.

like image 816
Michael Durrant Avatar asked Sep 04 '13 14:09

Michael Durrant


1 Answers

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.

Here's the correct way:

RSpec.configure do |config|
  config.include Capybara::DSL, :type => :feature
end
like image 195
Caleb Hearth Avatar answered Oct 19 '22 19:10

Caleb Hearth