RSpec and "uninitialized constant Features" error - ruby-on-rails

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:inconfigure'
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:inblock 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:inblock in requires='
from /home/jasiek/.rvm/gems/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:inrequires='
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:ineach'
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:inconfigure'
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:inrun'
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:ininvoke'
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:inload'
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:ineval'
from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/bin/ruby_executable_hooks:15:in `'

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'

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

Related

Failure/Error: config.include ::Rails::Controller::Testing::TemplateAssertions, type: :controller

I am trying to run a single test file: bundle exec rspec spec/models/user_spec.rb
But get following error:
An error occurred while loading ./spec/models/user_spec.rb.
Failure/Error: config.include ::Rails::Controller::Testing::TemplateAssertions, type: :controller
NameError:
uninitialized constant Rails::Controller
Did you mean? ApiController
# ./spec/rails_helper.rb:149:in `block in <top (required)>'
# ./spec/rails_helper.rb:61:in `<top (required)>'
# ./spec/models/user_spec.rb:3:in `require'
# ./spec/models/user_spec.rb:3:in `<top (required)>'
No examples found.
Initially, I was getting following error:
An error occurred while loading ./spec/models/user_spec.rb.
Failure/Error: module Shoulda::Matchers::ActiveModel
NameError:
uninitialized constant Shoulda
# ./spec/support/matchers/validate_kept_of_matcher.rb:4:in `<top (required)>'
# ./spec/rails_helper.rb:51:in `block in <top (required)>'
# ./spec/rails_helper.rb:51:in `each'
# ./spec/rails_helper.rb:51:in `<top (required)>'
# ./spec/models/user_spec.rb:3:in `require'
# ./spec/models/user_spec.rb:3:in `<top (required)>'
No examples found.
But then it fixed after I added following to the test file.
require "shoulda/matchers"
I am newbie in Ruby/Rails world, can someone please give a direction?
Rails::Controller::Testing::TemplateAssertions was removed in Rails 5.
You can re-add the depreciated functionality by installing the Rails controller testing gem. However the use of controller specs, assigns and template assertions is discouraged by both the RSpec and Rails teams and is not very future proof.
The community accepted solution is to write request specs and stop poking inside your controllers.

Message: Failure/Error: require File.expand_path('../../config/environment', __FILE__)

First i read other posts of users with similiar problems, but couldnt come along where my mistake is. I wanted to start a test with RSpec on the following file:
dashboard_view_spec.rb:
require 'rails_helper'
RSpec.feature "Dashboard", type: :feature do
before(:each) do
#current_user = User.create!(email: "xyz#xyz.com", password: "xyz123")
sign_in_with(#current_user.email,#current_user.password)
end
#NAV BAR RSPEC TEST
scenario 'Home bar nav link present' do
visit "/"
expect(page).to have_text('Home')
end
scenario 'How it work nav bar link present' do
visit "/"
expect(page).to have_text('How it work')
end
scenario 'Support nav bar link present' do
visit "/"
expect(page).to have_text('Support')
end
end
On rails_helper.rb on the top:
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rake'
require 'spec_helper'
require 'rspec/rails'
require 'shoulda/matchers'
require 'capybara/rails'
require 'capybara/rspec'
require 'rspec/retry'
require 'devise'
Error message:
Failure/Error: require File.expand_path('../../config/environment', __FILE__)
NoMethodError:
undefined method `[]' for nil:NilClass
# ./config/initializers/devise.rb:258:in `block in <top (required)>'
# ./config/initializers/devise.rb:5:in `<top (required)>'
# ./config/environment.rb:5:in `<top (required)>'
# ./spec/rails_helper.rb:4:in `require'
# ./spec/rails_helper.rb:4:in `<top (required)>'
# ./spec/views/dashboard_view_spec.rb:1:in `require'
# ./spec/views/dashboard_view_spec.rb:1:in `<top (required)>'
No examples found.
Randomized with seed 14549
Then the command i used on the terminal
bundle exec rspec spec/views/dashboard_view_spec.rb
After watching the documentation of testing with Devise i changed the code in dashboard_view_spec.rb and used to sign_in as a user and got the same error message.
Line 258 of devise.rb
config.omniauth :facebook, Rails.application.secrets.facebook[:key], Rails.application.secrets.facebook[:secret], scope: 'email', info_fields: 'email, name'
In the gemfile
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '~> 2.13'
gem 'selenium-webdriver'
gem 'rspec-rails', '~> 3.8'
gem 'factory_girl_rails'
gem 'faker'
gem 'database_cleaner'
end
and
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
The problem is that you're missing a variable that your devise initializer expects to find, but only missing it in the test environment. (not the development environment)
The stack trace that you provided and line 258 from config/initializers/devise.rb are all that are needed. First, let's look at the stack trace:
NoMethodError:
undefined method `[]' for nil:NilClass
# ./config/initializers/devise.rb:258:in `block in <top (required)>'
# ./config/initializers/devise.rb:5:in `<top (required)>'
# ./config/environment.rb:5:in `<top (required)>'
# ./spec/rails_helper.rb:4:in `require'
# ./spec/rails_helper.rb:4:in `<top (required)>'
# ./spec/views/dashboard_view_spec.rb:1:in `require'
# ./spec/views/dashboard_view_spec.rb:1:in `<top (required)>'
Starting from the bottom up, we can see that the first line of your spec is what's causing the issue. If you follow the stack you'll see that it ends up in config/initializers/devise.rb:258 and is complaining that something making a [] method call isn't getting the expected object type in return, and is instead getting nil in return.
Looking at line 258 you find:
config.omniauth :facebook, Rails.application.secrets.facebook[:key], Rails.application.secrets.facebook[:secret], scope: 'email', info_fields: 'email, name'
So you can see that there are two times that [] is called:
Rails.application.secrets.facebook[:key]
Rails.application.secrets.facebook[:secret]
What is expected is that calling Rails.application.secrets.facebook will return an Enumerable object (like an array or a hash) but instead it is returning nil, and when it attempts to run nil[:key] or nil[:secret] it raises an exception because NilClass is not an Enumerable and does not have a [] method. You can test this yourself in the rails console:
nil[:secret]
=> NoMethodError: undefined method `[]' for nil:NilClass
The solution is to ensure that calling Rails.application.secrets.facebook returns the expected object type. The short answer is to edit config/secrets.yml to ensure that the values you require for the test environment are present.
I haven't worked with devise in a long time, but I assume that you can safely use the same values that you're using for the development environment for the test environment. You can read more about secrets() elsewhere, but the basic template for config/secrets.yml is as follows:
environment:
key: value
For example:
test:
my_secret_key: my_secret_value
It should be fairly straightforward to copy and paste the missing facebook secrets into the test environment. After making the change you can verify it worked:
$ RAILS_ENV=test rails console
Rails.application.secrets.facebook[:key]
=> <your key here>
If that worked, then run your spec with rspec and it should successfully get past line 1. (assuming there are no other bugs or missing secrets)
I had very similar errors. Here's how I solved
Run rspec --backtrace
This could produce a lot of console output. Scroll right to the top, and start reading from the top. It will tell you the file your problem started in, and the line it happened on. Go to that file (and that line), and figure out what's missing.
In my case, it was actually a missing variable in credentials.yml, but cases will vary. Like in the excellent answer by #anothermh, it's basically telling you something is missing, so you have to figure out what's missing and make sure you provide it.
Just got the same error, but when I ran bundle exec rake spec instead of bundle exec rspec it worked.

NoMethodError: undefined method `[]' for nil:NilClass for assets:precompile on heroku

An app using devise and omniauth is working well on localhost, but when I deploy it on heroku, I get an error:
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
NoMethodError: undefined method `[]' for nil:NilClass
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/config/initializers/omniauth.rb:6:in `block in <top (required)>'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/omniauth-1.2.2/lib/omniauth/builder.rb:6:in `initialize'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.4/lib/action_dispatch/middleware/stack.rb:43:in `new'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.4/lib/action_dispatch/middleware/stack.rb:43:in `build'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.4/lib/action_dispatch/middleware/stack.rb:118:in `block in build'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.4/lib/action_dispatch/middleware/stack.rb:118:in `each'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.4/lib/action_dispatch/middleware/stack.rb:118:in `inject'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.4/lib/action_dispatch/middleware/stack.rb:118:in `build'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/railties-4.1.4/lib/rails/engine.rb:498:in `app'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/railties-4.1.4/lib/rails/application/finisher.rb:36:in `block in <module:Finisher>'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `instance_exec'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `run'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/railties-4.1.4/lib/rails/initializable.rb:55:in `block in run_initializers'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/railties-4.1.4/lib/rails/initializable.rb:54:in `run_initializers'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/railties-4.1.4/lib/rails/application.rb:300:in `initialize!'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/config/environment.rb:5:in `<top (required)>'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `block in require'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:232:in `load_dependency'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/railties-4.1.4/lib/rails/application.rb:276:in `require_environment!'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/railties-4.1.4/lib/rails/application.rb:379:in `block in run_tasks_blocks'
/tmp/build_e711adadeab2d8cb9d37632e4c0ba08b/vendor/bundle/ruby/2.1.0/gems/sprockets-rails-2.2.2/lib/sprockets/rails/task.rb:64:in `block (2 levels) in define'
Tasks: TOP => environment
(See full trace by running task with --trace)
!
! Precompiling assets failed.
!
! Push rejected, failed to compile Ruby app
To git#heroku.com:my-app.git
! [remote rejected] master -> master (pre-receive hook declined)
Here is Gemfile and omniauth files:
#Gemfile:
#....
gem 'google-api-client'
gem 'omniauth'
gem 'omniauth-google-oauth2'
gem 'devise'
#.....
#config/initializers/omniauth.rb
# probably this isn't necessary
if Rails.env.production?
OmniAuth.config.full_host = 'https://my-app.herokuapp.com'
end
# but it is necessary
Rails.application.config.middleware.use OmniAuth::Builder do
provider(:google_oauth2, $ga_client['client_id'], $ga_client['client_secret'],
{ scope: 'userinfo.profile, userinfo.email, analytics', access_type: 'offline', prompt: 'consent' }
)
end
In your code, $ga_client is nil. You are not defining such an array anywhere in your file and, in case is defined in other place, it's not loaded at the time this initializer is executed.
Try setting the client_id and client_secret with environment variables, as recommended in the docs.
provider :google_auth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET']
The globals variables weren't initialized:
# but it is necessary
Rails.application.config.middleware.use OmniAuth::Builder do
provider(:google_oauth2, $ga_client['client_id'], $ga_client['client_secret'],
{ scope: 'userinfo.profile, userinfo.email, analytics', access_type: 'offline', prompt: 'consent' }
)
end
# ops $ga_client is nil
I discovered it when I replaced the code above with:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"]
end
I was having the same problem. The cause of this problem is that Rails uses a database system called sqlite3, Heroku does not use this database. To fix this, go into your Gemfile and scroll down until you see something which will look a bit like this
group :development, :test do
gem 'byebug'
gem 'web-console', '~> 2.0'
end
Note: If you are using any versions lower than Rails 4.0.0, you will not have this group, simply create it.
Now somewhere at the top of your Gemfile, will be a line which says
gem 'sqlite3'
Move this line into the Development, Test Group This now will only run in development. You can now try creating your Heroku app again by writing
$ heroku create
Then you may need to migrate your database. Do this by running
$ rake db:migrate
Now push to Heroku
$ heroku push
That should work!
Hope I helped ;)

RSpec verbose error messages

When I run any RSpec test that fails, I get many lines of messages that I don't really understand.
For instance, suppose I run:
expect(true).to be_false
Then my console gets cluttered with messages beginning with #
Failures:
1) Some test
Failure/Error: expect(true).to be_false
expected true to respond to `false?`
# ./spec/controllers/wing_relationships_controller_spec.rb:43:in `block (3 levels) in <top (required)>'
# /Users/mac/.rvm/gems/ruby-2.1.2#global/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:in `load'
# /Users/mac/.rvm/gems/ruby-2.1.2#global/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:in `block in load'
# /Users/mac/.rvm/gems/ruby-2.1.2#global/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:232:in `load_dependency'
# /Users/mac/.rvm/gems/ruby-2.1.2#global/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:in `load'
# /Users/mac/.rvm/gems/ruby-2.1.2#global/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:in `load'
# /Users/mac/.rvm/gems/ruby-2.1.2#global/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:in `block in load'
# /Users/mac/.rvm/gems/ruby-2.1.2#global/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:232:in `load_dependency'
# /Users/mac/.rvm/gems/ruby-2.1.2#global/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:in `load'
# -e:1:in `<main>'
The error messages always vary, and sometimes they are extremely long.
When I run many tests, it gets hard to read the results. I would like to get rid of those. Any suggestions? I already turned off --warning in RSpec
It's better find out where the errors come from and fix the leaky specs rather the ignoring the errors.
If you are not interested in doing it for some reason then you can always use:
You use a simple trick if you really want to:
rspec 2>/dev/null
Got this answer from https://github.com/rspec/rspec-rails/issues/1237
To remove the gems from the output, it's one line of config:
RSpec.configure do |config|
config.backtrace_exclusion_patterns << %r{/gems/}
end
Or, if you want to only filter out particular gems from your backtraces:
RSpec.configure do |config|
config.filter_gems_from_backtrace "rack", "rack-test", "capybara"
end

Devise & Rspec Test Integration

I'm trying to run tests with Devise and Rspec and have been unsuccessful thus far - any help would be greatly appreciated.
rake spec:requests --trace
gives me this error
`/Users/carl/.rvm/rubies/ruby-1.9.2-head/bin/ruby -S rspec ./spec/requests/users_spec.rb
/Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:503:in ‘load_missing_constant': Expected /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/devise-2.1.2/app/controllers/devise_controller.rb to define DeviseController (LoadError)
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:192:in ‘block in const_missing'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in ‘each'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in ‘const_missing'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/devise-2.1.2/app/controllers/devise/sessions_controller.rb:1:in ‘<top (required)>'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘block in require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in ‘load_dependency'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:359:in ‘require_or_load'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:502:in ‘load_missing_constant'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:192:in ‘block in const_missing'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in ‘each'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in ‘const_missing'
from /Users/carl/rails_projects/my_rails_app_name/app/controllers/application_controller.rb:14:in ‘<class:ApplicationController>'
from /Users/carl/rails_projects/my_rails_app_name/app/controllers/application_controller.rb:1:in ‘<top (required)>'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘block in require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in ‘load_dependency'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:359:in ‘require_or_load'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:502:in ‘load_missing_constant'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:192:in ‘block in const_missing'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in ‘each'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in ‘const_missing'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/inflector/methods.rb:229:in ‘block in constantize'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/inflector/methods.rb:228:in ‘each'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/inflector/methods.rb:228:in ‘constantize'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/core_ext/string/inflections.rb:54:in ‘constantize'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/devise-2.1.2/app/controllers/devise_controller.rb:2:in ‘<top (required)>'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘block in require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in ‘load_dependency'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:359:in ‘require_or_load'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:502:in ‘load_missing_constant'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:192:in ‘block in const_missing'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in ‘each'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in ‘const_missing'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/devise-2.1.2/app/controllers/devise/confirmations_controller.rb:1:in ‘<top (required)>'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘block in require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in ‘load_dependency'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in ‘require'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:359:in ‘require_or_load'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:313:in ‘depend_on'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:225:in ‘require_dependency'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/engine.rb:439:in ‘block (2 levels) in eager_load!'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/engine.rb:438:in ‘each'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/engine.rb:438:in ‘block in eager_load!'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/engine.rb:436:in ‘each'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/engine.rb:436:in ‘eager_load!'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/application/railties.rb:8:in ‘each'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/application/railties.rb:8:in ‘all'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/engine.rb:434:in ‘eager_load!'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/application/finisher.rb:53:in ‘block in <module:Finisher>'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/initializable.rb:30:in ‘instance_exec'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/initializable.rb:30:in ‘run'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/initializable.rb:55:in ‘block in run_initializers'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/initializable.rb:54:in ‘each'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/initializable.rb:54:in ‘run_initializers'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/application.rb:136:in ‘initialize!'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in ‘method_missing'
from /Users/carl/rails_projects/my_rails_app_name/config/environment.rb:5:in ‘<top (required)>'
from /Users/carl/rails_projects/my_rails_app_name/spec/spec_helper.rb:3:in ‘require'
from /Users/carl/rails_projects/my_rails_app_name/spec/spec_helper.rb:3:in ‘<top (required)>'
from /Users/carl/rails_projects/my_rails_app_name/spec/requests/users_spec.rb:1:in ‘require'
from /Users/carl/rails_projects/my_rails_app_name/spec/requests/users_spec.rb:1:in ‘<top (required)>'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in ‘load'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in ‘block in load_spec_files'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in ‘map'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in ‘load_spec_files'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:22:in ‘run'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in ‘run'
from /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in ‘block in autorun'
rake aborted!
/Users/carl/.rvm/rubies/ruby-1.9.2-head/bin/ruby -S rspec ./spec/requests/users_spec.rb failed
/Users/carl/.rvm/gems/ruby-1.9.2-head/gems/rspec-core-2.11.1/lib/rspec/core/rake_task.rb:137:in ‘block (2 levels) in initialize'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/file_utils_ext.rb:60:in ‘verbose'
/Users/carl/.rvm/gems/ruby-1.9.2-head/gems/rspec-core-2.11.1/lib/rspec/core/rake_task.rb:127:in ‘block in initialize'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in ‘call'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in ‘block in execute'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in ‘each'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in ‘execute'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in ‘block in invoke_with_call_chain'
/Users/carl/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/monitor.rb:201:in ‘mon_synchronize'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in ‘invoke_with_call_chain'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in ‘invoke'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in ‘invoke_task'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in ‘block (2 levels) in top_level'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in ‘each'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in ‘block in top_level'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in ‘standard_exception_handling'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in ‘top_level'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in ‘block in run'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in ‘standard_exception_handling'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in ‘run'
/Users/carl/.rvm/gems/ruby-1.9.2-head#global/gems/rake-0.9.2.2/bin/rake:33:in ‘<top (required)>'
/Users/carl/.rvm/gems/ruby-1.9.2-head/bin/rake:19:in ‘load'
/Users/carl/.rvm/gems/ruby-1.9.2-head/bin/rake:19:in ‘<main>'
`
Gemfile for :development, :test
gem 'sqlite3'
gem 'rspec-rails'
gem 'capybara'
spec/requests/user_spec.rb
> `require 'spec_helper'
>
> describe "Users" do
> describe "GET /" do
> it "goes to homepage" do
> visit '/'
> response.status.should be(200)
> end
> end
> end`
spec/spec_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'
#require 'capybara/rails'
# Note: To create integration test: $rails g integration_test blah --integration-tool=rspec
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
# Include devise in Rspec tests
config.include Devise::TestHelpers, :type => :controller
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
end
I don't know exactly what is going wrong, but a quick search for LoadError and the "Expected ... to define" pattern brought up a few relevant discussions.
Expected ... to Define
Rails 3.1 — 'load_missing_contant': Expected ... to define ... (LoadError)
Expected x.rb to define X (LoadError)
Rails: Why does RSpec crash on my overridden Devise controller request spec?
From the first link:
The error message is misleading. Expected foo.rb to define Foo usually
just means that something bad happened when loading foo.rb (syntax
errors, missing constant etc...). You can usually get a better error
message by just typing Foo into script/console
The error is coming directly from Devise, so perhaps there is some naming conflict in your controllers with the devise controllers? I don't use devise so I don't really know much about how it works. Although I doubt that it's the problem, have a look at the file /Users/carl/.rvm/gems/ruby-1.9.2-head/gems/devise-2.1.2/app/controllers/devise_controller.rb and make sure it's not corrupted. You might try to reinstall the gem in rvm.
A friend helped me figure this one out. In my application controller I was overriding Devise with the below code. Commenting this out allowed rake spec:requests to pass successfully.
# ===============================================
# == Commented this out to make rspec tests work
# ===============================================
# Override Devise create session controller
# Devise::SessionsController.class_eval do
# def create
# resource = warden.authenticate!(auth_options)
# set_flash_message(:notice, :signed_in) if is_navigational_format?
# sign_in(resource_name, resource)
# #sign_in_path = after_sign_in_path_for(resource)
# end
# end
Thank you again for your time and help!

Resources