Hi Ben Here's why I think it's not working: when you have a helper in your views like this, you're using <%= %> tags around each field - thus, you're outputting the return values as you call each method. Given the select call is your final call within the block, that's probably why that's being returned, but not the text_field.
I know there's a way of providing a slab of ERB text - within which you could use the form helper like you're currently doing - and get the proper behaviour happening, but I can't find any examples right now. I would recommend you change to unit tests to cover each field method's behaviour - but of course, integration tests are important too, so something like what you're already trying would be helpful. I'll see if I can hunt down the ERB helper from somewhere (or maybe someone else here knows what I'm talking about?) -- Pat On 15/10/2012, at 12:41 PM, Ben MacLeod wrote: > 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. > > • Am I right that it's not possible to test rendering helper > methods in this way, with multiple statements in a block? > • 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. -- You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group. 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.
