Class: Capybara::RSpecMatchers::HaveText
- Defined in:
- lib/capybara/rspec/matchers.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #description ⇒ Object
- #does_not_match?(actual) ⇒ Boolean
- #failure_message_for_should ⇒ Object
- #failure_message_for_should_not ⇒ Object
- #format(content) ⇒ Object
-
#initialize(*args) ⇒ HaveText
constructor
A new instance of HaveText.
- #matches?(actual) ⇒ Boolean
Methods inherited from Matcher
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
#content ⇒ Object (readonly)
Returns the value of attribute content.
36 37 38 |
# File 'lib/capybara/rspec/matchers.rb', line 36 def content @content end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
36 37 38 |
# File 'lib/capybara/rspec/matchers.rb', line 36 def @options end |
#type ⇒ Object (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
#description ⇒ Object
64 65 66 |
# File 'lib/capybara/rspec/matchers.rb', line 64 def description "text #{format(content)}" end |
#does_not_match?(actual) ⇒ 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, ) end |
#failure_message_for_should ⇒ Object
54 55 56 57 58 |
# File 'lib/capybara/rspec/matchers.rb', line 54 def = Capybara::Helpers.(description, ) << " in #{format(@actual.text(type))}" end |
#failure_message_for_should_not ⇒ Object
60 61 62 |
# File 'lib/capybara/rspec/matchers.rb', line 60 def .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
44 45 46 47 |
# File 'lib/capybara/rspec/matchers.rb', line 44 def matches?(actual) @actual = wrap(actual) @actual.has_text?(type, content, ) end |