I'm writing a simple test to check that a form is loading the correct values.
I've looked through the docs and can't seem to find an example that shows how to verify the value of a form input.
I have a form that renders the first_name of a user.
I just want to use assert_select
on the text input and verify that the first_name field matches what's in the database exactly (e.g users(:one).first_name)
How does one do this in Rails?
Actually the assert_tag
is deprecated.
There's a good example of how to do this with assert_select
in the documentation, so you could do this:
assert_select '#user_first_name' do
assert_select "[value=?]", Users.first.first_name
end
Checkbox: If you want to assert_select a checked checkbox (in this case 1 checked checkbox), try this:
assert_select 'input[type=checkbox][checked]', 1
Not 100% related to the question, but more for documentation purpose for others.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With