Sha256: 88a9bfcce1bd5d2850203deaa28dd48dda873b1028cf2b898d3878449ec4ab14

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

require "capybara_table"
require "capybara/rspec"

module CapybaraTable
  module RSpecMatchers
    extend RSpec::Matchers::DSL
    def have_table(caption, **options)
      have_selector(:table, caption, **options)
    end

    matcher :have_table_row do |fields_and_options|
      fields, options = fields_and_options.partition { |k, v| k.is_a?(String) }.map(&:to_h)
      selector = Capybara::RSpecMatchers::HaveSelector.new(:table_row, fields, options)

      match do |node|
        selector.matches?(node)
      end

      match_when_negated do |node|
        selector.does_not_match?(node)
      end

      failure_message do |node|
        node = node.document if node.is_a?(Capybara::Session)
        node.synchronize do
          tables = node.all(:xpath, XPath.descendant_or_self(:table)).map do |table|
            CapybaraTable::Renderer.render(table)
          end

          selector.failure_message + " in the following tables:\n\n" + tables.join("\n\n")
        end
      end
    end
  end
end

RSpec.configure do |config|
  config.include CapybaraTable::RSpecMatchers, type: :feature
  config.include CapybaraTable::RSpecMatchers, type: :system
  config.include CapybaraTable::RSpecMatchers, type: :view
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
capybara_table-0.2.0 lib/capybara_table/rspec.rb