Controller spec, integrate views, mocking helper method

I need to use integrate views to test some particular features. In
ApplicationHelper I have:

module ApplicationHelper
def current_user_permitted?
# some logic that returns true/false
end
end

I’m testing MyController using Rspec/flexmock…

describe MyController do
integrate_views
before(:each) do
# how can I mock the ‘current_user_permitted?’ method here ?
get :index
end

 it "should display blah blah" do
      response.should have_tag('div#foo') do
           with_tag('div#bar',{:html => (/blah blah/)} )
      end
 end

end

I’ve found that I can make the test pass by mocking the
current_user_permitted? like this (BOTH mocks required in order to
pass!):

flexmock(ActionView::Base).new_instances.should_receive(“current_user_permitted?”).and_return(true)
flexmock(controller, ‘current_user_permitted?’ => true)

but this (2 mocks) just doesn’t seem right, what is the right way?

thanks in advance for any insight you can offer

Les

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs