Forum: RSpec matcher to see if radio button is selected at page load

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.
Pau C. (Guest)
on 2008-11-26 06:16
Hi. I'm trying to write a matcher to make sure a radio button is
selected when the page loads.

I got this at the moment:

When /^I leave "(.*)" selected$/ do |label|
  field = field_labeled label
  unless field.instance_variable_get("@element")['checked'] &&
field.instance_variable_get("@element")['checked'] == "checked"
    raise "Expected radio button with label #{label} to be checked, but
it wasn't"
  end
end

But I'm kind of assuming that there is a reason that @element isn't
accessible. Is there a better way to do this?
Zach D. (Guest)
on 2008-11-26 07:53
(Received via mailing list)
On Tue, Nov 25, 2008 at 11:16 PM, Pau C. <removed_email_address@domain.invalid> 
wrote:
> it wasn't"
>  end
> end
>
> But I'm kind of assuming that there is a reason that @element isn't
> accessible. Is there a better way to do this?

Have you tried using a CSS3 selector with something like have_tag ?

response.should
have_tag("input[type=radio][checked=checked][name=?][valued=?]",
"your[button]", "foo")



--
Zach D.
http://www.continuousthinking.com
http://www.mutuallyhuman.com
Pau C. (Guest)
on 2008-11-26 09:10
Zach D. wrote:
> response.should
> have_tag("input[type=radio][checked=checked][name=?][valued=?]",
> "your[button]", "foo")


Wouldn't that require me to do this: <input>My label</input>
My validator is saying that is not valid XHTML.

Thanks for the suggestion. I definitely haven't looked into the power of
have_tag enough.

Paul
This topic is locked and can not be replied to.