Sha256: fcb7b13c3a6c5e10176e465dab572f754eb22bfa8028c687514bcf8164877a0d

Contents?: true

Size: 907 Bytes

Versions: 2

Compression:

Stored size: 907 Bytes

Contents

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

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

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

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

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
capybara_error_intel-0.1.2 lib/capybara_error_intel/dsl.rb
capybara_error_intel-0.1.1 lib/capybara_error_intel/dsl.rb