Lilp
Lilp

Reputation: 971

Uninitialized constant RSpec when adding gem

I am creating some automated tests using Cucumber and Capybara. I want to add the Touch Action gem (https://github.com/Ricardonacif/touch_action). I added the gem and then in my env file required it but i am getting the following error. I am really confused as to whether i should be creating a separate helper file but i tried something along these lines and still got the same error. Could anyone offer any advice as to how to resolve this?

    uninitialized constant RSpec (NameError)
/Users/em/.rvm/gems/ruby-2.1.1/gems/touch_action-1.3.0/lib/touch_action/capybara_rspec_helper.rb:17:in `<top (required)>'
/Users/em/.rvm/gems/ruby-2.1.1/gems/touch_action-1.3.0/lib/touch_action.rb:12:in `require'
/Users/em/.rvm/gems/ruby-2.1.1/gems/touch_action-1.3.0/lib/touch_action.rb:12:in `<top (required)>'
/Users/em/reallyenglish/learning_specs/learning-platform-specs/features/support/env.rb:3:in `require'
/Users/em/reallyenglish/learning_specs/learning-platform-specs/features/support/env.rb:3:in `<top (required)>'
/Users/em/.rvm/gems/ruby-2.1.1/gems/cucumber-2.0.0/lib/cucumber/rb_support/rb_language.rb:94:in `load'
/Users/em/.rvm/gems/ruby-2.1.1/gems/cucumber-2.0.0/lib/cucumber/rb_support/rb_language.rb:94:in `load_code_file'
/Users/em/.rvm/gems/ruby-2.1.1/gems/cucumber-2.0.0/lib/cucumber/runtime/support_code.rb:237:in `load_file'
/Users/em/.rvm/gems/ruby-2.1.1/gems/cucumber-2.0.0/lib/cucumber/runtime/support_code.rb:97:in `block in load_files!'
/Users/em/.rvm/gems/ruby-2.1.1/gems/cucumber-2.0.0/lib/cucumber/runtime/support_code.rb:96:in `each'
/Users/em/.rvm/gems/ruby-2.1.1/gems/cucumber-2.0.0/lib/cucumber/runtime/support_code.rb:96:in `load_files!'
/Users/em/.rvm/gems/ruby-2.1.1/gems/cucumber-2.0.0/lib/cucumber/runtime.rb:242:in `load_step_definitions'
/Users/em/.rvm/gems/ruby-2.1.1/gems/cucumber-2.0.0/lib/cucumber/runtime.rb:65:in `run!'
/Users/em/.rvm/gems/ruby-2.1.1/gems/cucumber-2.0.0/lib/cucumber/cli/main.rb:38:in `execute!'
/Users/em/.rvm/gems/ruby-2.1.1/gems/cucumber-2.0.0/bin/cucumber:9:in `<top (required)>'
/Users/em/.rvm/gems/ruby-2.1.1/bin/cucumber:23:in `load'
/Users/em/.rvm/gems/ruby-2.1.1/bin/cucumber:23:in `<main>'
/Users/em/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
/Users/em/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `<main>'

Gemfile

source "https://rubygems.org"

gem 'rake'
gem 'touch_action'

group(:test) do
  gem 'cucumber'
  gem 'capybara'
  gem 'rspec'
  gem 'selenium-webdriver'
end

env.rb

require 'capybara'
require 'capybara/cucumber'
require 'touch_action'

Capybara.configure do |config|
    config.default_selector = :css
  config.default_driver = :selenium
  config.app_host   = 'http://testem.co.uk
    # Capybara.ignore_hidden_elements = false --video testing
    config.include Capybara::DSL
end

After do
  page.execute_script("window.localStorage.clear()")
end

Upvotes: 0

Views: 518

Answers (1)

dax
dax

Reputation: 10997

After our chat discussion, it seems that touch-action needs rspec to be explicitly required. Your env.rb file should look like this:

require 'rspec'
require 'capybara'
require 'capybara/cucumber'
require 'touch_action'

Upvotes: 1

Related Questions