Sha256: 19ae4c9d95a7c4dd5c7f27190c0a80a3d05c3c6f7a8c284af64ccc240bbfc63a

Contents?: true

Size: 1.69 KB

Versions: 19

Compression:

Stored size: 1.69 KB

Contents

require 'spec_helper'

describe HashDiff::LinearCompareArray do
  it "should find no differences between two empty arrays" do
    difference = described_class.call([], [])
    difference.should == []
  end

  it "should find added items when the old array is empty" do
    difference = described_class.call([], [:a, :b])
    difference.should == [['+', '[0]', :a], ['+', '[1]', :b]]
  end

  it "should find removed items when the new array is empty" do
    difference = described_class.call([:a, :b], [])
    difference.should == [['-', '[1]', :b], ['-', '[0]', :a]]
  end

  it "should find no differences between identical arrays" do
    difference = described_class.call([:a, :b], [:a, :b])
    difference.should == []
  end

  it "should find added items in an array" do
    difference = described_class.call([:a, :d], [:a, :b, :c, :d])
    difference.should == [['+', '[1]', :b], ['+', '[2]', :c]]
  end

  it "should find removed items in an array" do
    difference = described_class.call([:a, :b, :c, :d, :e, :f], [:a, :d, :f])
    difference.should == [['-', '[4]', :e], ['-', '[2]', :c], ['-', '[1]', :b]]
  end

  it "should show additions and deletions as changed items" do
    difference = described_class.call([:a, :b, :c], [:c, :b, :a])
    difference.should == [['~', '[0]', :a, :c], ['~', '[2]', :c, :a]]
  end

  it "should show changed items in a hash" do
    difference = described_class.call([{ :a => :b }], [{ :a => :c }])
    difference.should == [['~', '[0].a', :b, :c]]
  end

  it "should show changed items and added items" do
    difference = described_class.call([{ :a => 1, :b => 2 }], [{ :a => 2, :b => 2 }, :item])
    difference.should == [['~', '[0].a', 1, 2], ['+', '[1]', :item]]
  end
end

Version data entries

19 entries across 18 versions & 5 rubygems

Version Path
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.7/spec/hashdiff/linear_compare_array_spec.rb
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/hashdiff-0.3.7/spec/hashdiff/linear_compare_array_spec.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.7/spec/hashdiff/linear_compare_array_spec.rb
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.7/spec/hashdiff/linear_compare_array_spec.rb
vagrant-unbundled-2.2.2.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.7/spec/hashdiff/linear_compare_array_spec.rb
vagrant-unbundled-2.2.0.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.7/spec/hashdiff/linear_compare_array_spec.rb
vagrant-unbundled-2.1.4.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.7/spec/hashdiff/linear_compare_array_spec.rb
vagrant-unbundled-2.1.2.0 vendor/bundle/ruby/2.3.0/gems/hashdiff-0.3.7/spec/hashdiff/linear_compare_array_spec.rb
cloudsmith-api-0.30.7 vendor/bundle/ruby/2.3.0/gems/hashdiff-0.3.7/spec/hashdiff/linear_compare_array_spec.rb
color_me_shop-1.0.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.7/spec/hashdiff/linear_compare_array_spec.rb
vagrant-unbundled-2.1.1.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.7/spec/hashdiff/linear_compare_array_spec.rb
vagrant-unbundled-2.0.4.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.7/spec/hashdiff/linear_compare_array_spec.rb
vagrant-unbundled-2.0.3.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.7/spec/hashdiff/linear_compare_array_spec.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/spec/hashdiff/linear_compare_array_spec.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.7/spec/hashdiff/linear_compare_array_spec.rb
vagrant-unbundled-2.0.1.0 vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/spec/hashdiff/linear_compare_array_spec.rb
cloudsmith-api-0.21.4 vendor/bundle/ruby/2.3.0/gems/hashdiff-0.3.7/spec/hashdiff/linear_compare_array_spec.rb
hashdiff-0.3.7 spec/hashdiff/linear_compare_array_spec.rb
hashdiff-0.3.6 spec/hashdiff/linear_compare_array_spec.rb