Sha256: 4e009aeb5e362cc6db8ed4a48a3b83145ca680cd9409d48e15a6ddb3bf0378e4

Contents?: true

Size: 1.81 KB

Versions: 9

Compression:

Stored size: 1.81 KB

Contents

require 'spec_helper'
module Finitio
  describe Support, "compare_attrs" do
    include Support

    context 'with arrays' do
      it 'works on same attrs' do
        h1 = [:a, :b]
        h2 = [:b, :a]
        shared, mine, yours = compare_attrs(h1, h2)
        expect(shared).to eql([:a, :b])
        expect(mine).to eql([])
        expect(yours).to eql([])
      end

      it 'works on not same attrs' do
        h1 = [ :a, :b ]
        h2 = [ :c, :a ]
        shared, mine, yours = compare_attrs(h1, h2)
        expect(shared).to eql([:a])
        expect(mine).to eql([:b])
        expect(yours).to eql([:c])
      end
    end

    context 'with hashes' do
      it 'works on same attrs' do
        h1 = { a: 1, b: 2 }
        h2 = { a: 1, b: 2 }
        shared, mine, yours = compare_attrs(h1, h2)
        expect(shared).to eql([:a, :b])
        expect(mine).to eql([])
        expect(yours).to eql([])
      end

      it 'works on not same attrs' do
        h1 = { a: 1, b: 2 }
        h2 = { a: 1, c: 2 }
        shared, mine, yours = compare_attrs(h1, h2)
        expect(shared).to eql([:a])
        expect(mine).to eql([:b])
        expect(yours).to eql([:c])
      end
    end

    context 'with a block' do
      it 'works on same attrs' do
        h1 = [{:name => :a}, {:name => :b}]
        h2 = [{:name => :b}, {:name => :a}]
        shared, mine, yours = compare_attrs(h1, h2){|a| a[:name] }
        expect(shared).to eql([:a, :b])
        expect(mine).to eql([])
        expect(yours).to eql([])
      end

      it 'works on not same attrs' do
        h1 = [{:name => :a}, {:name => :b}]
        h2 = [{:name => :c}, {:name => :a}]
        shared, mine, yours = compare_attrs(h1, h2){|a| a[:name] }
        expect(shared).to eql([:a])
        expect(mine).to eql([:b])
        expect(yours).to eql([:c])
      end
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
finitio-0.12.0 spec/support/test_compare_attrs.rb
finitio-0.11.4 spec/support/test_compare_attrs.rb
finitio-0.11.3 spec/support/test_compare_attrs.rb
finitio-0.11.2 spec/support/test_compare_attrs.rb
finitio-0.11.1 spec/support/test_compare_attrs.rb
finitio-0.10.0 spec/support/test_compare_attrs.rb
finitio-0.9.1 spec/support/test_compare_attrs.rb
finitio-0.9.0 spec/support/test_compare_attrs.rb
finitio-0.8.0 spec/support/test_compare_attrs.rb