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.



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

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#typeObject (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

#descriptionObject



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

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

#does_not_match?(actual) ⇒ Boolean

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

#failure_message_for_shouldObject



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

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

#failure_message_for_should_notObject



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

def failure_message_for_should_not
  failure_message_for_should.sub(/(to find)/, 'not \1')
end

#format(content) ⇒ Object



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

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

#matches?(actual) ⇒ Boolean

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