[rspec-devel] [ rspec-Bugs-6555 ] should_have_tag does not match documentation

noreply at rubyforge.org noreply at rubyforge.org
Wed Nov 8 07:48:58 EST 2006


Bugs item #6555, was opened at 2006-11-08 09:21
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=6555&group_id=797

Category: expectation module
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Jerry West (jjw)
Assigned to: Nobody (None)
Summary: should_have_tag does not match documentation

Initial Comment:
http://rspec.rubyforge.org/documentation/rails/writing/views.html says should_have_tag takes symbols as arguments.  Should_have_tag says otherwise.

require File.dirname(__FILE__) + '/../spec_helper'

class TestController < ActionController::Base
  def index() render :inline => '<h1>Hello<h1>'; end
end

context 'Test Controller' do
  controller_name :test
  integrate_views

  specify 'presents h1' do
    get :index
    response.should_have_tag :h1, :content => 'Hello'
  end
  
end

spec -fs spec/controllers/test_controller_spec.rb
Creating sqlite in memory database...

Test Controller
/home/jjw/work/northants/vendor/plugins/rspec/lib/spec/rails/tag_expectations.rb:28:in `find_tag':  (SyntaxError)

SyntaxError in should_have_tag(tag, *opts)
* tag should be the name of the tag (like 'div', or 'select' without '<' or '>')
* opts should be a Hash of key value pairs

        from /home/jjw/work/northants/vendor/plugins/rspec/lib/spec/rails/tag_expectations.rb:5:in `should_have_tag'
        from /home/jjw/work/northants/vendor/plugins/rspec/lib/extensions/action_controller/test_response.rb:22:in `should_have_tag'
        from ./spec/controllers/test_controller_spec.rb:13:in `__instance_exec0'
        from ...

Whereas strings work fine...

    response.should_have_tag 'h1', :content => 'Hello'

spec -fs spec/controllers/test_controller_spec.rb
Creating sqlite in memory database...

Test Controller
- presents h1

Finished in 0.007113 seconds

1 specification, 0 failures

Either the docs or the code should be adjusted.


----------------------------------------------------------------------

>Comment By: Jerry West (jjw)
Date: 2006-11-08 12:48

Message:
Point taken re SyntaxError, but other 'fatal' coding errors
such as deferencing nil get caught.  However ruby syntax
errors in specs (missing 'end' etc) cause the run to fail
without executing a spec.  This SyntaxError neither causes
the run to fail immediately (it can't, of course) nor plays
nicely with the usual output.  My thinking was that since
the spec and the reality differ, it should be reported as
usual.  It's the coder's job to realise it's the spec that's
at fault.

That said, it's absolutely no big deal.

Regarding symbols yes or no, what does assert_select do?
(assert_tag now deprecated)  Hmmm, looks like strings.  Oh
well, my vote would have been for symbols, but I can live
without.

----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2006-11-08 10:32

Message:
Can you explain your reasoning? This is a SyntaxError, not an ExpectationNotMet error. Fundamentally different animal IMO.

----------------------------------------------------------------------

Comment By: Jerry West (jjw)
Date: 2006-11-08 10:19

Message:
PS: tag_expectations / should_have_tag should really wrap
its SyntaxError in something that can be caught by
ExpectationNotMetError and handled in the usual way.

----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2006-11-08 09:38

Message:
Should we adjust docs, or support symbols?

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=6555&group_id=797


More information about the rspec-devel mailing list