5

このRSpecメソッドが機能しない理由について混乱しています。私はここで答えを見ていました:何らかの例外を除いてRSpecのshould_raiseを使用する方法は?提案されたすべての組み合わせを試しましたが、何らかの理由で、まだNoMethodErrorが発生しています。

これが例外です

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

方法は次のとおりです。

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

以前にこのエラーが発生したので、メソッドが実行したいことを実行していることがわかります。

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

私は走っています:

Rails3上のRSpec2.1.0、guard-spork0.3.2およびspork0.9.0

4

1 に答える 1

13

これはクラシックです!あなたはブロックを逃してい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
于 2012-07-06T21:25:06.857 に答える