[rspec-users] undefined method
dchelimsky at gmail.com
Mon Jun 28 15:00:45 EDT 2010
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.
> require 'rubygems'
> require 'open-uri'
> require 'hpricot'
> class Timer
> #this is the retrieve method used to retrieve the contents of the xml
> def self.retrieve
> doc = Hpricot(open('some site'))
> #get the times
> times = doc/"//times"
> puts times
> Timer.retrieve - this works fine
> require 'app'
> describe Timer do
> it "should retrieve the xml info from the site" do
> Timer.should retrieve
> NameError in 'Timer should retrieve the xml info from the site'
> undefined local variable or method `retrieve' for
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"
> Hope that's clear enough, I am a tad confused about what's going on,
> it looks pretty clear cut.
More information about the rspec-users