Topic: Test::Rails View

I have some code that is mysteriously breaking and wondered if anyone could see why. In the first case, there are some checkboxes named 'projects[]' and the word "properties" appears in a <p></p> content tag. In the second case, these checkboxes should be absent, replaced by a hidden tag named 'projects[]'. Additionally, the word properties is replaced with property. I think that's what my test expresses, but clearly Test::Rails feels otherwise.

The error I'm receiving is:

test_index_with_key(MemberViewTest):
RuntimeError: expected > (got "" for <input type="hidden" id="projects[]" name="projects[]" value=""  , {"name"=>"projects[]", "type"=>"hidden", "id"=>"projects[]", "value"=>""})

I'm not sure what got "" refers to.

class MemberViewTest < Test::Rails::ViewTestCase
  def test_index
    # first visit case
    assigns[:member] = Member.new
    render
    assert_post_form '/member/signup'
    assert_input '/member/signup', :checkbox, 'projects[]'  # checkboxes only present if we go there directly
    assert_tag :tag => 'p', :content => 'properties'        # pluralized only if we go there directly   
  end
 
  def test_index_with_key
    # key visit case
    assigns[:member] = Member.new
    assigns[:key]    = true
    assigns[:project_array] = ['Three19']
   
    render :action => 'index', :key => 'BAhbBiIKTWV6em8='
    assert_tag :tag => 'p', :content => 'property'      # pluralized only if we go there directly   
    assert_post_form '/member/signup'
    assert_input('/member/signup', :hidden, 'projects[]', 'Three19')  # checkboxes only present if we go there directly
  end
end

Re: Test::Rails View

That looks like an unit diff style report (maybe via autotest?) perhaps try running it from rake and see if the error message is a little more verbose and helpful.

It looks like the closing '>' of the input tag wasn't found.  Why on earth that's getting stripped, I have no clue.

My RoR journey  -- thoughts on learning RoR and lessons learned in applying TDD and agile practices.

Re: Test::Rails View

I have been using autotest, but the actual error clipped was from:

rake test:views

It turns out you nailed exactly what the problem was. I'm adding rows to an array that will build the form and by golly I forgot the closing '>'. Benign in every browser that's ever hit this site, but I'd hate to find out what would happen if a browser actually held to one of the (X)HTML standards and rejected this.

Thanks for getting me unstuck. Clear evidence again of the importance of tests.