|
| 1 | +require 'pact/matching_rules' |
| 2 | + |
| 3 | +module Pact |
| 4 | + module MatchingRules |
| 5 | + describe ".merge" do |
| 6 | + before do |
| 7 | + allow(V3::Merge).to receive(:call) |
| 8 | + allow(Merge).to receive(:call) |
| 9 | + allow(Pact.configuration.error_stream).to receive(:puts) |
| 10 | + end |
| 11 | + |
| 12 | + let(:object) { double('object') } |
| 13 | + let(:rules) { double('rules') } |
| 14 | + let(:options) { { pact_specification_version: Gem::Version.new(pact_specification_version) } } |
| 15 | + |
| 16 | + subject { MatchingRules.merge(object, rules, options)} |
| 17 | + |
| 18 | + context "when the pact_specification_version is nil" do |
| 19 | + let(:pact_specification_version) { nil } |
| 20 | + |
| 21 | + it "prints a warning" do |
| 22 | + expect(Pact.configuration.error_stream).to receive(:puts).with(/No pact specification version found/) |
| 23 | + subject |
| 24 | + end |
| 25 | + |
| 26 | + it "calls Merge" do |
| 27 | + expect(Merge).to receive(:call) |
| 28 | + subject |
| 29 | + end |
| 30 | + end |
| 31 | + |
| 32 | + context "when the pact_specification_version starts with '1.'" do |
| 33 | + let(:pact_specification_version) { "1.0" } |
| 34 | + |
| 35 | + it "calls Merge" do |
| 36 | + expect(Merge).to receive(:call) |
| 37 | + subject |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 41 | + context "when the pact_specification_version is with '1'" do |
| 42 | + let(:pact_specification_version) { "1" } |
| 43 | + |
| 44 | + it "calls Merge" do |
| 45 | + expect(Merge).to receive(:call) |
| 46 | + subject |
| 47 | + end |
| 48 | + end |
| 49 | + |
| 50 | + context "when the pact_specification_version starts with '2.'" do |
| 51 | + let(:pact_specification_version) { "2.0" } |
| 52 | + |
| 53 | + it "calls Merge" do |
| 54 | + expect(Merge).to receive(:call) |
| 55 | + subject |
| 56 | + end |
| 57 | + end |
| 58 | + |
| 59 | + context "when the pact_specification_version starts with '3.'" do |
| 60 | + let(:pact_specification_version) { "3.0" } |
| 61 | + |
| 62 | + it "calls V3::Merge" do |
| 63 | + expect(V3::Merge).to receive(:call) |
| 64 | + subject |
| 65 | + end |
| 66 | + end |
| 67 | + |
| 68 | + context "when the pact_specification_version starts with '4.'" do |
| 69 | + let(:pact_specification_version) { "4.0" } |
| 70 | + |
| 71 | + it "prints a warning" do |
| 72 | + expect(Pact.configuration.error_stream).to receive(:puts).with(/only knows how to parse v3 pacts/) |
| 73 | + subject |
| 74 | + end |
| 75 | + |
| 76 | + it "calls V3::Merge" do |
| 77 | + expect(V3::Merge).to receive(:call) |
| 78 | + subject |
| 79 | + end |
| 80 | + end |
| 81 | + |
| 82 | + context "when the pact_specification_version is with '11'" do |
| 83 | + let(:pact_specification_version) { "11" } |
| 84 | + |
| 85 | + it "prints a warning" do |
| 86 | + expect(Pact.configuration.error_stream).to receive(:puts).with(/only knows how to parse v3 pacts/) |
| 87 | + subject |
| 88 | + end |
| 89 | + |
| 90 | + it "calls V3::Merge" do |
| 91 | + expect(V3::Merge).to receive(:call) |
| 92 | + subject |
| 93 | + end |
| 94 | + end |
| 95 | + end |
| 96 | + end |
| 97 | +end |
0 commit comments