Skip to content

Commit

Permalink
style: code style fixes as per fasterer suggestion (pact-foundation#203)
Browse files Browse the repository at this point in the history
* Use symbol to proc for slight performance gain
* Replace `reverse.each` with `reverse_each`
* Switch to `tr` for slight performance gain
* Clean up duplicate requires
* Empty lines vacuum
  • Loading branch information
tancnle authored and bethesque committed Nov 14, 2019
1 parent 9a5fe98 commit 26e2baa
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/pact/consumer/spec_hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ def after_each example_description

def after_suite
if Pact.consumer_world.any_pact_examples_ran?
Pact.consumer_world.consumer_contract_builders.each { | c | c.write_pact }
Pact.consumer_world.consumer_contract_builders.each(&:write_pact)
Pact::Doc::Generate.call
Pact::MockService::AppManager.instance.kill_all
Pact::MockService::AppManager.instance.clear_all
end
end
end
end
end
end
5 changes: 2 additions & 3 deletions lib/pact/doc/sort_interactions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ module Doc
class SortInteractions

def self.call interactions
interactions.sort{|a, b| sortable_id(a) <=> sortable_id(b)}
interactions.sort_by { |interaction| sortable_id(interaction) }
end

private

def self.sortable_id interaction
"#{interaction.description.downcase} #{interaction.response.status} #{(interaction.provider_state || '').downcase}"
end

end
end
end
end
1 change: 0 additions & 1 deletion lib/pact/provider/pact_helper_locator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ def self.pact_helper_path
end
end
end

2 changes: 1 addition & 1 deletion lib/pact/provider/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def reified_body
end

def rack_request_header_for header
with_http_prefix(header.to_s.upcase).gsub('-', '_')
with_http_prefix(header.to_s.upcase).tr('-', '_')
end

def rack_request_value_for value
Expand Down
2 changes: 1 addition & 1 deletion lib/pact/provider/test_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def set_up_provider_states provider_states, consumer, options = {}
def tear_down_provider_states provider_states, consumer, options = {}
# If there are no provider state, execute with an nil state to ensure global and base states are executed
Pact.configuration.provider_state_tear_down.call(nil, consumer, options) if provider_states.nil? || provider_states.empty?
provider_states.reverse.each do | provider_state |
provider_states.reverse_each do | provider_state |
Pact.configuration.provider_state_tear_down.call(provider_state.name, consumer, options.merge(params: provider_state.params))
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pact/provider/world.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def pact_uri_sources
end

def pact_uris_from_pact_uri_sources
pact_uri_sources.collect{| pact_uri_source| pact_uri_source.call }.flatten
pact_uri_sources.collect(&:call).flatten
end
end
end
Expand Down
6 changes: 2 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'rspec'
require 'fakefs/spec_helpers'
require 'rspec'
require 'pact'
require 'webmock/rspec'
require 'support/factories'
Expand All @@ -15,7 +14,7 @@
is_jruby = defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'

RSpec.configure do | config |
config.include(FakeFS::SpecHelpers, :fakefs => true)
config.include(FakeFS::SpecHelpers, fakefs: true)

config.extend Pact::Provider::RSpec::ClassMethods
config.include Pact::Provider::RSpec::InstanceMethods
Expand All @@ -24,6 +23,5 @@
if config.respond_to?(:example_status_persistence_file_path=)
config.example_status_persistence_file_path = "./spec/examples.txt"
end
config.filter_run_excluding :skip_jruby => is_jruby
config.filter_run_excluding skip_jruby: is_jruby
end

0 comments on commit 26e2baa

Please sign in to comment.