[rspec-users] RSPEC and RoR undefined method for hash when running model tests

Matt Riches mattriches at gmail.com
Mon Dec 14 15:36:48 EST 2009

Within my project, I have a number of models that have additional methods
within them other than those provided by active record.

as an example (to keep it short and sweet)

class foo < ActiveRecod::Base

def status
    "New Record"

def reset


in my spec file I have

require 'spec_helper'

describe Foo do

before(:each) do
  @foo = Foo.new()

it "should have a status of New Record"
    @foo.status.should == "New Record"

it "should have a status of Reset after reset"
    @foo.reset.should == "Reset"

however, when I run rake spec I get
NoMethodError in 'Foo should have a status of New Record'
undefined method 'status' for #<Hash...>

and an equivalent one for the other method.

I am sure that this is something fundamental in my understanding, but I'm
scuppered. I have spent the best part of a day trying to resolve this.

1) Why are my methods undefined, when they are there (I can create the
object via script/console and call the status and reset methods and see them
2) What is the best way of resolving the issue

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091214/67988a7d/attachment-0001.html>

More information about the rspec-users mailing list