Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Proposal: Consumer API #125

Open
maxlinc opened this issue Jun 16, 2014 · 1 comment
Open

Proposal: Consumer API #125

maxlinc opened this issue Jun 16, 2014 · 1 comment

Comments

@maxlinc
Copy link
Collaborator

maxlinc commented Jun 16, 2014

Here's my proposed API after playing around with some of the ideas on the roadmap. I think this idea will help tie together a lot of the items on the roadmap.

      # Simplest possible API
      Pacto.simulate_consumer do
        request 'create something'
      end

      # You should probably be able to use Contract objects instead of names, as well:
      contracts = Pacto.load_contract('my_contracts')
      Pacto.simulate_consumer do
        request contracts.first
      end

      # The use of named consumers will help with later reporting and CDC features
      Pacto.simulate_consumer :my_consumer do
        # Request should accept values for simulation
        request 'create something', color: 'blue', size: 'small'
        request 'create something', color: 'blue', size: 'large'
      end

      # You should also be able to pass the default values to the consumer, which
      # will be merged with values on the request. This has the same request as
      # the block above.
      Pacto.simulate_consumer :my_consumer, color: 'blue' do
        # Request should accept values for simulation
        request 'create something', size: 'small'
        request 'create something', size: 'large'
      end

      # We could add middlware to deal with the "enrichment" items on the roadmap
      Pacto.simulate_consumer :my_consumer, color: 'blue' do
        use CustomAuthentication
        use RandomHeaderCapitalization
        # ...
      end

      # The consumer should return a set of interactions
      interactions = Pacto.simulate_consumer :my_consumer, color: 'blue' do
        # Request should accept values for simulation
        request 'create something', size: 'small'
        request 'create something', size: 'large'
      end

      # We can probably add middleware to handle the "enrichment" items on the roadmap

      # This will clean up the RSpec API for collaboration testing. Previously we used
      # expect(Pacto).to ..., now you can do things like:

      # RSpec 3
      # expect(interactions).to include(an_interaction_for('create something').with(size: 'large'))

      # RSpec 2
      expect(interactions.first).to be_an_interaction_for('create something').with(size: 'large')

      # Interactions may also (in the future) have some aggregate methods or advanced capabilities, like:
      interactions.slowest(5) # returns the 5 slowest HTTP request/response interactions
      interactions.group_by(&:service) # groups by service, in this case 'create something'
      # auto_cleanup detects interactions that match a "creation pattern" (like a PUT, a
      # or a POST that returned a 201 (possibly as part of a POST-REDIRECT-GET), and sends
      # a DELETE request to undo the creation action.
      interactions.auto_cleanup
@maxlinc
Copy link
Collaborator Author

maxlinc commented Jul 29, 2014

Created #144 for better interactions.

Need to fix to return interactions, then will close.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant