mock/stub helper method on Controller Example of rspec

It’s kinda tricky if you want to mock helper methods on Controller Example with integrate_views of rspec::rails because template object won’t be created until you call a request method. But you presumably want to configure mock before calling a request on such situation. If you are using rr as your mock library, you can mock/stub the helper method like this:

it "should stub/mock helper_method"
  stub.proxy(response).template do |tmpl|
    stub(tmpl).your_helper_method { "stubbed" }
  end
  get :action_you_want_to_test
  response.body.should =~ /stubbed/
end

There might be better ways, though, I think it is good enough.

Advertisement

~ by ono on June 19, 2009.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.