Module: CapybaraExtensions::Matchers
- Includes:
- Locators
- Defined in:
- lib/capybara-extensions/matchers.rb
Instance Method Summary collapse
-
#has_field_value?(locator, text) ⇒ Boolean
Checks that the value of a field matches a given value.
-
#has_image?(options = {}) ⇒ Boolean
Checks that the current node has an image with the given src or alt.
-
#has_meta_tag?(name, content) ⇒ Boolean
Checks the that the content of a meta tag matches a given value.
-
#has_no_field_value?(locator, text) ⇒ Boolean
Checks that the value of a field does not match a given value.
-
#has_no_image?(options = {}) ⇒ Boolean
Checks that the current node does not have an image with the given src or alt.
-
#has_no_meta_tag?(name, content) ⇒ Boolean
Checks the that the content of a meta tag does not match a given value.
Methods included from Locators
#image_locator, #meta_tag_locator
Instance Method Details
#has_field_value?(locator, text) ⇒ Boolean
Checks that the value of a field matches a given value. Typically, you’ll want to scope this to a form.
32 33 34 35 36 37 38 |
# File 'lib/capybara-extensions/matchers.rb', line 32 def has_field_value?(locator, text) if find_field(locator).value == text true else raise Capybara::ExpectationNotMet, "expected to find field #{locator} with a value of #{text}." end end |
#has_image?(options = {}) ⇒ Boolean
Checks that the current node has an image with the given src or alt.
11 12 13 14 |
# File 'lib/capybara-extensions/matchers.rb', line 11 def has_image?( = {}) raise "Must pass a hash containing 'src' or 'alt'" unless .is_a?(Hash) && (.has_key?(:src) || .has_key?(:alt)) has_selector?(:xpath, "//img#{image_locator()}") end |
#has_meta_tag?(name, content) ⇒ Boolean
Checks the that the content of a meta tag matches a given value.
60 61 62 |
# File 'lib/capybara-extensions/matchers.rb', line 60 def (name, content) has_selector?(:xpath, "/html/head/meta#{(name, content)}", visible: false) end |
#has_no_field_value?(locator, text) ⇒ Boolean
Checks that the value of a field does not match a given value. Typically, you’ll want to scope this to a form.
46 47 48 49 50 51 52 |
# File 'lib/capybara-extensions/matchers.rb', line 46 def has_no_field_value?(locator, text) if find_field(locator).value != text true else raise Capybara::ExpectationNotMet, "expected to not find field #{locator} with a value of #{text}." end end |
#has_no_image?(options = {}) ⇒ Boolean
Checks that the current node does not have an image with the given src or alt.
21 22 23 24 |
# File 'lib/capybara-extensions/matchers.rb', line 21 def has_no_image?( = {}) raise "Must pass a hash with 'alt' or 'src'" unless .is_a?(Hash) and (.has_key?(:alt) or .has_key?(:src)) has_no_selector?(:xpath, "//img#{image_locator()}") end |
#has_no_meta_tag?(name, content) ⇒ Boolean
Checks the that the content of a meta tag does not match a given value.
70 71 72 |
# File 'lib/capybara-extensions/matchers.rb', line 70 def (name, content) has_no_selector?(:xpath, "/html/head/meta#{(name, content)}", visible: false) end |