Sha256: 48370cf9f3c57d2ccc760402e839a415ad8a12e98c09220cb864a7fec48e0677

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

require 'spec_helper'
require 'pact/matchers/nested_json_diff_decorator'

module Pact
  module Matchers
    describe NestedJsonDiffDecorator do

      let(:diff) do
        {
          :something => Difference.new({name: 'Fred'}, KeyNotFound.new)
        }
      end

      subject { NestedJsonDiffDecorator.new(diff) }

      describe "#to_s" do

        context "when color_enabled is true" do
          it "returns nicely formatted json" do
            expect(subject.to_s.split("\n").size).to eq 8
          end

          it "returns a string displaying the diff in colour" do
            expect(subject.to_s).to include NestedJsonDiffDecorator::EXPECTED_COLOURED
            expect(subject.to_s).to include NestedJsonDiffDecorator::ACTUAL_COLOURED
          end
        end

        context "when color_enabled is false" do
          before do
            Pact.configuration.stub(:color_enabled).and_return(false)
          end

          it "returns nicely formatted json" do
            expect(subject.to_s.split("\n").size).to eq 8
          end

          it "returns a string displaying the diff without colour" do
            expect(subject.to_s).to_not include NestedJsonDiffDecorator::EXPECTED_COLOURED
            expect(subject.to_s).to_not include NestedJsonDiffDecorator::ACTUAL_COLOURED
          end
        end
      end

    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pact-1.1.0.rc2 spec/lib/pact/matchers/nested_json_diff_decorator_spec.rb
pact-1.1.0.rc1 spec/lib/pact/matchers/nested_json_diff_decorator_spec.rb