After handling rspec exceptions, get 'NoMethodError' for 'expect'

It is vague why this RSpec method does not work. I looked at the answer here: How to use RSpec's should_raise with any exception? and tried all the suggested combinations, but for some reason I still get a NoMethodError.

Here is the exception

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

Here is a way:

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

I got this error before, so I know that my method does what I want:

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

I run:

RSpec 2.1.0 on Rails 3 with protective veneer 0.3.2 and spork 0.9.0

+5
source share
1 answer

This is a classic! you are missing a block it!

describe "admin should not be accesible" do
  it "should bla" do
    expect { User.new(name: "Example Name", email: "email@example.org", password:    "foobar", password_confirmation: "foobar", admin: "true") }.should raise_error(ActiveModel::MassAssignmentSecurity::Error)
  end
end
+13
source

All Articles