Open boris-petrov opened 2 years ago
Capybara.exact=
is dynamic code which is not executed by RuboCop and, as you mention, may not exist in the same file as the offense.Just to be sure I understand this – is it correct that when Capybara.exact = true
is set, we should change
expect(page).to have_link(exact_text: 'foobar')
into
expect(page).to have_link('foobar')
But the following should not be changed:
expect(page).to have_link(exact_text: <<~TEXT)
foo
bar
TEXT
@bquorning sorry for the late reply.
Yes, that's correct. Also expect(page).to have_link(exact_text: "foo\nbar")
shouldn't be changed. Also expect(page).to have_link(text: 'foobar')
should not be changed because that doesn't look for an exact match but a partial one.
And yes, a cop-configuration is perhaps the way to go for this.
P.S. Code similar to find('td', exact_text: 'foo')
and expect(page).to have_css('.some-class', exact_text: 'foo')
also shouldn't be changed.
It would be nice to have a check that disallows passing
exact_text
to such matchers as that's unneeded -Capybara.exact
makes these matcher work like so by default. That is, the above is equivalent toexpect(page).to have_link('foobar')
.A couple of things to note: 1) this is perhaps difficult to implement as
Capybara.exact = true
is generally set in a different filespec_helper.rb
. Perhaps an option to the plugin could be passed, not sure? 1) there are exceptions to this. If the text contains new lines,exact_text
must be passed (because of https://github.com/teamcapybara/capybara/issues/2533).