[rspec-users] [NoMethodError] simple problem

David Chelimsky dchelimsky at gmail.com
Sun May 27 11:52:43 EDT 2007


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")
>   end

FYI - 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
>


More information about the rspec-users mailing list