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



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

def initialize(*args)
  @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



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

def content
  @content
end

- (Object) options (readonly)

Returns the value of attribute options



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

def options
  @options
end

- (Object) type (readonly)

Returns the value of attribute type



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

def type
  @type
end

Instance Method Details

- (Object) description



68
69
70
# File 'lib/capybara/rspec/matchers.rb', line 68

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

- (Boolean) does_not_match?(actual)

Returns:

  • (Boolean)


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

def does_not_match?(actual)
  @actual = wrap(actual)
  @actual.has_no_text?(type, content, options)
end

- (Object) failure_message Also known as: failure_message_for_should



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

def failure_message
  message = Capybara::Helpers.failure_message(description, options)
  message << " in #{format(@actual.text(type))}"
  message
end

- (Object) failure_message_when_negated Also known as: failure_message_for_should_not



60
61
62
# File 'lib/capybara/rspec/matchers.rb', line 60

def failure_message_when_negated
  failure_message.sub(/(to find)/, 'not \1')
end

- (Object) format(content)



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

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

- (Boolean) matches?(actual)

Returns:

  • (Boolean)


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

def matches?(actual)
  @actual = wrap(actual)
  @actual.has_text?(type, content, options)
end