Recently, I am trying to integrate rspec and capybara with sinatra (see here). But when I try to run my test file, I get below error
undefined method `visit’ for #<RSpec::Core::ExampleGroup::Nested_1:0x9209d5c @example=nil>
I find it strange, as I have configured capybara many a time with rails and it work smoothly. I get some hint of problem here on stack overflow.
visit is a method defined by capybara over rspec layer i,e it is DSL (domain specific language). when working with rails, capybara DSL module is automatically loaded by rails when rspec is loaded, but with sinatra, this is not happening. So we have to include Capybara::DSL in the file we want to use its method. I have added the include line in my spec_helper.rb file which is required in my all other test files.
SOLUTION : add include Capybara::DSL to your configuration file or the individual test file
My, spec_helper.rb file look like this
require 'capybara' include Capybara::DSL # Adding this line solved the error Capybara.default_driver = :selenium def app Sinatra::Application end set :environment, :test RSpec.configure do |config| config.treat_symbols_as_metadata_keys_with_true_values = true config.run_all_when_everything_filtered = true config.filter_run :focus config.order = 'random' end