Module: CapybaraErrorIntel::DSL

Defined in:
lib/capybara_error_intel/dsl.rb

Instance Method Summary collapse

Instance Method Details

#handle_failure(matcher) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/capybara_error_intel/dsl.rb', line 23

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) ⇒ Boolean



3
4
5
6
# File 'lib/capybara_error_intel/dsl.rb', line 3

def has_selector?(*args)
  matcher = Capybara::RSpecMatchers::HaveSelector.new(*args)
  match_or_error(matcher)
end

#has_text?(*args) ⇒ Boolean Also known as: has_content?



8
9
10
11
# File 'lib/capybara_error_intel/dsl.rb', line 8

def has_text?(*args)
  matcher = Capybara::RSpecMatchers::HaveText.new(*args)
  match_or_error(matcher)
end

#has_title?(title, options = {}) ⇒ Boolean



14
15
16
17
# File 'lib/capybara_error_intel/dsl.rb', line 14

def has_title?(title, options = {})
  matcher = Capybara::RSpecMatchers::HaveTitle.new(title, options)
  match_or_error(matcher)
end

#match_or_error(matcher) ⇒ Object



19
20
21
# File 'lib/capybara_error_intel/dsl.rb', line 19

def match_or_error(matcher)
  matcher.matches?(Capybara.current_session) || handle_failure(matcher)
end