missing matcher for script tag content
Closed this issue · 8 comments
Hi,
In order for me to fully replace rspec_tag_matchers with this one (which I'd really like to, since the other is rspec-rails-dependent and this is only nokogiri-dependent), I'd need one matcher for the content of a script tag, namely access its script and check whether certain text is available inside. Currently there doesn't seem to be one, or haven't I looked further enough?
Regards
you can match any tag's content by using have_tag, if you have some special case I'll appreciate if you post it here.
True, but it's more about the way you do it. I would like to have something like this:
html.should have_tag("script") do
with_text("function bla()")
with_text("var i = 2")
with_text(/BAMALAM\.com/)
end
Currently text parsing is only available as a direct param of have tag, so the above example is now written as:
html.should have_tag("script", :text => "function bla()")
html.should have_tag("script", :text => "var i = 2")
html.should have_tag("script", :text => /BAMALAM\.com/)
This would even be useful to check multiple text assertions on some div assertion and so on.
Got it. I'm working on something similar right now, so as you suggest I'll add with_text matcher. Thanks for this!
Hi, thx for the quick feature! I'm closing the issue then. This is also going to be referenced as soon as you make it into a versioned release, right?
yes
Hi! Quick question about with_text: can I use a regex with captures and access those in my scope? e.g.
rendered.should have_tag("script") do
with_text /foo = "([^"]+)"/
$1.should == "Contents of the Foo variable in my JS"
end
Yeah, I tried it within have_tag and the captures did not survive into the block. I wonder if there's a way to do this at all within nokogiri -- I have some code that I'm porting from rspec 1 and it used have_tag { ... $_ ... } where $_ was the text contents of the tag, and was further tested with a capturing regex.