Skip to content

Commit

Permalink
feat(verify cli): rename --wip to --ignore-failures
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Aug 13, 2018
1 parent 2fca940 commit 8e2dffd
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ Gemfile.lock
gemfiles/*.gemfile.lock
reports/pacts
spec/examples.txt
*bethtest*
2 changes: 1 addition & 1 deletion lib/pact/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CLI < Thor
desc 'verify', "Verify a pact"
method_option :pact_helper, aliases: "-h", desc: "Pact helper file", :required => true
method_option :pact_uri, aliases: "-p", desc: "Pact URI"
method_option :wip, type: :boolean, default: false, desc: "If WIP, process will always exit with exit code 0", hide: true
method_option :ignore_failures, type: :boolean, default: false, desc: "Process will always exit with exit code 0", hide: true
method_option :pact_broker_username, aliases: "-u", desc: "Pact broker user name"
method_option :pact_broker_password, aliases: "-w", desc: "Pact broker password"
method_option :backtrace, aliases: "-b", desc: "Show full backtrace", :default => false, :type => :boolean
Expand Down
2 changes: 1 addition & 1 deletion lib/pact/cli/run_pact_verification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def pact_spec_options
criteria: SpecCriteria.call(options),
format: options[:format],
out: options[:out],
wip: options[:wip]
ignore_failures: options[:ignore_failures]
}
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/pact/provider/pact_spec_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def run_specs
::RSpec::Core::CommandLine.new(NoConfigurationOptions.new)
.run(::RSpec.configuration.output_stream, ::RSpec.configuration.error_stream)
end
options[:wip] ? 0 : exit_code
options[:ignore_failures] ? 0 : exit_code
end

def rspec_runner_options
Expand Down Expand Up @@ -120,7 +120,7 @@ def initialize_specs
pact_sources.each do | pact_source |
options = {
criteria: @options[:criteria],
wip: @options[:wip]
ignore_failures: @options[:ignore_failures]
}
honour_pactfile pact_source.uri, ordered_pact_json(pact_source.pact_json), options
end
Expand All @@ -147,7 +147,7 @@ def configure_output

::RSpec.configuration.full_backtrace = @options[:full_backtrace]

::RSpec.configuration.failure_color = :yellow if @options[:wip]
::RSpec.configuration.failure_color = :yellow if @options[:ignore_failures]
end

def ordered_pact_json(pact_json)
Expand Down
4 changes: 2 additions & 2 deletions lib/pact/provider/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module ClassMethods
include ::RSpec::Core::DSL

def honour_pactfile pact_uri, pact_json, options
pact_description = options[:wip] ? "WIP pact" : "pact"
pact_description = options[:ignore_failures] ? "Pending pact" : "pact"
Pact.configuration.output_stream.puts "INFO: Reading #{pact_description} at #{pact_uri}"
Pact.configuration.output_stream.puts "INFO: Filtering interactions by: #{options[:criteria]}" if options[:criteria] && options[:criteria].any?
consumer_contract = Pact::ConsumerContract.from_json(pact_json)
Expand Down Expand Up @@ -74,7 +74,7 @@ def describe_interaction interaction, options
pact_interaction: interaction,
pact_interaction_example_description: interaction_description_for_rerun_command(interaction),
pact_uri: options[:pact_uri],
pact_wip: options[:wip]
pact_ignore_failures: options[:ignore_failures]
}

describe description_for(interaction), metadata do
Expand Down
8 changes: 4 additions & 4 deletions lib/pact/provider/rspec/formatter_rspec_3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ def failed_interactions_count(summary)
summary.failed_examples.collect{ |e| e.metadata[:pact_interaction_example_description] }.uniq.size
end

def wip?(summary)
summary.failed_examples.any?{ |e| e.metadata[:pact_wip] }
def ignore_failures?(summary)
summary.failed_examples.any?{ |e| e.metadata[:pact_ignore_failures] }
end

def failure_title summary
if wip?(summary)
if ignore_failures?(summary)
"#{failed_interactions_count(summary)} pending"
else
::RSpec::Core::Formatters::Helpers.pluralize(failed_interactions_count(summary), "failure")
Expand All @@ -69,7 +69,7 @@ def color_for_summary summary
end

def print_rerun_commands summary
if wip?(summary)
if ignore_failures?(summary)
output.puts("\nPending interactions: (Failures listed here are expected and do not affect your suite's status)\n\n")
else
output.puts("\nFailed interactions:\n\n")
Expand Down
2 changes: 1 addition & 1 deletion lib/pact/tasks/task_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def verify_command pact_helper, pact_uri, rspec_opts, verification_opts
command_parts << "-S pact verify"
command_parts << "--pact-helper" << Shellwords.escape(pact_helper.end_with?(".rb") ? pact_helper : pact_helper + ".rb")
(command_parts << "--pact-uri" << pact_uri) if pact_uri
command_parts << "--wip" if verification_opts[:wip]
command_parts << "--ignore-failures" if verification_opts[:ignore_failures]
command_parts << "--pact-broker-username" << ENV['PACT_BROKER_USERNAME'] if ENV['PACT_BROKER_USERNAME']
command_parts << "--pact-broker-password" << ENV['PACT_BROKER_PASSWORD'] if ENV['PACT_BROKER_PASSWORD']
command_parts << "--backtrace" if ENV['BACKTRACE'] == 'true'
Expand Down
6 changes: 3 additions & 3 deletions lib/pact/tasks/verification_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class VerificationTask < ::Rake::TaskLib

attr_reader :pact_spec_configs
attr_accessor :rspec_opts
attr_accessor :wip
attr_accessor :ignore_failures

def initialize(name)
@rspec_opts = nil
@wip = false
@ignore_failures = false
@pact_spec_configs = []
@name = name
yield self
Expand Down Expand Up @@ -76,7 +76,7 @@ def rake_task
require 'pact/tasks/task_helper'

exit_statuses = pact_spec_configs.collect do | config |
Pact::TaskHelper.execute_pact_verify config[:uri], config[:pact_helper], rspec_opts, { wip: wip }
Pact::TaskHelper.execute_pact_verify config[:uri], config[:pact_helper], rspec_opts, { ignore_failures: ignore_failures }
end

Pact::TaskHelper.handle_verification_failure do
Expand Down
8 changes: 4 additions & 4 deletions spec/lib/pact/provider/rspec/formatter_rspec_3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module RSpec
pactfile_uri: pactfile_uri,
pact_interaction_example_description: description,
pact_json: pact_json,
pact_wip: wip
pact_ignore_failures: ignore_failures
}
end
let(:metadata_2) { metadata.merge(pact_interaction_example_description: 'another interaction')}
Expand All @@ -34,7 +34,7 @@ module RSpec
let(:summary) { double("summary", failure_count: 1, failed_examples: failed_examples, examples: examples)}
let(:pact_executing_language) { 'ruby' }
let(:pact_interaction_rerun_command) { Pact::TaskHelper::PACT_INTERACTION_RERUN_COMMAND }
let(:wip) { nil }
let(:ignore_failures) { nil }

subject { Formatter.new output }

Expand Down Expand Up @@ -105,8 +105,8 @@ module RSpec
end
end

context "when wip is true" do
let(:wip) { true }
context "when ignore_failures is true" do
let(:ignore_failures) { true }

it "reports failures as pending" do
expect(output_result).to include("1 pending")
Expand Down
12 changes: 6 additions & 6 deletions spec/lib/pact/tasks/task_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module Pact
let(:ruby_path) { "/path/to/ruby" }
let(:pact_uri) { "/pact/uri" }
let(:default_pact_helper_path) { "/pact/helper/path.rb" }
let(:verification_options) { { wip: wip } }
let(:wip) { nil }
let(:verification_options) { { ignore_failures: ignore_failures } }
let(:ignore_failures) { nil }

before do
stub_const("FileUtils::RUBY", ruby_path)
Expand Down Expand Up @@ -119,10 +119,10 @@ module Pact
end
end

context "with wip: true" do
let(:wip) { true }
it "executes the command with --wip" do
expect(TaskHelper).to receive(:execute_cmd).with(/ --wip\b/)
context "with ignore_failures: true" do
let(:ignore_failures) { true }
it "executes the command with --ignore-failures" do
expect(TaskHelper).to receive(:execute_cmd).with(/ --ignore-failures\b/)
TaskHelper.execute_pact_verify(pact_uri, nil, nil, verification_options)
end
end
Expand Down
18 changes: 9 additions & 9 deletions spec/lib/pact/tasks/verification_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Pact
@pact_uri = 'http://example.org/pact.json'
@task_name = 'pact:verify:pact_rake_spec'
@task_name_with_explict_pact_helper = 'pact:verify:pact_rake_spec_with_explict_pact_helper'
@task_name_wip = 'pact:verify:pact_rake_spec_wip'
@task_name_ignore_failures = 'pact:verify:pact_rake_spec_ignore_failures'
@consumer = 'some-consumer'
@criteria = {:description => /wiffle/}

Expand All @@ -21,9 +21,9 @@ module Pact
pact.uri @pact_uri
end

VerificationTask.new(:pact_rake_spec_wip) do | pact |
VerificationTask.new(:pact_rake_spec_ignore_failures) do | pact |
pact.uri @pact_uri
pact.wip = true
pact.ignore_failures = true
end
end

Expand All @@ -47,23 +47,23 @@ module Pact
describe 'execute' do
context "with no explicit pact_helper" do
it 'verifies the pacts using the TaskHelper' do
expect(Pact::TaskHelper).to receive(:execute_pact_verify).with(@pact_uri, nil, nil, { wip: false })
expect(Pact::TaskHelper).to receive(:execute_pact_verify).with(@pact_uri, nil, nil, { ignore_failures: false })
Rake::Task[@task_name].execute
end
end

context "with an explict pact_helper" do
let(:verification_config) { [ uri: @pact_uri, pact_helper: @pact_helper] }
it 'verifies the pacts using specified pact_helper' do
expect(Pact::TaskHelper).to receive(:execute_pact_verify).with(@pact_uri, @pact_helper, nil, { wip: false })
expect(Pact::TaskHelper).to receive(:execute_pact_verify).with(@pact_uri, @pact_helper, nil, { ignore_failures: false })
Rake::Task[@task_name_with_explict_pact_helper].execute
end
end

context "with wip: true" do
it 'verifies the pacts with wip: true' do
expect(Pact::TaskHelper).to receive(:execute_pact_verify).with(@pact_uri, anything, anything, { wip: true })
Rake::Task[@task_name_wip].execute
context "with ignore_failures: true" do
it 'verifies the pacts with ignore_failures: true' do
expect(Pact::TaskHelper).to receive(:execute_pact_verify).with(@pact_uri, anything, anything, { ignore_failures: true })
Rake::Task[@task_name_ignore_failures].execute
end
end

Expand Down
2 changes: 1 addition & 1 deletion tasks/foo-bar.rake
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ end

Pact::VerificationTask.new('foobar:wip') do | pact |
pact.uri './spec/pacts/foo-bar-wip.json', pact_helper: './spec/support/bar_pact_helper.rb'
pact.wip = true
pact.ignore_failures = true
end

Pact::VerificationTask.new(:foobar_using_broker) do | pact |
Expand Down
2 changes: 1 addition & 1 deletion tasks/pact-test.rake
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ end

Pact::VerificationTask.new('test_app:wip') do | pact |
pact.uri './spec/support/test_app_fail.json', pact_helper: './spec/support/pact_helper.rb'
pact.wip = true
pact.ignore_failures = true
end


Expand Down

0 comments on commit 8e2dffd

Please sign in to comment.