You can clone with
I can't seem to use ERBUtils methods like h or html_escape inside my helper specs.
assert_equal link_to(html_escape("<b>hello</b>")), link_to_custom("<b>hello</b>")
This will raise undefined method for html_escape.
Is this a bug, a feature request or just a question?
In the last case just the first think I think about it: ERB::Util.new.html_escape
I know it's pretty ugly, but this is a better place to ask it: https://www.ruby-forum.com/
Yes, this isn't really a bug; those helpers aren't in scope.
I would suggest what @jeroeningen says: create a semi-global ERB::Util object somewhere, and then use it to get access to these methods.
You can just include ERB::Util in your test case
That works too.
Hey guys, thanks for the feedback. The workaround isn't the problem for me, it's not too difficult as you guys have stated.
My question would be why isn't it included into the scope?
That's a good question. Before answering I tried to include ERB::Util in TestCase and some other test failed, so I didn't want to dig further. That fail looked like coincidence - meaning that it worked assuming that ERB::Util is not included, so there might be no reason.
Anyway, I think that it's rarely used in tests, so there is not much gain in including it, but I don't have anything against either.
Polluting namespaces is a bad idea. Many people don't need to use these in their tests, so no reason to introduce the burden on those who don't.
Quite strange. Shouldn't all helper methods be included or none? Strange to leave some out on the merits of assumption that many don't use it. I guess I gotta take it at face value...
I like how rspec puts helper methods inside a helper variable. Maybe rails should do something similar...
If I ruled rails (and/or cared enough to write a patch, heh), that's exactly how it'd work.
If it can help anyone, please note that this is a change between Rails 3.0 and Rails 3.1. In Rails 3.0, we can call html_escape in any subclass of ActionView::TestCase. Not in Rails 3.1.
There is a strange consequence: in Rails 3.1, if you need to test an helper that uses html_escape (which seems to be a pretty common case), you have to include ERB::Util in your test case.