Sha256: 4fbfd1b46ce17d1c3d0c97ead877884a1c275512d79f613ea8ac02e7584655f7

Contents?: true

Size: 1.46 KB

Versions: 7

Compression:

Stored size: 1.46 KB

Contents

RSpec::Matchers.define :have_versions do |versions_str|
  @table = have_versions_parse_table versions_str
  @last_index = nil
  @last_version = nil
  match do |master|
    versions = master.versions_dataset.order(:id).all
    versions.size == @table.size && @table.each.with_index.all? do |version, index|
      @last_index = index
      @last_version = version
      master_version = versions[index]
      [:name, :price, :valid_from, :valid_to, :created_at, :expired_at, :current].all? do |column|
        expected = version[column.to_s]
        case column
        when :valid_to
          expected = "9999-01-01"
        when :current
          expected = "false"
        end if expected==""
        found = master_version.send(column == :current ? "current?" : column).to_s
        equal = found == expected
        puts "#{column}: #{found} != #{expected}" unless equal
        equal
      end
    end
  end
  failure_message_for_should do |master|
    versions = master.versions_dataset.order(:id).all
    if versions.size != @table.size
      "Expected #{master.class} to have #{@table.size} versions but found #{versions.size}"
    else
      "Expected row #{@last_index+1} to match #{@last_version.inspect} but found #{versions[@last_index].inspect}"
    end
  end
end

def have_versions_parse_table(str)
  rows = str.strip.split("\n")
  rows.collect!{|row| row[/^\s*\|(.+)\|\s*$/, 1].split("|").collect(&:strip)}
  headers = rows.shift
  rows.collect{|row| Hash[headers.zip row]}
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sequel_bitemporal-0.1.6 spec/support/bitemporal_matchers.rb
sequel_bitemporal-0.1.5 spec/support/bitemporal_matchers.rb
sequel_bitemporal-0.1.4 spec/support/bitemporal_matchers.rb
sequel_bitemporal-0.1.3 spec/support/bitemporal_matchers.rb
sequel_bitemporal-0.1.2 spec/support/bitemporal_matchers.rb
sequel_bitemporal-0.1.1 spec/support/bitemporal_matchers.rb
sequel_bitemporal-0.1.0 spec/support/bitemporal_matchers.rb