1

I am running through the Hartl Rails Tutorial and have completed the exercises in 9.60, 9.61, 9.62 that call for refactoring of the new and edit form code with a new partial. The forms now use 'provide' to supply button text as in:

<% provide(:button_text, 'Create my account') %>

Which is rendered on the page with 'yield' as in:

<%= f.submit yield(:button_text), class: "btn btn-primary" %>

While not part of the exercise, I am not trying to write an integration test that will test for the correct text on the button for each page. For example this code will test the sign up form page:

test "signup page" do
  get signup_path
  assert_select "title", full_title("Sign up")
  assert_select "input[type=submit]", value: "Create my account"
end

However I have not been able to figure out the correct code for selecting the button and specifying the correct value for the button text. I have made the button text incorrect to try to get the test to fail, but have not found the correct test syntax that succeeds at failing ;-)

Documentation for ActionDispatch did not have a specific example that was helpful for this test case.

dtburgess
  • 613
  • 5
  • 19

1 Answers1

2

Ok found my own answer. The correct for selecting the button and validating the text:

test "signup page" do
  get signup_path
  assert_select "title", full_title("Sign up")
  assert_select "input[value=?]",  "Create my account"
end

What I learned is that 1. an attribute of an element should be enclosed in square brackets. 2. Use 'attribute=?' to match that attribute value to the value you are testing for: in this case "Create my account"

dtburgess
  • 613
  • 5
  • 19