[rspec-users] Stub activerecord find given instance?

Saverio Miroddi lists at ruby-forum.com
Tue Jan 12 19:58:41 EST 2010


David Chelimsky wrote:

>>> MyModel.stub(:find).with(42).and_return(myModel)
>> Didn't work as expected - I'll do a bit of research and post again.
> What is expected? What are you trying to accomplish?

Example in horror-code:

##################################################

class MyController < ApplicationController
  def show
    MyModel.find_by_code( params[:code] )
    head :ok
  end
end

describe "MySuite" do
  it "should" do
    MyModel.stub!( :find_by_code ).with( "abc" ) do
      puts "triggered 'abc'!"
    end

    get :show, :code => "kkk"
  end
end

##################################################

I'm expecting nothing to be printed, instead "triggered 'abc'!" is 
printed.

The example is, as I said, completely meaningless, but would simplify 
some tests in our suites.
-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list