Stub! does not work

Hi,

This piece of code does not work. Does anybody know the cause?

describe “/loan-events/{source-id}-lend.json” do
describe “GET” do
it “should call all method of LoanEvent with source_id” do
source_id = rand(1000)
LoanEvent.should_receive(:all).with(:source_id =>
source_id.to_s).once
get “/loan-events/#{source_id}-lend.json”
end
it “should return the JSON of this LoanEvent collection” do
collection = mock(“collection”)
LoadEvent.stub!(:all).and_return(collection)
collection.should_receive(:to_json).with(no_args).once
get “/loan-events/#{rand(1000)}-lend.json”
end
end
end

  1. EIOU::CoreApplication /loan-events/{source-id}-lend.json GET should
    return the JSON of this LoanEvent collection
    Failure/Error: LoadEvent.should_receive(:all).and_return({})
    uninitialized constant
    RSpec::Core::ExampleGroup::Nested_1::Nested_2::Nested_1::LoadEvent

    ./spec/core_application_spec.rb:42:in `block (4 levels) in <top

(required)>’

Best regards,
Zhi-Qiang L.
[email protected]

On Dec 3, 2010, at 5:37 AM, Zhi-Qiang L. wrote:

   get "/loan-events/#{source_id}-lend.json"
  1. EIOU::CoreApplication /loan-events/{source-id}-lend.json GET should return
    the JSON of this LoanEvent collection
    Failure/Error: LoadEvent.should_receive(:all).and_return({})
    uninitialized constant
    RSpec::Core::ExampleGroup::Nested_1::Nested_2::Nested_1::LoadEvent

This failure message ^^ tells you exactly what the problem is. There is
no constant named LoadEvent (with a ‘d’). I believe you meant to type
LoanEvent (with an ‘n’).

Cheers,
David