Sha256: f2a789019af684f93dd99b44b86d87109c557f8140dd58ff16ff18c94c314b88

Contents?: true

Size: 1.97 KB

Versions: 45

Compression:

Stored size: 1.97 KB

Contents

require 'pact_broker/client/matrix/resource'
require 'pact_broker/client/matrix/text_formatter'

module PactBroker
  module Client
    describe Matrix::TextFormatter do
      let(:matrix) { PactBroker::Client::Matrix::Resource.new(JSON.parse(File.read('spec/support/matrix.json'), symbolize_names: true)) }
      let(:expected_matrix_lines) { File.read('spec/support/matrix.txt') }

      # SublimeText removes whitespace from the end of files when you save them,
      # so removing trailing whitespace before comparing
      def strip_trailing_whitespace(text)
        text.split("\n").collect(&:strip).join("\n")
      end

      subject { strip_trailing_whitespace(Matrix::TextFormatter.call(matrix)) }

      context "with valid data" do
        it "it has the right text" do
          expect(subject).to start_with expected_matrix_lines
        end
      end

      context "with invalid data" do
        let(:expected_matrix_lines) { File.read('spec/support/matrix_error.txt') }
        let(:matrix) { PactBroker::Client::Matrix::Resource.new(matrix: [{}]) }

        it "doesn't blow up" do
          expect(subject).to eq expected_matrix_lines
        end
      end

      context "when some rows have a verification result URL and some don't" do
        let(:matrix_lines) do
          line_creator = -> { JSON.parse(File.read('spec/support/matrix.json'), symbolize_names: true)[:matrix].first }
          line_1 = line_creator.call
          line_2 = line_creator.call
          line_3 = line_creator.call
          line_2[:verificationResult] = nil
          line_3[:verificationResult][:success] = false
          [line_1, line_2, line_3]
        end

        let(:matrix) { PactBroker::Client::Matrix::Resource.new(matrix: matrix_lines) }

        let(:expected_matrix_lines) { File.read('spec/support/matrix_with_results.txt') }

        it "only provides a result number for the lines that have a result URL" do
          expect(subject).to eq expected_matrix_lines
        end
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
pact_broker-client-1.69.0 spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
pact_broker-client-1.68.0 spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
pact_broker-client-1.67.0 spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
pact_broker-client-1.66.1 spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
pact_broker-client-1.66.0 spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
pact_broker-client-1.65.0 spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
pact_broker-client-1.64.0 spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
pact_broker-client-1.63.0 spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
pact_broker-client-1.62.1 spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
pact_broker-client-1.62.0 spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
pact_broker-client-1.61.1 spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
pact_broker-client-1.61.0 spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
pact_broker-client-1.60.0 spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
pact_broker-client-1.59.0 spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
pact_broker-client-1.58.0 spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
pact_broker-client-1.57.0 spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
pact_broker-client-1.56.0 spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
pact_broker-client-1.55.0 spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
pact_broker-client-1.54.0 spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
pact_broker-client-1.53.0 spec/lib/pact_broker/client/matrix/text_formatter_spec.rb