Should_receive working in before(:each) but not in example

Hi there,

I’m striking a wee problem - and haven’t been able to figure it out. In
my
before statement I’m setting up a mock video. I’d like one of my
examples
to check that original= and save! are being called on the mock video, so
I
have an example that looks like this:

  it "should update the original video and save the video" do
    post :upload_video, :video_id => 'hi', :Filedata => @video_file
    @vid.should_receive(:original=)
    @vid.should_receive(:save!)
  end

This fails saying that @vid didn’t receive original=. However, if I
move
the two should’s up into the before block, then the example passes. I
thought @vid might be getting reassigned somewhere before the example
code
is run, but I can’t spot it. (@video is used in the action - not @vid).
Can anyone spot something obvious I’m doing wrong here? I’m happy for
any
other feedback on this too - it’s pretty ugly. Here’s the whole before
block with the should’s included in a location that let the example(s)
pass:

  before(:each) do
    @video_file =  ActionController::TestUploadedFile.new(RAILS_ROOT 

“/spec/fixtures/files/video.mpg”, ‘video/mp4’)

    @thumb = "thumb"
    @thumb.stub!(:url).and_return("the_thumb_url")

    @original = "original"
    @original.stub!(:path)

    @vid = mock_video(:original_thumbnail => @thumb, :convert_path 

=>
“convert_path”, :still_path => “still_path”, :original => @original)
# @vid.stub!(:original=)
# @vid.stub!(:save!)

    @videos = []
    @videos.stub!(:find).and_return(@vid)
    @current_user = mock_model(User, :id => 1, :videos => @videos)
    controller.stub!(:current_user).and_return(@current_user)

    @vid.should_receive(:original=)
    @vid.should_receive(:save!)
  end

I’m betting it’s something really obvious somewhere. :wink:

Cheers,

Tim.

On Wed, Sep 17, 2008 at 8:23 PM, Tim H. [email protected] wrote:

  it "should update the original video and save the video" do
    post :upload_video, :video_id => 'hi', :Filedata => @video_file
    @vid.should_receive(:original=)
    @vid.should_receive(:save!)
  end

This fails saying that @vid didn’t receive original=. However, if I move
the two should’s up into the before block, then the example passes.

Right. should_receive specifies what should happen in the future, not
what
has happened in the past.

///ark

Lol. I need another coffee. The should’s needed to be above the post.
:slight_smile:

Tim.