[rspec-users] Rspec: `should': uninitialized constant RSpec::Expectations (NameError)

David K. lists at ruby-forum.com
Mon Dec 6 15:06:30 EST 2010


David Chelimsky wrote in post #966405:
> On Sun, Dec 5, 2010 at 6:19 PM, DK <structuralartistry at gmail.com> 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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

-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list