I think this test should pass but it doesn''t 1) NoMethodError in ''Person should return full name'' undefined method `full_name?'' for #<Person:0x3567964> ./spec/models/person_spec.rb:43: describe Person do it "should return full name" do person = Person.new person.should be_full_name end end class Person < ActiveRecord::Base def full_name true end end -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070527/18efd0c1/attachment.html
On 5/27/07, Andrew WC Brown <omen.king at gmail.com> wrote:> I think this test should pass but it doesn''t > > 1) > NoMethodError in ''Person should return full name'' > undefined method `full_name?'' for #<Person:0x3567964> > ./spec/models/person_spec.rb:43: > > describe Person do > it "should return full name" do > person = Person.new > person.should be_full_name > end > end > > class Person < ActiveRecord::Base > def full_name > true > end > endThe error message says that what is missing is full_name?, not full_name. Try this: class Person < ActiveRecord::Base def full_name? true end end
Oh it all just clicked. What I wanted to do was: def full_name [first_name, last_name].join('' '') end it "should return full name" do person = Person.create(:first_name => "Andrew",:last_name => "Brown") person.full_name.should eql("Andrew Brown") end Still getting use to RSpec but I''m loving it. On 5/27/07, David Chelimsky <dchelimsky at gmail.com> wrote:> > On 5/27/07, Andrew WC Brown <omen.king at gmail.com> wrote: > > I think this test should pass but it doesn''t > > > > 1) > > NoMethodError in ''Person should return full name'' > > undefined method `full_name?'' for #<Person:0x3567964> > > ./spec/models/person_spec.rb:43: > > > > describe Person do > > it "should return full name" do > > person = Person.new > > person.should be_full_name > > end > > end > > > > class Person < ActiveRecord::Base > > def full_name > > true > > end > > end > > The error message says that what is missing is full_name?, not > full_name. Try this: > > class Person < ActiveRecord::Base > def full_name? > true > end > end > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070527/e5496ad3/attachment.html
On 5/27/07, Andrew WC Brown <omen.king at gmail.com> wrote:> Oh it all just clicked. > What I wanted to do was: > > def full_name > [first_name, last_name].join('' '') > end > > it "should return full name" do > person = Person.create(:first_name => "Andrew",:last_name => "Brown") > person.full_name.should eql("Andrew Brown") > endFYI - this will run faster if you use Person.new, which doesn''t save the database record. May seem trivial on one spec, but as they multiply, this sort of thing can make a big difference.> > Still getting use to RSpec but I''m loving it. > > > On 5/27/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > > On 5/27/07, Andrew WC Brown < omen.king at gmail.com> wrote: > > > I think this test should pass but it doesn''t > > > > > > 1) > > > NoMethodError in ''Person should return full name'' > > > undefined method `full_name?'' for #<Person:0x3567964> > > > ./spec/models/person_spec.rb:43: > > > > > > describe Person do > > > it "should return full name" do > > > person = Person.new > > > person.should be_full_name > > > end > > > end > > > > > > class Person < ActiveRecord::Base > > > def full_name > > > true > > > end > > > end > > > > The error message says that what is missing is full_name?, not > > full_name. Try this: > > > > class Person < ActiveRecord::Base > > def full_name? > > true > > end > > end > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >