为什么Rails 4.2中的assert_select不接受参数?

4

我正在进行Rails集成测试,有人编写的测试在过去是通过的,但现在却出现了警告。

这是我正在处理的代码行:

assert_select "a[href=/monster_xml_users/#{user_xml.id}][data-method=delete]", I18n.t('revoke_access')

但现在它显示警告:

无效的CSS选择器,断言未运行。

但如果我这样写:

 assert_select "a", I18n.t('revoke_access')
        assert_select "a" do
          assert_select "[href=?]","/monster_xml_users/#{user_xml.id}"
          assert_select "[data-method=?]", "delete"
        end

然后它没有发出警告,测试通过并且是正确的。 但是我无法弄清楚为什么之前的断言现在失败了? 在Rails 4.2中,assert_select语法是否已更改?

1个回答

5

您正在使用旧的断言语法。现在 Rails 更喜欢将引号放在 CSS 对象周围,如下所示:

assert_select "a[href='/monster_xml_users/#{user_xml.id}'][data-method='delete']", I18n.t('revoke_access')

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接