Module: SbmtPactProducerDsl::ClassMethods
- Defined in:
- lib/sbmt/pact/rspec/support/pact_provider_helpers.rb
Constant Summary collapse
- PACT_PROVIDER_NOT_DECLARED_MESSAGE =
"http_pact_provider or grpc_pact_provider should be declared first"
Instance Method Summary collapse
- #_pact_provider(transport_type, provider, opts: {}) ⇒ Object
- #after_state_teardown(&block) ⇒ Object
- #before_state_setup(&block) ⇒ Object
- #grpc_pact_provider(provider, opts: {}) ⇒ Object
- #handle_message(name, opts: {}, &block) ⇒ Object
- #http_pact_provider(provider, opts: {}) ⇒ Object
- #message_pact_provider(provider, opts: {}) ⇒ Object
- #pact_config ⇒ Object
- #provider_state(name, opts: {}, &block) ⇒ Object
Instance Method Details
#_pact_provider(transport_type, provider, opts: {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sbmt/pact/rspec/support/pact_provider_helpers.rb', line 22 def _pact_provider(transport_type, provider, opts: {}) raise "#{transport_type}_pact_provider is designed to be used with RSpec" unless defined?(::RSpec) raise "#{transport_type}_pact_provider has to be declared at the top level of a suite" unless top_level? raise "*_pact_provider is designed to be run once per provider so cannot be declared more than once" if defined?(@_pact_config) pact_config_instance = Sbmt::Pact::Provider::PactConfig.new(transport_type, provider_name: provider, opts: opts) instance_variable_set(:@_pact_config, pact_config_instance) # rubocop:disable RSpec/BeforeAfterAll before(:context) do # rspec allows only context ivars in specs and ignores the rest # so we use block-as-a-closure feature to save pact_config ivar reference and make it available for descendants @_pact_config = pact_config_instance end # rubocop:enable RSpec/BeforeAfterAll it "verifies interactions with provider #{provider}" do pact_config.new_verifier.verify! end end |
#after_state_teardown(&block) ⇒ Object
48 49 50 51 |
# File 'lib/sbmt/pact/rspec/support/pact_provider_helpers.rb', line 48 def after_state_teardown(&block) raise PACT_PROVIDER_NOT_DECLARED_MESSAGE unless pact_config pact_config.after_teardown(&block) end |
#before_state_setup(&block) ⇒ Object
43 44 45 46 |
# File 'lib/sbmt/pact/rspec/support/pact_provider_helpers.rb', line 43 def before_state_setup(&block) raise PACT_PROVIDER_NOT_DECLARED_MESSAGE unless pact_config pact_config.before_setup(&block) end |
#grpc_pact_provider(provider, opts: {}) ⇒ Object
14 15 16 |
# File 'lib/sbmt/pact/rspec/support/pact_provider_helpers.rb', line 14 def grpc_pact_provider(provider, opts: {}) _pact_provider(:grpc, provider, opts: opts) end |
#handle_message(name, opts: {}, &block) ⇒ Object
58 59 60 61 62 |
# File 'lib/sbmt/pact/rspec/support/pact_provider_helpers.rb', line 58 def (name, opts: {}, &block) raise "message_pact_provider should be declared first" unless pact_config raise "message_pact_provider should be declared first" unless pact_config.is_a?(Sbmt::Pact::Provider::PactConfig::Async) pact_config.(name, opts: opts, &block) end |
#http_pact_provider(provider, opts: {}) ⇒ Object
10 11 12 |
# File 'lib/sbmt/pact/rspec/support/pact_provider_helpers.rb', line 10 def http_pact_provider(provider, opts: {}) _pact_provider(:http, provider, opts: opts) end |
#message_pact_provider(provider, opts: {}) ⇒ Object
18 19 20 |
# File 'lib/sbmt/pact/rspec/support/pact_provider_helpers.rb', line 18 def (provider, opts: {}) _pact_provider(:async, provider, opts: opts) end |
#pact_config ⇒ Object
64 65 66 |
# File 'lib/sbmt/pact/rspec/support/pact_provider_helpers.rb', line 64 def pact_config instance_variable_get(:@_pact_config) end |
#provider_state(name, opts: {}, &block) ⇒ Object
53 54 55 56 |
# File 'lib/sbmt/pact/rspec/support/pact_provider_helpers.rb', line 53 def provider_state(name, opts: {}, &block) raise PACT_PROVIDER_NOT_DECLARED_MESSAGE unless pact_config pact_config.new_provider_state(name, opts: opts, &block) end |