Class: Capybara::RSpecMatchers::HaveText

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/rspec/matchers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ HaveText

Returns a new instance of HaveText.



36
37
38
# File 'lib/capybara/rspec/matchers.rb', line 36

def initialize(text)
  @text = text
end

Instance Attribute Details

#textObject (readonly)

Returns the value of attribute text.



34
35
36
# File 'lib/capybara/rspec/matchers.rb', line 34

def text
  @text
end

Instance Method Details

#descriptionObject



58
59
60
# File 'lib/capybara/rspec/matchers.rb', line 58

def description
  "have text #{format(text)}"
end

#does_not_match?(actual) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
# File 'lib/capybara/rspec/matchers.rb', line 45

def does_not_match?(actual)
  @actual = wrap(actual)
  @actual.has_no_text?(text)
end

#failure_message_for_shouldObject



50
51
52
# File 'lib/capybara/rspec/matchers.rb', line 50

def failure_message_for_should
  "expected there to be text #{format(text)} in #{format(@actual.text)}"
end

#failure_message_for_should_notObject



54
55
56
# File 'lib/capybara/rspec/matchers.rb', line 54

def failure_message_for_should_not
  "expected there not to be text #{format(text)} in #{format(@actual.text)}"
end

#format(text) ⇒ Object



70
71
72
73
# File 'lib/capybara/rspec/matchers.rb', line 70

def format(text)
  text = Capybara::Helpers.normalize_whitespace(text) unless text.is_a? Regexp
  text.inspect
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
# File 'lib/capybara/rspec/matchers.rb', line 40

def matches?(actual)
  @actual = wrap(actual)
  @actual.has_text?(text)
end

#wrap(actual) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/capybara/rspec/matchers.rb', line 62

def wrap(actual)
  if actual.respond_to?("has_selector?")
    actual
  else
    Capybara.string(actual.to_s)
  end
end