Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8194131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:43:04+00:00 2026-06-07T04:43:04+00:00

Confused as to why this RSpec method isn’t working. I was looking at the

  • 0

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@example.org", 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: "hey@hey.org", 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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:43:07+00:00Added an answer on June 7, 2026 at 4:43 am

    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@example.org", password:    "foobar", password_confirmation: "foobar", admin: "true") }.should raise_error(ActiveModel::MassAssignmentSecurity::Error)
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm confused about this. Most of us have been told that there isn't any
I'm totally confused on this matter, some say use tables and others say it's
I'm confused why this is ot working: var blocks = document.getElementsByTagName(td); var i =
I am so confused on this. I want to use the SQL Server on
I am little confused with this code am looking for somenthing similar i have
I am really confused with this one. Here's my code class inner { var
I am very confused about this... Here is an extract from my code.. float
I am very confused with this kind of casting. Can someone explain what exactly
I'm very confused about this error message, I'm completely unaware of any missing controllers
I´m littel confused with this reserve key and cases caused errors. Here a sample

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.