练习 2:他建议的用于检查与注册表单相关的错误消息的模板是下面的最后两个 assert_selects:
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
我无法弄清楚需要用什么来替换括号内的内容。自定义 CSS 具有如下形式部分:
#error_explanation {
color: red;
ul {
color: red;
margin: 0 0 30px 0;
}
}
.field_with_errors {
@extend .has-error;
.form-control {
color: $state-danger-text;
}
}
最佳答案
按照他的指示添加它们
assert_select 'div#<CSS id for error explanation>'
assert_select 'div.<CSS class for field with error>'
会是
assert_select 'div#error_explanation'
assert_select 'div.field_with_errors'
关于css - 关于 Michael Hartl 的(优秀的)Rails 教程的第 7 章练习 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27054475/