Rspec: `should': uninitialized constant RSpec::Expectations (NameError)

Hi all, anyone have an idea why I am getting an error trying to ‘rake
spec’:

‘kernel.rb:27:in `should’: uninitialized constant RSpec::Expectations
(NameError)’.

Can’t seem to find a useful reference online to solve. This project I
was working on a few months ago and got put aside, meanwhile I rebuilt
my mac. So something is off but not sure what.

Using rvm, Rails 3.0.3, Ruby 1.9.2, my gemfile.lock installs fine and
shows the following for rspec. I actually deleted my rvm gemset and re-
installed the bundle just in case but same error.

Gemfile.lock
rspec (2.2.0)
rspec-core (~> 2.2)
rspec-expectations (~> 2.2)
rspec-mocks (~> 2.2)
rspec-core (2.2.1)
rspec-expectations (2.2.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.2.0)
rspec-rails (2.2.1)
actionpack (~> 3.0)
activesupport (~> 3.0)
railties (~> 3.0)
rspec (~> 2.2.0)

Gemfile:

group :development, :test do
gem ‘ruby-debug19’
gem ‘cucumber-rails’
gem ‘cucumber’, ‘>=0.8.5’
gem ‘capybara’
gem ‘rspec-rails’
gem ‘factory_girl_rails’
gem ‘webrat’, ‘>=0.4.3’
gem ‘heroku’
gem ‘database_cleaner’
end

Thanks,

David

On Sun, Dec 5, 2010 at 6:19 PM, DK [email protected] wrote:

Hi all, anyone have an idea why I am getting an error trying to ‘rake
spec’:

‘kernel.rb:27:in `should’: uninitialized constant RSpec::Expectations
(NameError)'.

Looking through the code I can see why this might be happening, but
I’m at a loss as to why it’s happening to you and not to everybody.

I think you can work around it for now by requiring “rspec/matchers”
in your spec_helper file. I’d recommend doing so immediately after
require “rspec/core”. Please report back as to whether this works.

While you do that, I’ll try to reproduce the error here and resolve it
in a definitive way.

Cheers,
David

El 06/12/2010, a las 01:19, DK escribi:

Hi all, anyone have an idea why I am getting an error trying to ‘rake
spec’:

‘kernel.rb:27:in `should’: uninitialized constant RSpec::Expectations
(NameError)’.

Can you paste the full backtrace and the code of the spec which is
causing this failure?

It wouldn’t surprise me if you had a naked example – ie. nested inside
a “describe/context” block, without an “it” block.

I had one such example in an application with thousands of specs, so it
slipped by unnoticed for a long while, but on moving to RSpec 2.1.0 this
kind of latent bug is no longer tolerated. If you use a few levels of
nesting to organize your specs it is quite possible for this kind of
mistake to creep in.

Cheers,
Wincent

Wincent C. wrote in post #966456:

El 06/12/2010, a las 01:19, DK escribi:

Hi all, anyone have an idea why I am getting an error trying to ‘rake
spec’:

‘kernel.rb:27:in `should’: uninitialized constant RSpec::Expectations
(NameError)’.

Can you paste the full backtrace and the code of the spec which is
causing this failure?

It wouldn’t surprise me if you had a naked example – ie. nested inside
a “describe/context” block, without an “it” block.

I had one such example in an application with thousands of specs, so it
slipped by unnoticed for a long while, but on moving to RSpec 2.1.0 this
kind of latent bug is no longer tolerated. If you use a few levels of
nesting to organize your specs it is quite possible for this kind of
mistake to creep in.

Ahh… Wincent, you are right. Exactly the problem… so it was
tolerated on an older version, and I was stuck thinking it was a
configuration issue. Appreciated!

Cheers,
Wincent

David C. wrote in post #966405:

On Sun, Dec 5, 2010 at 6:19 PM, DK [email protected] wrote:

Hi all, anyone have an idea why I am getting an error trying to ‘rake
spec’:

‘kernel.rb:27:in `should’: uninitialized constant RSpec::Expectations
(NameError)'.

Looking through the code I can see why this might be happening, but
I’m at a loss as to why it’s happening to you and not to everybody.

I think you can work around it for now by requiring “rspec/matchers”
in your spec_helper file. I’d recommend doing so immediately after
require “rspec/core”. Please report back as to whether this works.

While you do that, I’ll try to reproduce the error here and resolve it
in a definitive way.

Thanks so much for the response. For some reason the group would not let
me add my correct email (dk at structuralartistry.com) so I did not get
advised you had responded.

Before I noticed that you responded, I tried creating a new rails app
(3.0.3 also) and got the same error, so either it is affecting others or
my environment is messed up.

Anyhow… based on your feedback:
I tried changing my spec_helper to this at 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)
require ‘rspec/rails’
require ‘rspec/matchers’
require ‘ruby-debug’

But to no avail…

Also noticed that there is no reference to ‘rspec/core’, but when I
added it, same result.

Following is the actual spec (truncated to the failing line):

require ‘spec_helper’

describe User do

before(:all) do
Factory.create(:sysadmin_role)
Factory.create(:practice_admin_role)
Factory.create(:practice_user_role)
end

describe “user authorization - guest role” do
user = User.new
user.authorize(‘activations’, ‘create’)[:success].should == true
end

And the backtrace:

/Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-expectations-2.2.0/lib/rspec/expectations/extensions/kernel.rb:27:in
should': uninitialized constant RSpec::Expectations (NameError) from /Users/DK/Documents/ror/projects/wavelineup3/spec/models/user_spec.rb:14:in block (2 levels) in <top (required)>’
from
/Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/example_group.rb:131:in
module_eval' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/example_group.rb:131:in subclass’
from
/Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/example_group.rb:118:in
describe' from /Users/DK/Documents/ror/projects/wavelineup3/spec/models/user_spec.rb:12:in block in <top (required)>’
from
/Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/example_group.rb:131:in
module_eval' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/example_group.rb:131:in subclass’
from
/Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/example_group.rb:118:in
describe' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/extensions/object.rb:6:in describe’
from
/Users/DK/Documents/ror/projects/wavelineup3/spec/models/user_spec.rb:3:in
<top (required)>' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/configuration.rb:327:in block in load_spec_files’
from
/Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/configuration.rb:327:in
map' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/configuration.rb:327:in load_spec_files’
from
/Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/command_line.rb:18:in
run' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/runner.rb:55:in run_in_process’
from
/Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/runner.rb:46:in
run' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/rspec-core-2.2.1/lib/rspec/core/runner.rb:10:in block in autorun’
rake aborted!
ruby -S bundle exec rspec “./spec/mailers/system_mailer_spec.rb”
“./spec/models/practice_member_spec.rb” “./spec/models/practice_spec.rb”
“./spec/models/role_spec.rb” “./spec/models/travel_card_spec.rb”
“./spec/models/user_session_spec.rb” “./spec/models/user_spec.rb” failed

Cheers,
David