Class: Capybara::RSpecMatchers::HaveText

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

Instance Attribute Summary collapse

Attributes inherited from Matcher

#failure_message, #failure_message_when_negated

Instance Method Summary collapse

Methods inherited from Matcher

#wrap

Methods included from Compound

#and, #and_then, #or

Constructor Details

#initialize(*args) ⇒ HaveText



140
141
142
143
144
145
146
147
# File 'lib/capybara/rspec/matchers.rb', line 140

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



138
139
140
# File 'lib/capybara/rspec/matchers.rb', line 138

def content
  @content
end

#optionsObject (readonly)

Returns the value of attribute options



138
139
140
# File 'lib/capybara/rspec/matchers.rb', line 138

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type



138
139
140
# File 'lib/capybara/rspec/matchers.rb', line 138

def type
  @type
end

Instance Method Details

#descriptionObject



157
158
159
# File 'lib/capybara/rspec/matchers.rb', line 157

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

#does_not_match?(actual) ⇒ Boolean



153
154
155
# File 'lib/capybara/rspec/matchers.rb', line 153

def does_not_match?(actual)
  wrap_does_not_match?(actual) { |el| el.assert_no_text(*@args) }
end

#format(content) ⇒ Object



161
162
163
164
# File 'lib/capybara/rspec/matchers.rb', line 161

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

#matches?(actual) ⇒ Boolean



149
150
151
# File 'lib/capybara/rspec/matchers.rb', line 149

def matches?(actual)
  wrap_matches?(actual) { |el| el.assert_text(*@args) }
end