Class: Phlex::Reactive::TestHelpers::System::ReactiveValueMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/phlex/reactive/test_helpers/system.rb

Overview

A waiting matcher that asserts a field's live .value PROPERTY (issue #204), read by id via evaluate_script so it sees a value a reducer set on a DISABLED output (where the value attribute stays blank). Polls until the property equals the expected value or the wait budget elapses, re-resolving the node by id every cycle (morph-immune). Supports negation (not_to) the Capybara way: the negative holds as soon as the property differs from the expected value (an absent field reads nil, which never equals a String expectation — so a missing field satisfies not_to).

A plain class (not RSpec::Matchers.define) so it needs no RSpec at load time beyond the duck-typed matcher protocol RSpec calls (matches?, does_not_match?, failure_message*), keeping System loadable under Capybara alone. The expected value is stringified because a DOM .value is always a JS string on the wire (a numeric literal like 6 compares as "6").

Instance Method Summary collapse

Constructor Details

#initialize(id, value, wait: nil) ⇒ ReactiveValueMatcher

Returns a new instance of ReactiveValueMatcher.



112
113
114
115
116
# File 'lib/phlex/reactive/test_helpers/system.rb', line 112

def initialize(id, value, wait: nil)
  @id = id
  @expected = value.to_s
  @wait = wait
end

Instance Method Details

#does_not_match?(page) ⇒ Boolean

does_not_match? is RSpec's REQUIRED negated-matcher protocol method — its name is fixed by RSpec, not a predicate we get to rename. rubocop:disable Naming/PredicatePrefix

Returns:

  • (Boolean)


126
127
128
129
130
131
132
# File 'lib/phlex/reactive/test_helpers/system.rb', line 126

def does_not_match?(page)
  @page = page
  # The negative is satisfied the moment the property is NOT the expected
  # value (or the field is absent → nil). poll_until returns true as soon
  # as that holds, false if it stayed equal for the whole budget.
  poll_until { current_value != @expected }
end

#failure_messageObject

rubocop:enable Naming/PredicatePrefix



135
136
137
138
# File 'lib/phlex/reactive/test_helpers/system.rb', line 135

def failure_message
  "expected ##{@id} to have value #{@expected.inspect} (its .value property), " \
    "but after waiting it was #{current_value.inspect}"
end

#failure_message_when_negatedObject



140
141
142
# File 'lib/phlex/reactive/test_helpers/system.rb', line 140

def failure_message_when_negated
  "expected ##{@id} NOT to have value #{@expected.inspect} (its .value property), but it did"
end

#matches?(page) ⇒ Boolean

Returns:

  • (Boolean)


118
119
120
121
# File 'lib/phlex/reactive/test_helpers/system.rb', line 118

def matches?(page)
  @page = page
  poll_until { current_value == @expected }
end