Tim Haines
2008-Sep-18 03:23 UTC
[rspec-users] 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. ;-)
Cheers,
Tim.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/rspec-users/attachments/20080918/fee9512f/attachment.html>
Tim Haines
2008-Sep-18 03:30 UTC
[rspec-users] should_receive working in before(:each) but not in example
Lol. I need another coffee. The should''s needed to be above the post. :-) Tim. On Thu, Sep 18, 2008 at 3:23 PM, Tim Haines <tmhaines at gmail.com> wrote:> 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. ;-) > > Cheers, > > Tim. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080918/5f3367ef/attachment.html>
Mark Wilden
2008-Sep-18 03:44 UTC
[rspec-users] should_receive working in before(:each) but not in example
On Wed, Sep 17, 2008 at 8:23 PM, Tim Haines <tmhaines at gmail.com> 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080917/ffdddf9f/attachment-0001.html>