Please do not tell me to โlook for moreโ or other things, because all solutions for such a question do not work.
Simple: I have functional tests. I want to make easy access and see if the correct content is displayed.
test "displays headline if user should see it" do
get: index
assert_match / headline /, response.body
end
test "doesn't display headline if user shouldn't see it" do
get: index
assert_no_match / headline /, response.body
end
and simple view
<% if show_headline? (arg)%>
headline
<% end%>
and assistant:
module TheHelper
def show_headline? (arg)
arg? hard_code_logic: even_harder_logic
end
end
so what I need to do in the test is something like:
test "displays headline if user should see it" do
Something.stubs (: show_headline?). Returns (true)
get: index
assert_match / headline /, response.body
end
test "doesn't display headline if user shouldn't see it" do
Something.stubs (: show_headline?). Returns (false)
get: index
assert_no_match / headline /, response.body
end
The question is, what is something? I want to disable it because I have helpers checked in module / helpers.
After the get helper gets remixes in the controller class. Please do not give me links to other answers, I read them (but, of course, I could read the wrong ones), and they do not work for me. I am using Rails 2.3.10 with Mocha 0.9.8.
Things that don't work:
TheController.any_instance.stubs (: show_headline?)
ActionView :: Base.any_instance ...
@ controller.stubs ...
UPDATE:
The only layout that worked:
<% self.stubs (: show_headline?). returns (true)>%
<% if show_headline? (arg)%>
headline
<% end%>
but of course I wonโt use it ... maybe this is the key