Minitest assert_select 的水豚等价物是什么?
What is the capybara equivalent for Minitest's assert_select?
我是测试新手,所以如果我的方法有误,请随时纠正我。
我正在使用 Minitest 测试 Rails4 应用程序。由于我在许多页面中包含 JS,因此我使用 Capybara 在我的测试中使用 JS 驱动程序,并且能够触发 JS 事件并测试预期结果。我的困惑开始了,因为有很多方法可以包含水豚。
此外,我发现 "normal" 断言式语法不适用于 Capybara。在这里,我的困惑达到了顶峰。在我的研究过程中,我发现有一个 Spec-style DSL for Capybara 以及其他一些。
现在我使用 gem 'minitest-rails-capybara' (Github), and I tried to work with the methods/DSL in this list: RubyDoc
我试图替换一个测试 HTML 元素的简单断言。
之前:assert_select "title", "Study | Word Up"
现在:page.has_selector?('title', :text => "Study | Word Up")
但无论我测试什么,测试总是通过。这怎么可能?我检查了服务器日志,看我是否在正确的页面上。但一切似乎都很好,通过测试没有意义。
您需要使用 assert
:
assert page.has_selector?('title', :text => "Study | Word Up")
has_selector?
returns 一个布尔值,你需要检查这个布尔值。
你需要使用水豚的assert_selector
:
assert_selector "title", text: "Study | Word Up"
如果您尝试从 head 元素而不是 body 断言文档的标题,那么您需要使用 assert_title
:
assert_title "Study | Word Up"
我是测试新手,所以如果我的方法有误,请随时纠正我。
我正在使用 Minitest 测试 Rails4 应用程序。由于我在许多页面中包含 JS,因此我使用 Capybara 在我的测试中使用 JS 驱动程序,并且能够触发 JS 事件并测试预期结果。我的困惑开始了,因为有很多方法可以包含水豚。
此外,我发现 "normal" 断言式语法不适用于 Capybara。在这里,我的困惑达到了顶峰。在我的研究过程中,我发现有一个 Spec-style DSL for Capybara 以及其他一些。 现在我使用 gem 'minitest-rails-capybara' (Github), and I tried to work with the methods/DSL in this list: RubyDoc
我试图替换一个测试 HTML 元素的简单断言。
之前:assert_select "title", "Study | Word Up"
现在:page.has_selector?('title', :text => "Study | Word Up")
但无论我测试什么,测试总是通过。这怎么可能?我检查了服务器日志,看我是否在正确的页面上。但一切似乎都很好,通过测试没有意义。
您需要使用 assert
:
assert page.has_selector?('title', :text => "Study | Word Up")
has_selector?
returns 一个布尔值,你需要检查这个布尔值。
你需要使用水豚的assert_selector
:
assert_selector "title", text: "Study | Word Up"
如果您尝试从 head 元素而不是 body 断言文档的标题,那么您需要使用 assert_title
:
assert_title "Study | Word Up"