Class: SwissKnife::RSpec::Matchers::HaveText

Inherits:
Object
  • Object
show all
Defined in:
lib/swiss_knife/rspec/have_text.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(matcher) ⇒ HaveText

Returns a new instance of HaveText.



11
12
13
# File 'lib/swiss_knife/rspec/have_text.rb', line 11

def initialize(matcher)
  @matcher = matcher
end

Instance Attribute Details

#matcherObject

Returns the value of attribute matcher.



9
10
11
# File 'lib/swiss_knife/rspec/have_text.rb', line 9

def matcher
  @matcher
end

#regexObject

Returns the value of attribute regex.



9
10
11
# File 'lib/swiss_knife/rspec/have_text.rb', line 9

def regex
  @regex
end

#subjectObject

Returns the value of attribute subject.



9
10
11
# File 'lib/swiss_knife/rspec/have_text.rb', line 9

def subject
  @subject
end

Instance Method Details

#descriptionObject



26
27
28
# File 'lib/swiss_knife/rspec/have_text.rb', line 26

def description
  "have text #{matcher.inspect}"
end

#failure_messageObject



30
31
32
# File 'lib/swiss_knife/rspec/have_text.rb', line 30

def failure_message
  "expected #{subject.inspect} to include #{matcher.inspect}"
end

#matches?(text) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
# File 'lib/swiss_knife/rspec/have_text.rb', line 15

def matches?(text)
  @subject = text.to_s

  case matcher
  when String
    subject.index(matcher)
  when Regexp
    subject.match(matcher)
  end
end

#negative_failure_messageObject



34
35
36
# File 'lib/swiss_knife/rspec/have_text.rb', line 34

def negative_failure_message
  "expected #{subject.inspect} to exclude #{matcher.inspect}"
end