Class: Capybara::RSpecMatchers::HaveText

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Matcher

#wrap

Constructor Details

#initialize(*args) ⇒ HaveText

Returns a new instance of HaveText.



54
55
56
57
58
59
60
61
# File 'lib/capybara/rspec/matchers.rb', line 54

def initialize(*args)
  @args = args.dup

  # are set just for backwards compatability
  @type = args.shift if args.first.is_a?(Symbol)
  @content = args.shift
  @options = (args.first.is_a?(Hash))? args.first : {}
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#failure_messageObject (readonly) Also known as: failure_message_for_should

Returns the value of attribute failure_message.



52
53
54
# File 'lib/capybara/rspec/matchers.rb', line 52

def failure_message
  @failure_message
end

#failure_message_when_negatedObject (readonly) Also known as: failure_message_for_should_not

Returns the value of attribute failure_message_when_negated.



52
53
54
# File 'lib/capybara/rspec/matchers.rb', line 52

def failure_message_when_negated
  @failure_message_when_negated
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#descriptionObject



77
78
79
# File 'lib/capybara/rspec/matchers.rb', line 77

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

#does_not_match?(actual) ⇒ Boolean

Returns:

  • (Boolean)


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

def does_not_match?(actual)
  wrap(actual).assert_no_text(*@args)
rescue Capybara::ExpectationNotMet => e
  @failure_message_when_negated = e.message
  return false
end

#format(content) ⇒ Object



81
82
83
84
# File 'lib/capybara/rspec/matchers.rb', line 81

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

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(actual)
  wrap(actual).assert_text(*@args)
rescue Capybara::ExpectationNotMet => e
  @failure_message = e.message
  return false
end