Class: CapybaraMiniTestSpec::Matcher::Name

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

Overview

Represents the a matcher name. Returns different forms of the name depending on whether it is in a positive or negative state.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, positive) ⇒ Name

Returns a new instance of Name.



86
87
88
89
# File 'lib/capybara_minitest_spec/matcher.rb', line 86

def initialize(name, positive)
  @original = name.to_s
  @positive = positive
end

Instance Attribute Details

#originalObject (readonly)

Returns the value of attribute original.



84
85
86
# File 'lib/capybara_minitest_spec/matcher.rb', line 84

def original
  @original
end

Instance Method Details

#assertionObject



107
108
109
110
111
112
113
# File 'lib/capybara_minitest_spec/matcher.rb', line 107

def assertion
  if positive?
    "assert_page_#{without_question_mark}"
  else
    "refute_page_#{without_question_mark}"
  end
end

#expectationObject



115
116
117
118
119
120
121
# File 'lib/capybara_minitest_spec/matcher.rb', line 115

def expectation
  if positive?
    "must_#{have}"
  else
    "wont_#{have}"
  end
end

#haveObject



103
104
105
# File 'lib/capybara_minitest_spec/matcher.rb', line 103

def have
  without_question_mark.sub /has_/, 'have_'
end

#negate!Object



95
96
97
# File 'lib/capybara_minitest_spec/matcher.rb', line 95

def negate!
  @positive = !positive?
end

#positive?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/capybara_minitest_spec/matcher.rb', line 91

def positive?
  !!@positive
end

#without_question_markObject



99
100
101
# File 'lib/capybara_minitest_spec/matcher.rb', line 99

def without_question_mark
  @original.to_s.sub /\?$/, ''
end