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.



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

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.



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

def content
  @content
end

#failure_messageObject (readonly) Also known as: failure_message_for_should

Returns the value of attribute failure_message.



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

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.



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

def failure_message_when_negated
  @failure_message_when_negated
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#descriptionObject



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

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

#does_not_match?(actual) ⇒ Boolean

Returns:

  • (Boolean)


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

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



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

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

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


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

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