Forum: RSpec Problem with mocking helper methods

Posted by Ervin (Guest)
on 2011-11-14 21:54
(Received via mailing list)
Given that I assume that rails helper image_tag works as intended, I
want  to mock out call to this method in my helper.

spec/helpers/some_helper_spec.rb:
require 'spec_helper'
describe SomeHelper do
   it  'allows stub tags' do
        helper.should_receive(:image_tag).with(2).and_return(3)
        helper.image_tag(2).should == 3
   end
end

result:
        Failure/Error : helper.image_tag(2).should == 3
        expected : 3
        got : "<img alt=\"2\" src=\"/assets/2\" />" (using ==)

Bundle:
  * rspec (2.7.0)
  * rspec-core (2.7.1)
  * rspec-expectations (2.7.0)
  * rspec-mocks (2.7.0)
  * rspec-rails (2.7.0)
  * rails (3.1.1)
Posted by David Chelimsky (Guest)
on 2011-11-15 06:09
(Received via mailing list)
On Nov 11, 2011, at 6:48 AM, Ervin wrote:

> end
Unfortunately, I copied the example (from 'it' to 'end') directly into a 
helper spec and it passed :(

Are there any other testing related gems in your Gemfile that might be 
gumming things up?
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.