Sha256: 69525ddea7a8262212d6ce4cd4b913b3ca5404251706d973934f4efa83331f7d

Contents?: true

Size: 1.69 KB

Versions: 67

Compression:

Stored size: 1.69 KB

Contents

require 'spec_helper'
require 'pact/shared/form_differ'
require 'pact/matchers/difference'
require 'pact/matchers/unix_diff_formatter'

module Pact
  describe FormDiffer do

    describe ".call" do

      let(:expected) { "param1=foo&param2=bar&param2=foobar" }
      let(:actual)   { "param1=wiffle&param2=foobar&param2=bar" }

      let(:difference) do
        {
          'param1' => [Pact::Matchers::Difference.new("foo", "wiffle")],
          'param2' => [Pact::Matchers::Difference.new("bar", "foobar"), Pact::Matchers::Difference.new("foobar", "bar")]
        }
      end

      subject { FormDiffer.call(expected, actual) }

      context "when there is a diff" do
        it "returns the diff" do
          expect(subject).to eq difference
        end
      end

      context "when the expected is a matching Hash" do
        let(:expected) do
          {
            param1: "wiffle",
            param2: ["foobar", "bar"]
          }
        end

        it "returns an empty diff" do
          expect(subject).to be_empty
        end
      end

      context "when the expected is a matching Hash with a Pact::Term" do
        let(:expected) do
          {
            param1: "wiffle",
            param2: [Pact::Term.new(generate: 'foobar', matcher: /bar/), "bar"]
          }
        end

        it "returns an empty diff" do
          expect(subject).to be_empty
        end
      end

      context "when the expected is a Hash that doesn't match the actual" do
        let(:expected) do
          {
            param1: "woffle",
            param2: ["foobar", "bar"]
          }
        end

        it "returns the diff" do
          expect(subject).to_not be_empty
        end
      end

    end

  end
end

Version data entries

67 entries across 67 versions & 1 rubygems

Version Path
pact-support-1.11.0 spec/lib/pact/shared/form_differ_spec.rb
pact-support-1.10.3 spec/lib/pact/shared/form_differ_spec.rb
pact-support-1.10.2 spec/lib/pact/shared/form_differ_spec.rb
pact-support-1.10.1 spec/lib/pact/shared/form_differ_spec.rb
pact-support-1.10.0 spec/lib/pact/shared/form_differ_spec.rb
pact-support-1.9.0 spec/lib/pact/shared/form_differ_spec.rb
pact-support-1.8.1 spec/lib/pact/shared/form_differ_spec.rb
pact-support-1.8.0 spec/lib/pact/shared/form_differ_spec.rb
pact-support-1.7.2 spec/lib/pact/shared/form_differ_spec.rb
pact-support-1.7.1 spec/lib/pact/shared/form_differ_spec.rb
pact-support-1.7.0 spec/lib/pact/shared/form_differ_spec.rb
pact-support-1.6.6 spec/lib/pact/shared/form_differ_spec.rb
pact-support-1.6.5 spec/lib/pact/shared/form_differ_spec.rb
pact-support-1.7.0.alpha.1 spec/lib/pact/shared/form_differ_spec.rb
pact-support-1.6.4 spec/lib/pact/shared/form_differ_spec.rb
pact-support-1.6.3 spec/lib/pact/shared/form_differ_spec.rb
pact-support-1.6.2 spec/lib/pact/shared/form_differ_spec.rb
pact-support-1.6.1 spec/lib/pact/shared/form_differ_spec.rb
pact-support-1.6.0 spec/lib/pact/shared/form_differ_spec.rb
pact-support-1.5.2 spec/lib/pact/shared/form_differ_spec.rb