Tyrel R.
2012-Jun-16 21:38 UTC
[rspec-users] 2 almost identical tests need different assertions to work and I can''t figure out why
Hey everyone, I am learning bdd and do deffently like it on the whole. I ran into a strange situation I got around it but it left a question in my mind and I would appreciate help in removing it ;) So hear is what happened test for one model: it "Should protect id from mass assignment" do attributes = @user.attributes attributes[''id''] = 42 lambda do User.create(attributes).id.should_not equal 42 end.should raise_error ActiveModel::MassAssignmentSecurity::Error end passes test for another model it "Should not allow ID to be mass assigned" do attributes = @dispensary.attributes attributes[''id''] = 42 disp = Dispensary.create( attributes ) disp.id.should_not equal 42 end also passes if I write a similar test for the first one instead of checking the exception like [code] it "Should not allow ID to be mass assigned" do attributes = @dispensary.attributes attributes[''id''] = 42 disp = Dispensary.create( attributes ) disp.id.should_not equal 42 end Rspec stops because an error was raised. I am confused what variable am I missing thank you -- Posted via http://www.ruby-forum.com/.
Justin Ko
2012-Jun-18 14:45 UTC
[rspec-users] 2 almost identical tests need different assertions to work and I can''t figure out why
On Jun 16, 2012, at 3:38 PM, Tyrel R. wrote:> Hey everyone, I am learning bdd and do deffently like it on the whole. I > ran into a strange situation I got around it but it left a question in > my mind and I would appreciate help in removing it ;) > > So hear is what happened > > test for one model: > > it "Should protect id from mass assignment" do > attributes = @user.attributes > attributes[''id''] = 42 > lambda do > User.create(attributes).id.should_not equal 42 > end.should raise_error ActiveModel::MassAssignmentSecurity::Error > end > > passes > > test for another model > > it "Should not allow ID to be mass assigned" do > attributes = @dispensary.attributes > attributes[''id''] = 42 > disp = Dispensary.create( attributes ) > disp.id.should_not equal 42 > end > > also passes > > if I write a similar test for the first one instead of checking the > exception like > [code] > it "Should not allow ID to be mass assigned" do > attributes = @dispensary.attributes > attributes[''id''] = 42 > disp = Dispensary.create( attributes ) > disp.id.should_not equal 42 > end > > Rspec stops because an error was raised. I am confused what variable am > I missing thank you > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-usersWhat is the error message?....