Forum: RSpec have_tag and img's

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B8c4bfb1b6002a5b43d87de3335401f5?d=identicon&s=25 BJ Clark (Guest)
on 2009-03-20 23:54
(Received via mailing list)
I'm specing some xhtml (which I don't normally do, so forgive me if
this is basic).

I've got the following spec:

       it "should build xhtml form pieces" do
         @captcha.should_receive(:request_image).and_return @image
         @captcha.vidoop_captcha().should have_tag "div.captcha" do
           with_tag
"img[src=http://api.vidoop.com/vs/captchas/cpt123/image
]"
           with_tag "input[type=hidden][name=captcha_id]"
           with_tag "input[name=captcha]"
         end
       end

@captcha.vidoop_captcha is returning the following html:
<div class="captcha"><input value="cpt123" name="captcha_id"/><image
src="http://api.vidoop.com/vs/captchas/cpt123/image" alt="VidoopSecure
Captcha Image"/><div class="instructions"><p>foo bar</p><input
type="text" autocomplete="off" maxlength="2" name="captcha"
id="captcha"/></div></div>

And my error is:
'Vidoop::Captcha::Helper rendering a catpcha should build xhtml form
pieces' FAILED
Expected at least 1 element matching
"img[src='http://api.vidoop.com/vs/captchas/cpt123/image'
]", found 0.
<false> is not true.

I've tried with_tag as simple as "img" but even that isn't matching.
The rest of the spec passes.

Any ideas?
Thanks,
BJ Clark
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-03-21 03:24
(Received via mailing list)
BJ Clark wrote:

>           with_tag "input[type=hidden][name=captcha_id]"
>           with_tag "input[name=captcha]"
>         end
>       end

I suspect the XPath predicate should be [@name='captcha'], but I don't
know
with_tag shortcuts.

You might also try (>cough<) my assert_xhtml:

   @captcha.vidoop_captcha().should be_html_with{
     div :id => :captcha do
       img :src => 'http://api.vidoop.com/vs/captchas/cpt123/image'
       input :type => :hidden, :name => :captcha_id
       input :name => :captcha
     end
   end

I invented it specifically to solve the verbosity problem you
encountered. gem
install nokogiri assert2, and require 'assert2/xhtml'.

If it fails, it prints out the HTML pattern it sought, and the sample
HTML from
your production code.

--
   Phlip
This topic is locked and can not be replied to.