5
Bu RSpec yönteminin neden çalışmadığı konusunda karışık. Buradaki cevaba bakıyordum: How to use RSpec's should_raise with any kind of exception? ve önerilen tüm kombinasyonları denedim ama bir nedenden dolayı hala bir NoMethodError alıyorum.rspec kural dışı durumlarını izleyerek, 'beklemek' için 'NoMethodError' almak
: bu yüzden benim yöntem bunu yapmak istediğinizi yaptığını biliyoruzdescribe "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
Daha önce bu hata var: Burada
yöntem istisna İşteException encountered: #<NoMethodError: undefined method `expect' for #<Class:0x007fa5bd8e4120>>
olduğu
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
Çalışıyorum:
RSpec 2.1.0, Rails 3, guard-spork 0.3.2 ve spork ile 0.9.0
Bu örnekte, 'beklemede {} .should' kullanımdan kaldırılmıştır, 'bekliyoruz {} .to'yu kullanın –