Class: StimulusSpec::Capybara::Matchers::HaveStimulusAction

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

Overview

Capybara matcher for +data-action+ attributes.

Examples:

expect(page).to have_stimulus_action("click->hello#greet")

Instance Method Summary collapse

Constructor Details

#initialize(descriptor) ⇒ HaveStimulusAction

Returns a new instance of HaveStimulusAction.

Parameters:

  • descriptor (String)

    action descriptor



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

def initialize(descriptor)
  @descriptor = descriptor.to_s
end

Instance Method Details

#descriptionObject



42
43
44
# File 'lib/stimulus_spec/capybara/matchers/have_stimulus_action.rb', line 42

def description
  "have Stimulus action \"#{@descriptor}\""
end

#does_not_match?(page) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/stimulus_spec/capybara/matchers/have_stimulus_action.rb', line 30

def does_not_match?(page)
  page.has_no_css?(scoped_selector, wait: 0)
end

#failure_messageObject



34
35
36
# File 'lib/stimulus_spec/capybara/matchers/have_stimulus_action.rb', line 34

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

#failure_message_when_negatedObject



38
39
40
# File 'lib/stimulus_spec/capybara/matchers/have_stimulus_action.rb', line 38

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

#matches?(page) ⇒ Boolean

Parameters:

  • page (Capybara::Session, Capybara::Node::Simple)

Returns:

  • (Boolean)


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

def matches?(page)
  @page = page
  page.has_css?(scoped_selector, wait: 0)
end

#within(selector) ⇒ self

Parameters:

  • selector (String)

    CSS selector for the scope element

Returns:

  • (self)


18
19
20
21
# File 'lib/stimulus_spec/capybara/matchers/have_stimulus_action.rb', line 18

def within(selector)
  @scope = selector
  self
end