在尝试创建无效对象时,尝试断言我的错误面板正在显示。
我有这个测试::
test 'invalid category submission results in failure' do
get new_category_path
assert_template 'categories/new'
assert_no_difference 'Category.count' do
post_via_redirect categories_path, category: {name: ''}
end
assert_template 'categories/new'
assert_select 'h2.panel-title' #<---Problem here
assert_select 'div.panel-body'
# assert_match 'prohibited', response.body #<---This works
end
执行test ::
时出现此错误1) Failure:
CreateCategoriesTest#test_invalid_category_submission_results_in_failure [/Users/jeffrey/Documents/workspace/Ruby/Udemy_Rails_Course/rails_projects/alpha-blog/test/integration/create_categories_test.rb:23]:
Expected at least 1 element matching "h2.panel-title", found 0..
Expected 0 to be >= 1.
如果我注释掉2&#34; assert_select&#34;声明并取消注释&#34; assert_match&#34;声明,然后我的测试通过,因为它检测到&#34;禁止&#34;在response.body。
所以关于为什么&#34;断言_选择&#34;找不到我的元素,即使它们显然在那里?