Class: StimulusSpec::Capybara::Matchers::HaveStimulusTarget

Inherits:
Object
  • Object
show all
Defined in:
lib/stimulus_spec/capybara/matchers/have_stimulus_target.rb

Instance Method Summary collapse

Constructor Details

#initialize(controller, target) ⇒ HaveStimulusTarget

Returns a new instance of HaveStimulusTarget.



7
8
9
10
# File 'lib/stimulus_spec/capybara/matchers/have_stimulus_target.rb', line 7

def initialize(controller, target)
  @controller = controller.to_s
  @target = target.to_s
end

Instance Method Details

#descriptionObject



29
30
31
# File 'lib/stimulus_spec/capybara/matchers/have_stimulus_target.rb', line 29

def description
  "have Stimulus target \"#{@target}\" for controller \"#{@controller}\""
end

#does_not_match?(page) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/stimulus_spec/capybara/matchers/have_stimulus_target.rb', line 17

def does_not_match?(page)
  page.has_no_css?("[data-#{@controller}-target~='#{@target}']", wait: 0)
end

#failure_messageObject



21
22
23
# File 'lib/stimulus_spec/capybara/matchers/have_stimulus_target.rb', line 21

def failure_message
  "expected to find an element with data-#{@controller}-target=\"#{@target}\" on the page"
end

#failure_message_when_negatedObject



25
26
27
# File 'lib/stimulus_spec/capybara/matchers/have_stimulus_target.rb', line 25

def failure_message_when_negated
  "expected not to find an element with data-#{@controller}-target=\"#{@target}\" on the page"
end

#matches?(page) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/stimulus_spec/capybara/matchers/have_stimulus_target.rb', line 12

def matches?(page)
  @page = page
  page.has_css?("[data-#{@controller}-target~='#{@target}']", wait: 0)
end