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

Pacto templating #14

Closed
maxlinc opened this issue Sep 5, 2013 · 4 comments
Closed

Pacto templating #14

maxlinc opened this issue Sep 5, 2013 · 4 comments

Comments

@maxlinc
Copy link
Collaborator

maxlinc commented Sep 5, 2013

We believe Pacto needs a templating system. This is useful both because:

  1. Some requests manipulation may need to be done to playback requests. For example, an authentication token or nonce is not replayable, so there needs to be a mechanism to insert this data during replay.
  2. While stubbing, it may be useful to map request data to response data. For example, if you have a "Create" service, then you might want to make the name in the request match the name in the response.
  3. Similarly, while stubbing it is sometimes desirable to give the stubs a more dynamic feel by using random data. This idea is implemented by the Faker gem (random names, text, etc.) and by Fog's Fog::Mock class (random IP addresses, base64 encoding data, etc).
@marcosccm
Copy link
Contributor

Actually we already have this feature! Sadly it's not on the Readme. You can use ERB (I know, not the most portable thing) and what we are calling File Preprocessors to template the contracts.

It's a very simple implementation of the templating idea and it needs to be improved, we also could use a more portable format, like mustache.

@maxlinc
Copy link
Collaborator Author

maxlinc commented Sep 5, 2013

Cool. That makes it easier.
Mustache would be more portable, but less flexible. It may be hard to do the last item.

So I think we'll add docs/tests for this using ERB, and we can look later if setting up alternate templating engines makes sense.

@maxlinc
Copy link
Collaborator Author

maxlinc commented Sep 6, 2013

@marcosccm It didn't really make it as easy as we'd hoped....

One problem was that it was a preprocessor. We would need a postprocessor for a lot of stuff. For example, if you just want to return Time.now, then a preprocessor will always return the same time, while a postprocessor will update with the current timestamp.

We also had to disable the hash-deep-merge while using an ERB post processor. We used the same system of passing values, but we wanted to use either HDM or ERB, not both.

Finally, the InstantiatedContract has caused a lot of confusion for us. We're not clear on the differences between Contract and InstantiatedContract. I think it may make more sense to use a hook with a request/response signature instead of a processor that acts on a contract. Similar to WebMock.after_request or VCR's before_playback hook.

So we should chat, this PR will probably require a few refactors.

@maxlinc
Copy link
Collaborator Author

maxlinc commented Sep 18, 2013

Fixed w/ #18.

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

2 participants