Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Following rspec exception handling, getting 'NoMethodError' for 'expect'

Confused as to why this RSpec method isn't working. I was looking at the answer here: How to use RSpec's should_raise with any kind of exception? and have tried all the combinations proposed but for some reason, I'm still getting a NoMethodError.

Here is the exception

Exception encountered: #<NoMethodError: undefined method `expect' for #<Class:0x007fa5bd8e4120>>

Here is the method:

describe "admin should not be accesible" do
expect { User.new(name: "Example Name", email: "[email protected]", password:    "foobar", password_confirmation: "foobar", admin: "true") }.should raise_error(ActiveModel::MassAssignmentSecurity::Error)
end

I got this error earlier so I know that my method is doing what I want it to do:

1) User admin should not be accesible
Failure/Error: hey = User.new(name: "Hello", email: "[email protected]", password: "foobar", password_confirmation: "foobar", admin: "true")
 ActiveModel::MassAssignmentSecurity::Error:
   Can't mass-assign protected attributes: admin

I am running:

RSpec 2.1.0 on Rails 3 with guard-spork 0.3.2 and spork 0.9.0

like image 821
ovatsug25 Avatar asked Jul 06 '12 21:07

ovatsug25


1 Answers

this is a classic! you are missing the it block!

describe "admin should not be accesible" do
  it "should bla" do
    expect { User.new(name: "Example Name", email: "[email protected]", password:    "foobar", password_confirmation: "foobar", admin: "true") }.should raise_error(ActiveModel::MassAssignmentSecurity::Error)
  end
end
like image 76
phoet Avatar answered Nov 15 '22 11:11

phoet