views:

1641

answers:

2

In my views I use a helper that takes arbitrary HTML as a block:

<% some_block_helper do %>
  Some arbitrary HTML and ERB variables here.
  More HTML here.
<% end %>

My helper does a bunch of things to the passed block of HTML before rendering it back to the view (Markdown and other formatting). I would like to know what are the cleanest ways of testing the result of the helper call in rSpec, if any. I've found a few examples that muck about with private methods of ERB but that seems a bit brittle and hard to read.

+1  A: 
  1. For a functional test, write a normal view spec and test the result.
  2. To unit test your helper, pass an arbitrary html input string to it directly.

If there's any other difficulty I'm missing, please comment?

James Baker
+6  A: 

To add just a bit to what James said, I think something like this should work just fine:

describe SomeHelper do
  it 'should do something' do
    helper.some_block_helper { the_block_code }.should XXXX
  end
end
Cameron Booth
how should the_block_code look like?
Bogdan Gusiev