Bjorn Boulder
2009-Mar-23 23:10 UTC
[rspec-users] Spec::Rails, "model.should have(1).error_on(:attribute)" passes when?
Spec::Rails people, I''m curious about: - model.should have(1).error_on(:attribute) displayed in the URL below: http://rspec.rubyforge.org/rspec-rails/1.2.2/classes/Spec/Rails/Extensions/ActiveRecord/InstanceMethods.html The Rspec peepcode screencast suggests that model.should have(1).error_on(:attribute) should pass if model.send(:attribute) returns nil For me, I get an exception from the rspec script. My work-around is simple. Instead of: - model.should have(1).error_on(:attribute) I Use: -model.send(:attribute).should be_nil But now I have the question: - What kind of error causes: - model.should have(1).error_on(:attribute) - to pass ?? --b
David Chelimsky
2009-Mar-23 23:18 UTC
[rspec-users] Spec::Rails, "model.should have(1).error_on(:attribute)" passes when?
On Mon, Mar 23, 2009 at 6:10 PM, Bjorn Boulder <bornboulder77 at gmail.com> wrote:> Spec::Rails people, > > I''m curious about: > ?- model.should have(1).error_on(:attribute) > > displayed in the URL below: > ?http://rspec.rubyforge.org/rspec-rails/1.2.2/classes/Spec/Rails/Extensions/ActiveRecord/InstanceMethods.html > > The Rspec peepcode screencast suggests that > model.should have(1).error_on(:attribute) > should pass if > model.send(:attribute) > returns nil > > For me, I get an exception from the rspec script. > > My work-around is simple. > > Instead of: > ?- model.should have(1).error_on(:attribute) > I Use: > ?-model.send(:attribute).should be_nil > > But now I have the question: > ?- What kind of error causes: > ? ?- model.should have(1).error_on(:attribute) > ? ?- to pass ??If you add this to your model: validates_presence_of :attribute Then this will pass Model.new(:attribute => nil).should have(1).error_on(:attribute) Cheers, David> > --b > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Phor Gruber
2009-Mar-25 18:37 UTC
[rspec-users] Spec::Rails, "model.should have(1).error_on(:attribute)"
I added: - validates_presence_of :attribute To my model. The test now passes. yay!! Thanks David. -- Posted via http://www.ruby-forum.com/.
David Chelimsky
2009-Mar-25 20:30 UTC
[rspec-users] Spec::Rails, "model.should have(1).error_on(:attribute)"
On Mar 25, 2009, at 1:37 PM, Phor Gruber <lists at ruby-forum.com> wrote:> I added: > - validates_presence_of :attribute > > To my model. > > The test now passes.Congrats! It took longer than it usually does, but you just experienced the red and green parts of the red/green/refactor cycle. Cheers, David> > > yay!! > > Thanks David. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users