I am pretty new to testing so feel free to correct me if I got things wrong in my approach to this.
I am testing a Rails4 app with Minitest. As I have JS included in many pages I am using Capybara to have JS drivers in my tests, and also to be able to trigger JS Events and test the expected results. Here my confusion begins, as there are many ways to include Capybara.
Furthermore I found out that the "normal" assertion-style syntax won't work with Capybara. And here my confusion peaks. During my research I found that there is a Spec-style DSL for Capybara as well as a few more. Now I use the gem 'minitest-rails-capybara' (Github), and I tried to work with the methods/DSL in this list: RubyDoc
I tried to replace a simple assertion that tests for a HTML Element.
before: assert_select "title", "Study | Word Up"
now: page.has_selector?('title', :text => "Study | Word Up")
But no matter what I test for, the test always passes. How is that possible? I checked the server logs to see if I am on the right page. But everything seems fine, the passing test doesn't make sense.
You need to use Capybara's assert_selector
:
assert_selector "title", text: "Study | Word Up"
If you are trying to assert the document's title from the head element and not the body, then you need to use assert_title
:
assert_title "Study | Word Up"
You need to use assert
:
assert page.has_selector?('title', :text => "Study | Word Up")
has_selector?
returns a boolean and you need to check the value of this boolean.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With