railstg railstg - 5 months ago 121
CSS Question

On Chapter 7, Excercise 2, of Michael Hartl's (excellent) Rails Tutorial

Exercise 2: His suggested template for checking error messages associated with signing up on a form are the last two assert_selects below:

require 'test_helper'

class UsersSignupTest < ActionDispatch::IntegrationTest

test "invalid signup information" do
get signup_path
assert_no_difference 'User.count' do
post users_path, user: { name: "",
email: "user@invalid",
password: "foo",
password_confirmation: "bar" }
end
assert_template 'users/new'
assert_select 'div#<CSS id for error explanation>'
assert_select 'div.<CSS class for field with error>'
end


I cannot figure out what needs to replace what he has within the brackets. The custom CSS has form sections like this:

#error_explanation {
color: red;
ul {
color: red;
margin: 0 0 30px 0;
}
}

.field_with_errors {
@extend .has-error;
.form-control {
color: $state-danger-text;
}
}

Answer

add them as he gave instructions

  assert_select 'div#<CSS id for error explanation>'
  assert_select 'div.<CSS class for field with error>'

will be

  assert_select 'div#error_explanation'
  assert_select 'div.field_with_errors'
Comments