Can't use ERBUtil methods in helper specs #597

Closed
ngan opened this Issue Aug 10, 2012 · 3 comments

Comments

Projects
None yet
2 participants
@ngan

ngan commented Aug 10, 2012

I can't seem to use ERBUtils methods like h or html_escape inside my helper specs.

For exampe....

helper.link_to_custom("<b>hello</b>").should == link_to(html_escape("<b>hello</b>"))

This will raise undefined method for html_escape.

@dchelimsky

This comment has been minimized.

Show comment Hide comment
@dchelimsky

dchelimsky Aug 11, 2012

Owner

RSpec's helper specs wrap Rails' helper tests. This would make more sense to fix there, so please submit this to the Rails issue tracker.

FYI if you do - Rails' helper specs work a bit differently - instead of exposing a helper object, they include the helper module right in the test so your example would look like this:

assert_equal link_to(html_escape("<b>hello</b>")), link_to_custom("<b>hello</b>")
Owner

dchelimsky commented Aug 11, 2012

RSpec's helper specs wrap Rails' helper tests. This would make more sense to fix there, so please submit this to the Rails issue tracker.

FYI if you do - Rails' helper specs work a bit differently - instead of exposing a helper object, they include the helper module right in the test so your example would look like this:

assert_equal link_to(html_escape("<b>hello</b>")), link_to_custom("<b>hello</b>")

@dchelimsky dchelimsky closed this Aug 11, 2012

@ngan

This comment has been minimized.

Show comment Hide comment
@ngan

ngan Aug 11, 2012

Thanks David!

rails/rails#7330

ngan commented Aug 11, 2012

Thanks David!

rails/rails#7330

@ngan

This comment has been minimized.

Show comment Hide comment
@ngan

ngan Aug 11, 2012

Hey David, rails doesn't include it into TestCase--as for the reason, I'm not really clear. And I'm not sure if they even consider it a bug.

In any case, now that I think about it, perhaps rspec should fix this "issue.". Rspec takes the extra mile and does the right thing by giving you a helper method that encapsulates the helper scope. To the rspec user, there's no knowledge that the helper inherits from rails TestCase, and they shouldn't. Rspec-rails promises the entire helper context inside helper and it should fix what rails TestCase lacks.

Just my opinion. Thanks!

ngan commented Aug 11, 2012

Hey David, rails doesn't include it into TestCase--as for the reason, I'm not really clear. And I'm not sure if they even consider it a bug.

In any case, now that I think about it, perhaps rspec should fix this "issue.". Rspec takes the extra mile and does the right thing by giving you a helper method that encapsulates the helper scope. To the rspec user, there's no knowledge that the helper inherits from rails TestCase, and they shouldn't. Rspec-rails promises the entire helper context inside helper and it should fix what rails TestCase lacks.

Just my opinion. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment