简体   繁体   中英

RSpec and “uninitialized constant Features” error

When I run rspec test I get:

/home/jasiek/Desktop/katowice-ror-workshops-2015/spec/support/features.rb:2:in `block in ': uninitialized constant Features (NameError)

I suppose problem is only on my local machine because this is repo from trust source (another users haven't got this problem). The repo I'm talking about: https://github.com/netguru-training/katowice-ror-workshops-2015

I read on Stack that the problem could be missing line:

Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }

But I've got it.

Where could be a problem?

And this is a whole log from console:

jasiek@jasiek-HP-EliteBook-8470p:~/Desktop/katowice-ror-workshops-2015$ RAILS_ENV=test bundle exec rspec /home/jasiek/Desktop/katowice-ror-workshops-2015/spec/support/features.rb:2:in block in <top (required)>': uninitialized constant Features (NameError) from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core.rb:97:in configure' from /home/jasiek/Desktop/katowice-ror-workshops-2015/spec/support/features.rb:1:in <top (required)>' from /home/jasiek/Desktop/katowice-ror-workshops-2015/spec/rails_helper.rb:23:in block in ' from /home/jasiek/Desktop/katowice-ror-workshops-2015/spec/rails_helper.rb:23:in each' from /home/jasiek/Desktop/katowice-ror-workshops-2015/spec/rails_helper.rb:23:in ' from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/configuration.rb:1280:in require' from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/configuration.rb:1280:in block in requires=' from /home/jasiek/.rvm/gem s/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/configuration.rb:1280:in each' from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/configuration.rb:1280:in requires=' from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/configuration_options.rb:109:in block in process_options_into' from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/configuration_options.rb:108:in each' from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/configuration_options.rb:108:in process_options_into' from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/configuration_options.rb:21:in configure' from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/runner.rb:101:in setup' from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/runner.rb:88:in run' from /home/jasiek/.rvm/gems/ruby-2.2. 0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/runner.rb:73:in run' from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/runner.rb:41:in invoke' from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/exe/rspec:4:in <top (required)>' from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/bin/rspec:23:in load' from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/bin/rspec:23:in <main>' from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/bin/ruby_executable_hooks:15:in eval' from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/bin/ruby_executable_hooks:15:in `'

Try adding the following in your spec/support/features.rb file:

require '../../spec/support/features/session_helpers'

So, it becomes:

require '../../spec/support/features/session_helpers'

RSpec.configure do |config|
  config.include Features::SessionHelpers, type: :feature
end

I know its late.

But for other people who may come here for searching the answer. I was facing the same issue. So when I checked rails_helper.rb file inside spec I found that this line

Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }

was commented initially so I un-commented it and everything worked fine. I am using

gem 'capybara', '~> 2.15', '>= 2.15.4'
gem 'rspec-rails', '~> 3.6'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM