module CapybaraErrorIntel::DSL

Wraps Capybara::DSL

Public Instance Methods

has_button?(locator, options = {}) click to toggle source
# File lib/capybara_error_intel/dsl.rb, line 15
def has_button?(locator, options = {})
  has_selector?(:button, locator, options)
end
has_checked_field?(locator, options = {}) click to toggle source
# File lib/capybara_error_intel/dsl.rb, line 27
def has_checked_field?(locator, options = {})
  has_selector?(:field, locator, options.merge(checked: true))
end
has_content?(*args)
Alias for: has_text?
has_css?(css, options = {}) click to toggle source
# File lib/capybara_error_intel/dsl.rb, line 11
def has_css?(css, options = {})
  has_selector?(:css, css, options)
end
has_field?(locator, options = {}) click to toggle source
# File lib/capybara_error_intel/dsl.rb, line 19
def has_field?(locator, options = {})
  has_selector?(:field, locator, options)
end
has_select?(locator, options = {}) click to toggle source
# File lib/capybara_error_intel/dsl.rb, line 35
def has_select?(locator, options = {})
  has_selector?(:select, locator, options)
end
has_selector?(*args) click to toggle source
# File lib/capybara_error_intel/dsl.rb, line 6
def has_selector?(*args)
  matcher = has_selector(*args)
  match_or_error(matcher)
end
has_table?(locator, options = {}) click to toggle source
# File lib/capybara_error_intel/dsl.rb, line 39
def has_table?(locator, options = {})
  has_selector?(:table, locator, options)
end
has_text?(*args) click to toggle source
# File lib/capybara_error_intel/dsl.rb, line 43
def has_text?(*args)
  matcher = has_text(*args)
  match_or_error(matcher)
end
Also aliased as: has_content?
has_title?(title, options = {}) click to toggle source
# File lib/capybara_error_intel/dsl.rb, line 49
def has_title?(title, options = {})
  matcher = has_title(title, options)
  match_or_error(matcher)
end
has_unchecked_field?(locator, options = {}) click to toggle source
# File lib/capybara_error_intel/dsl.rb, line 31
def has_unchecked_field?(locator, options = {})
  has_selector?(:field, locator, options.merge(unchecked: true))
end
has_xpath?(_xpath, options = {}) click to toggle source
# File lib/capybara_error_intel/dsl.rb, line 23
def has_xpath?(_xpath, options = {})
  has_selector?(:xpath, locator, options)
end

Private Instance Methods

capybara_matcher_module() click to toggle source
# File lib/capybara_error_intel/dsl.rb, line 68
def capybara_matcher_module
  if Capybara::VERSION.to_f >= 3.14
    Capybara::RSpecMatchers::Matchers
  else
    Capybara::RSpecMatchers
  end
end
handle_failure(matcher) click to toggle source
# File lib/capybara_error_intel/dsl.rb, line 80
def handle_failure(matcher)
  message = matcher.failure_message

  if matcher.respond_to?(:diffable?) && matcher.diffable?
    RSpec::Expectations.fail_with message, matcher.expected, matcher.actual
  else
    RSpec::Expectations.fail_with message
  end
end
has_selector(*args) click to toggle source
# File lib/capybara_error_intel/dsl.rb, line 56
def has_selector(*args)
  capybara_matcher_module::HaveSelector.new(*args)
end
has_text(*args) click to toggle source
# File lib/capybara_error_intel/dsl.rb, line 60
def has_text(*args)
  capybara_matcher_module::HaveText.new(*args)
end
has_title(title, options) click to toggle source
# File lib/capybara_error_intel/dsl.rb, line 64
def has_title(title, options)
  capybara_matcher_module::HaveTitle.new(title, options)
end
match_or_error(matcher) click to toggle source
# File lib/capybara_error_intel/dsl.rb, line 76
def match_or_error(matcher)
  matcher.matches?(Capybara.current_session) || handle_failure(matcher)
end