Hi all, Posted this question to StackOverflow (http://stackoverflow.com/questions/12684146/how-do-you-spec-an-overridden-rails-3-formhelper) and getting no love. Not sure if it's on the wrong track, too hard or misguided in some way, but it seemed like a question whose answer would teach me a bit about ActionView/RSpec for Rails, so was interested in pushing to see if I could get any help. This is the text on SO:
I have overridden the standard Rails FormHelper to get it to spit form elements out in our (pretty much Bootstrap-based) format (after http://www.likeawritingdesk.com/posts/very-custom-form-builders-in-rails). It works fine, but it is difficult to write a spec for. I am using a spec like this: rendered_form = helper.my_custom_form_for(@account, :url => '/accounts') do |f| f.inputs do # This isn't rendered f.text_field 'name', :size => 30 # This is rendered f.select 'locale', options_for_select([%w(Australia en-AU), %w(UK en-GB)]) end What is rendered includes the select tag, but not the text field tag. I suspect this is because of the way ActionView handles blocks now, appending the return value of the block rather than the return value of each statement in the block. Obviously, when used in context in an app, the helper method gets passed some ERB and evaluates in that context. 1. Am I right that it's not possible to test rendering helper methods in this way, with multiple statements in a block? 2. If I am right, what would be the least hacky way of making a spec that does the same thing as the helper does in the context of a full app? Make an ERB string and somehow pass it to the helper to render? Love it if anybody had anything helpful to add to it. Cheers, Ben -- You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group. To view this discussion on the web visit https://groups.google.com/d/msg/rails-oceania/-/L7iEg5-VPFMJ. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rails-oceania?hl=en.
