class HaveField
include RSpec::Matchers # just for your methods
def initialize(name, &block)
@name = name
@block = block
end
def matches?(target)
@target = target
@target.should have_tag("div.control-group") do
with_tag "label", :with => { :class => "control-label", :for => "item_#@name" }, :text => "#{@name.to_s.titleize}: "
with_tag "div.controls", &@block
end
end
# ...
end
#...
describe "#text_field" do
it "creates the text field" do
builder.text_field(:name).should have_field(:name) {
with_tag "input#item_name", :with => { :name => "item[name]", :type => "text", :value => "sshaw" }
}
end
end
But, I get this error:
NoMethodError:
undefined method `current_scope' for nil:NilClass
# /Users/sshaw/.rvm/gems/ruby-1.9.2-p290/gems/rspec-html-matchers-0.4.1/lib/rspec-html-matchers.rb:104:in `matches?'
Since @__current_scope_for_nokogiri_matcher was nil when the block argument to have_field(:name) was created the subsequent call to have_tag using that block doesn't work as the var is still nil in the block's binding.
Any reason to use RSpec's namespace?
Instead of using an instance var within RSpec::Matchers how do you feel about adding the matchers to their own module and getting the current scope form a module method RSpec::HTML::Matchers.current_scope?
Hi, I'm trying to do the following:
But, I get this error:
Since
@__current_scope_for_nokogiri_matcher
wasnil
when the block argument tohave_field(:name)
was created the subsequent call tohave_tag
using that block doesn't work as the var is stillnil
in the block's binding.Any reason to use RSpec's namespace?
Instead of using an instance var within
RSpec::Matchers
how do you feel about adding the matchers to their own module and getting the current scope form a module methodRSpec::HTML::Matchers.current_scope
?If that's OK I can submit a patch.