Sha256: 03cccffb7a14f29b6ca30838e3190e388ee281deff1bf9d8f121846bb0e49139

Contents?: true

Size: 1.49 KB

Versions: 5

Compression:

Stored size: 1.49 KB

Contents

require "open3"
require "pact_broker/client/cli/broker"

# This is not the ideal way to write a test, but I tried to write it with an in memory invocation,
# and I couldn't get the capture to work, and it became super complicated.

RSpec.describe "using unknown options", skip_windows: true do
  let(:unknown_switches_text) { "Unknown switches" }
  let(:warning_text) { "This is a warning"}
  let(:command) { "bundle exec bin/pact-broker can-i-deploy --pacticipant Foo --foo --broker-base-url http://example.org" }

  it "prints an 'unknown switches' warning to stderr and also includes the normal output of the command" do
    stderr_lines = nil

    Open3.popen3(command) do |stdin, stdout, stderr, thread|
       stderr_lines = stderr.readlines
    end

    expect(stderr_lines.join("\n")).to include(unknown_switches_text)
    expect(stderr_lines.join("\n")).to include(warning_text)

    expect(stderr_lines.size).to be > 2
  end


  context "with PACT_BROKER_ERROR_ON_UNKNOWN_OPTION=true" do
    it "prints an 'unknown switches' message to stderr and does NOT include the normal output of the command as it exits straight after" do
      stderr_lines = nil

      Open3.popen3({ "PACT_BROKER_ERROR_ON_UNKNOWN_OPTION" => "true" }, command) do |stdin, stdout, stderr, thread|
         stderr_lines = stderr.readlines
      end

      expect(stderr_lines.first).to include(unknown_switches_text)
      expect(stderr_lines.join("\n")).to_not include(warning_text)
      expect(stderr_lines.size).to eq 1
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pact_broker-client-1.75.3 spec/integration/unknown_options_spec.rb
pact_broker-client-1.75.1 spec/integration/unknown_options_spec.rb
pact_broker-client-1.75.0 spec/integration/unknown_options_spec.rb
pact_broker-client-1.74.0 spec/integration/unknown_options_spec.rb
pact_broker-client-1.73.0 spec/integration/unknown_options_spec.rb