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

- (HaveText) initialize(*args)

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

- (Object) content (readonly)

Returns the value of attribute content



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

def content
  @content
end

- (Object) failure_message (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

- (Object) failure_message_when_negated (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

- (Object) options (readonly)

Returns the value of attribute options



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

def options
  @options
end

- (Object) type (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

- (Object) description



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

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

- (Boolean) does_not_match?(actual)

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

- (Object) format(content)



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

- (Boolean) matches?(actual)

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