[rspec-users] undefined method

bertly_the_coder muchira at gmail.com
Mon Jun 28 18:49:07 EDT 2010


Thanks David,

That helps a lot and makes a lot of sense. Neat article by the way,
was following to get a hang on rspec.

Cheers!

On Jun 28, 3:00 pm, David Chelimsky <dchelim... at gmail.com> wrote:
> On Jun 28, 2010, at 1:14 PM, bertly_the_coder wrote:
>
>
>
> > Hey Guys,
> > I am working on my first TDD/BDDD example and running into a problem,
> > when I run 'ruby app.rb" The app seems to run fine, but when I run
> > it's rspec 'spec app_spec.rb" I get a no method defined.
>
> > app.rb
> > require 'rubygems'
> > require 'open-uri'
> > require 'hpricot'
>
> > class Timer
> >    #this is the retrieve method used to retrieve the contents of the xml
> > file
>
> >    def self.retrieve
> >            doc = Hpricot(open('some site'))
> >            #get the times
> >            times = doc/"//times"
> >            puts times
> >    end
> > end
>
> > Timer.retrieve - this works fine
>
> > rspec
> > require 'app'
>
> > describe Timer do
> >    it "should retrieve the xml info from the site" do
> >            Timer.should retrieve
> >  end
>
> > end
>
> > error:
> > NameError in 'Timer should retrieve the xml info from the site'
> > undefined local variable or method `retrieve' for
> > #<Spec::Example::ExampleGroup::Subclass_1:0xb6dc9c70>
> > ./app.rb:7:
>
> This error tells you that there is no retrieve() method on the example itself, but the expression "Timer.should retrieve" expects there to be.
>
> Try something like this:
>
> describe Timer do
>   it "retrieves xml from the site" do
>     Timer.retrieve.should == "whatever you're expecting"
>   end
> end
>
> > Hope that's clear enough, I am a tad confused about what's going on,
> > it looks pretty clear cut.
>
> _______________________________________________
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users


More information about the rspec-users mailing list