Class: Dommy::RSpec::CapyStyleMatchers::HaveRole Private

Inherits:
Object
  • Object
show all
Defined in:
lib/dommy/rspec/capy_style_matchers.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Matches elements by computed ARIA role (+ optional accessible name / level), walking the accessibility tree via Interaction::RoleQuery.

Direct Known Subclasses

HaveNoRole

Instance Method Summary collapse

Constructor Details

#initialize(role, name: nil, level: nil, count: nil, exact: false) ⇒ HaveRole

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of HaveRole.



367
368
369
370
371
372
373
# File 'lib/dommy/rspec/capy_style_matchers.rb', line 367

def initialize(role, name: nil, level: nil, count: nil, exact: false)
  @role = role
  @name = name
  @level = level
  @count = count
  @exact = exact
end

Instance Method Details

#descriptionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



388
389
390
# File 'lib/dommy/rspec/capy_style_matchers.rb', line 388

def description
  "have #{describe_target}"
end

#does_not_match?(scope) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


383
384
385
386
# File 'lib/dommy/rspec/capy_style_matchers.rb', line 383

def does_not_match?(scope)
  matches?(scope)
  @count ? @matched.size != @count : @matched.empty?
end

#failure_messageObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



392
393
394
# File 'lib/dommy/rspec/capy_style_matchers.rb', line 392

def failure_message
  "expected to find #{describe_target}, found #{@matched.size}"
end

#failure_message_when_negatedObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



396
397
398
# File 'lib/dommy/rspec/capy_style_matchers.rb', line 396

def failure_message_when_negated
  "expected NOT to find #{describe_target}, found #{@matched.size}"
end

#matches?(scope) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


375
376
377
378
379
380
381
# File 'lib/dommy/rspec/capy_style_matchers.rb', line 375

def matches?(scope)
  @matched = Interaction::RoleQuery.match(
    Internal::ScopeResolution.resolve(scope),
    role: @role, name: @name, level: @level, exact: @exact
  )
  @count ? @matched.size == @count : !@matched.empty?
end