Sha256: 15f1038456614b8ea46343b6ffb7b08cde122997240c644ae1bb742ccf154985

Contents?: true

Size: 1.51 KB

Versions: 34

Compression:

Stored size: 1.51 KB

Contents

require 'spec_helper'

describe HashDiff do
  it "should be able to diff two equal array" do
    a = [1, 2, 3]
    b = [1, 2, 3]

    diff = HashDiff.diff_array(a, b)
    diff.should == []
  end

  it "should be able to diff two arrays with one element in common" do
    a = [1, 2, 3]
    b = [1, 8, 7]

    diff = HashDiff.diff_array(a, b)
    diff.should == [['-', 2, 3], ['-', 1, 2], ['+', 1, 8], ['+', 2, 7]]
  end

  it "should be able to diff two arrays with nothing in common" do
    a = [1, 2]
    b = []

    diff = HashDiff.diff_array(a, b)
    diff.should == [['-', 1, 2], ['-', 0, 1]]
  end

  it "should be able to diff an empty array with an non-empty array" do
    a = []
    b = [1, 2]

    diff = HashDiff.diff_array(a, b)
    diff.should == [['+', 0, 1], ['+', 1, 2]]
  end

  it "should be able to diff two arrays with two elements in common" do
    a = [1, 3, 5, 7]
    b = [2, 3, 7, 5]

    diff = HashDiff.diff_array(a, b)
    diff.should == [['-', 0, 1], ['+', 0, 2], ['+', 2, 7], ['-', 4, 7]]
  end

  it "should be able to test two arrays with two common elements in different order" do
    a = [1, 3, 4, 7]
    b = [2, 3, 7, 5]

    diff = HashDiff.diff_array(a, b)
    diff.should == [['-', 0, 1], ['+', 0, 2], ['-', 2, 4], ['+', 3, 5]]
  end

  it "should be able to diff two arrays with similar elements" do
    a = [{'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5}, 3]
    b = [1, {'a' => 1, 'b' => 2, 'c' => 3, 'e' => 5}]
    diff = HashDiff.diff_array(a, b)
    diff.should == [['+', 0, 1], ['-', 2, 3]]
  end

end

Version data entries

34 entries across 33 versions & 5 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.4/spec/hashdiff/diff_array_spec.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.5/spec/hashdiff/diff_array_spec.rb
vagrant-unbundled-2.0.1.0 vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.5/spec/hashdiff/diff_array_spec.rb
logstash-output-icinga-1.1.0 vendor/jruby/2.3.0/gems/hashdiff-0.3.4/spec/hashdiff/diff_array_spec.rb
logstash-output-icinga-1.1.0 vendor/jruby/1.9/gems/hashdiff-0.3.4/spec/hashdiff/diff_array_spec.rb
vagrant-unbundled-2.0.0.1 vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.5/spec/hashdiff/diff_array_spec.rb
vagrant-unbundled-1.9.8.1 vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.5/spec/hashdiff/diff_array_spec.rb
vagrant-unbundled-1.9.7.1 vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.5/spec/hashdiff/diff_array_spec.rb
hashdiff-0.3.5 spec/hashdiff/diff_array_spec.rb
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.4/spec/hashdiff/diff_array_spec.rb
logstash-output-icinga-1.0.0 vendor/jruby/1.9/gems/hashdiff-0.3.4/spec/hashdiff/diff_array_spec.rb
hashdiff-0.3.4 spec/hashdiff/diff_array_spec.rb
logstash-input-salesforce-3.0.0 vendor/jruby/1.9/gems/hashdiff-0.3.2/spec/hashdiff/diff_array_spec.rb
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.0/spec/hashdiff/diff_array_spec.rb
hashdiff-0.3.2 spec/hashdiff/diff_array_spec.rb
hashdiff-0.3.1 spec/hashdiff/diff_array_spec.rb
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/hashdiff-0.3.0/spec/hashdiff/diff_array_spec.rb
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/hashdiff-0.3.0/spec/hashdiff/diff_array_spec.rb
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/hashdiff-0.3.0/spec/hashdiff/diff_array_spec.rb
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/hashdiff-0.3.0/spec/hashdiff/diff_array_spec.rb