Sha256: 25367aa7c40454b15e55857f1bc21193099230ac5e5041ef599a46e9e7e703c6

Contents?: true

Size: 1.97 KB

Versions: 31

Compression:

Stored size: 1.97 KB

Contents

require 'pact/term'
require 'pact/something_like'
require 'pact/matching_rules/extract'
require 'pact/matching_rules/merge'
require 'pact/reification'

describe "converting Pact::Term and Pact::SomethingLike to matching rules and back again" do

  let(:example) { Pact::Reification.from_term expected }
  let(:matching_rules) { Pact::MatchingRules::Extract.(expected) }
  let(:recreated_expected) { Pact::MatchingRules::Merge.(example, matching_rules)}

  context "with a Pact::Term" do
    let(:expected) do
      {
        body: {
          alligator: {
            name: Pact::Term.new(generate: 'Mary', matcher: /M/)
          }
        }
      }
    end

    it "recreates the same object hierarchy" do
      expect(recreated_expected).to eq expected
    end
  end

  context "with a Pact::SomethingLike" do
    let(:expected) do
      {
        body: {
          alligator: {
            name: Pact::SomethingLike.new("Mary")
          }
        }
      }
    end

    it "recreates the same object hierarchy" do
      expect(recreated_expected).to eq expected
    end
  end

  context "with a Pact::SomethingLike containing a Hash" do
    let(:expected) do
      {
        body: {
          alligator: Pact::SomethingLike.new(name: 'Mary')
        }
      }
    end

    let(:similar) do
      {
        body: {
          alligator: {
            name: Pact::SomethingLike.new('Mary')
          }
        }
      }
    end

    it "recreates the same object hierarchy" do
      expect(recreated_expected).to eq expected
    end
  end

  context "with a Pact::SomethingLike containing an Array" do
    let(:expected) do
      {
        body: {
          alligators: Pact::SomethingLike.new(["Mary", "Betty"])
        }
      }
    end

    let(:similar) do
      {
        body: {
          alligators: [Pact::SomethingLike.new("Mary"), Pact::SomethingLike.new("Betty")]
        }
      }
    end

    it "recreates the same object hierarchy" do
      expect(recreated_expected).to eq expected
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
pact-support-1.6.5 spec/integration/matching_rules_extract_and_merge_spec.rb
pact-support-1.7.0.alpha.1 spec/integration/matching_rules_extract_and_merge_spec.rb
pact-support-1.6.4 spec/integration/matching_rules_extract_and_merge_spec.rb
pact-support-1.6.3 spec/integration/matching_rules_extract_and_merge_spec.rb
pact-support-1.6.2 spec/integration/matching_rules_extract_and_merge_spec.rb
pact-support-1.6.1 spec/integration/matching_rules_extract_and_merge_spec.rb
pact-support-1.6.0 spec/integration/matching_rules_extract_and_merge_spec.rb
pact-support-1.5.2 spec/integration/matching_rules_extract_and_merge_spec.rb
pact-support-1.5.1 spec/integration/matching_rules_extract_and_merge_spec.rb
pact-support-1.5.0 spec/integration/matching_rules_extract_and_merge_spec.rb
pact-support-1.4.0 spec/integration/matching_rules_extract_and_merge_spec.rb
pact-support-1.3.1 spec/integration/matching_rules_extract_and_merge_spec.rb
pact-support-1.3.0 spec/integration/matching_rules_extract_and_merge_spec.rb
pact-support-1.2.99.alpha.1 spec/integration/matching_rules_extract_and_merge_spec.rb
pact-support-1.3.0.alpha.2 spec/integration/matching_rules_extract_and_merge_spec.rb
pact-support-1.3.0.alpha.1 spec/integration/matching_rules_extract_and_merge_spec.rb
pact-support-1.2.5 spec/integration/matching_rules_extract_and_merge_spec.rb
pact-support-1.2.4 spec/integration/matching_rules_extract_and_merge_spec.rb
pact-support-1.2.3 spec/integration/matching_rules_extract_and_merge_spec.rb
pact-support-1.2.2 spec/integration/matching_rules_extract_and_merge_spec.rb