Class: CapybaraMiniTestSpec::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara_minitest_spec/matcher.rb

Defined Under Namespace

Classes: Name

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node_matcher_name) ⇒ Matcher

Returns a new instance of Matcher.



6
7
8
9
# File 'lib/capybara_minitest_spec/matcher.rb', line 6

def initialize(node_matcher_name)
  @name = Name.new(node_matcher_name, true)
  define_expectations
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/capybara_minitest_spec/matcher.rb', line 4

def name
  @name
end

Class Method Details

.failure_message(assertion_method, matcher_name, *args) ⇒ Object

Compose failure message. E.g. Matcher failed: has_css?(“expected”, => 1)



33
34
35
36
37
38
39
40
# File 'lib/capybara_minitest_spec/matcher.rb', line 33

def self.failure_message(assertion_method, matcher_name, *args)
  if assertion_method == 'assert'
    message = "Matcher failed: "
  else
    message = 'Matcher should have failed: '
  end
  message += "#{matcher_name}(#{args.map(&:inspect).join(', ')})"
end

Instance Method Details

#define_expectationsObject



11
12
13
14
15
16
17
# File 'lib/capybara_minitest_spec/matcher.rb', line 11

def define_expectations
  # Define positive expectations.
  define_expectation
  # Define negative expectations.
  @name.negate!
  define_expectation
end

#test(page, *args) ⇒ Object

Send page the matcher name with args. E.g. page.has_css?(*args)



27
28
29
# File 'lib/capybara_minitest_spec/matcher.rb', line 27

def test(page, *args)
  wrap(page).send(name.original, *args)
end

#undefine_assertionsObject



19
20
21
22
23
# File 'lib/capybara_minitest_spec/matcher.rb', line 19

def undefine_assertions
  undefine_assertion
  @name.negate!
  undefine_assertion
end