Class: Spec::Rails::Matchers::HaveText

Inherits:
Object
  • Object
show all
Defined in:
lib/vendor/plugins/rspec-rails/lib/spec/rails/matchers/have_text.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ HaveText

Returns a new instance of HaveText.



7
8
9
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/matchers/have_text.rb', line 7

def initialize(expected)
  @expected = expected
end

Instance Method Details

#descriptionObject



25
26
27
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/matchers/have_text.rb', line 25

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

#failure_message_for_shouldObject



17
18
19
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/matchers/have_text.rb', line 17

def failure_message_for_should
  "expected #{expected.inspect}, got #{actual.inspect}"
end

#failure_message_for_should_notObject



21
22
23
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/matchers/have_text.rb', line 21

def failure_message_for_should_not
  "expected not to have text #{expected.inspect}"
end

#matches?(response_or_text) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/matchers/have_text.rb', line 11

def matches?(response_or_text)
  @actual = response_or_text.respond_to?(:body) ? response_or_text.body : response_or_text
  return actual =~ expected if Regexp === expected
  return actual == expected unless Regexp === expected
end