Verwirrt, warum diese RSpec-Methode nicht funktioniert. Ich schaute mir die Antwort hier an: How to use RSpec's should_raise with any kind of exception? und habe alle vorgeschlagenen Kombinationen ausprobiert, aber aus irgendeinem Grund bekomme ich immer noch einen NoMethodError. HierFolgende rspec-Ausnahmebehandlung: "NoMethodError" für "expect" erhalten
ist die Ausnahme
Exception encountered: #<NoMethodError: undefined method `expect' for #<Class:0x007fa5bd8e4120>>
Hier wird die Methode:
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
ich diesen Fehler habe früher so weiß ich, dass meine Methode tut, was ich will es tun:
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
Ich bin am Laufen:
RSpec 2.1.0 auf Rails 3 mit guard-spork 0.3.2 und spork 0.9.0
In diesem Beispiel ist 'expect {} .should' veraltet, verwenden Sie' expect {} .to' –