Make expect_value actually check value

It is a matter of operator precedence. `do end` has lesser precedence
and thus the code

    expect(page).to have_selector("input") do
      ...
    end

is actually evaluated like

    expect(page).to(have_selector("input")) do
      ...
    end

Meaning the block is an argument to the `to` method. Looking into rspec
source code, the block is later discarded. So the value was never
actually checked.

The :css selector has been modified to allow usage of `value` in the
`have_selector` helper, which fixes the issue.
pull/11649/head
Christophe Bliard 2 years ago committed by Oliver Günther
parent ae6ed59f27
commit 6d657f794d
  1. 10
      spec/support/capybara.rb
  2. 4
      spec/support/edit_fields/date_edit_field.rb

@ -40,6 +40,16 @@ RSpec.configure do |config|
# Set the default options
config.include_context 'with default_url_options set', type: :feature
# Make it possible to match on value attribute.
#
# For instance:
#
# expect(page).to have_selector(".date input", value: "2022-11-17")
#
Capybara.modify_selector(:css) do
filter(:value) { |node, v| node.value == v }
end
end
##

@ -146,9 +146,7 @@ class DateEditField < EditField
end
def expect_value(value)
expect(page).to have_selector (".#{property_name} input") do |input|
input.value == value
end
expect(page).to have_selector(".#{property_name} input", value:)
end
def set_active_date(value)

Loading…
Cancel
Save