Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support params in provider_state (v3) #168

Closed
jrmhaig opened this issue Jun 1, 2018 · 4 comments
Closed

Support params in provider_state (v3) #168

jrmhaig opened this issue Jun 1, 2018 · 4 comments
Labels
v3 pact v3 specification

Comments

@jrmhaig
Copy link
Contributor

jrmhaig commented Jun 1, 2018

The example on the README has a provider state of 'an alligator exists', which can be defined in the provider configuration with:

  provider_state 'an alligator exists' do
    ...
  end

Is there any way to use some form of pattern matching with provider_state so that a single block could be used for both 'an alligator called Tom exists' and 'an alligator called Jerry exists'?

I'm thinking of something similar to https://github.com/cucumber/cucumber/tree/master/cucumber-expressions

@bethesque
Copy link
Member

bethesque commented Jun 2, 2018

The provider state params in v3 will help with this, because you'll be able to pass in a hash of arbitrary params to help set up a provider state. eg {"name": "an alligator exists", "params": {"name": "Mary"}}.

I'm not sure when I'll get around to implementing that, so if you're interested in doing a PR for your suggestion, I'd be happy to accept it.

Personally, I always delegate from the provider state DSL to some helper class anyway, so it ends up being something like:

provider_state "an alligator called Tom exists" do
  ProviderStateHelper.new.create_alligator("Tom")
end

If I'm in a fancy mood, I'll make a fluent DSL so I can do something like:

provider_state "an alligator called Tom exists" do
  ProviderStateHelper.new
    .create_alligator("Tom")
    .create_alligator_credit_card("1234123412341234")
    .create_address("28 Swamp St")
end

@bethesque
Copy link
Member

Oh, you can include modules in the provider states code as well, so it could be as little as

provider_state "an alligator called Tom exists" do
  create_alligator("Tom")
end

@jrmhaig
Copy link
Contributor Author

jrmhaig commented Jun 5, 2018

Thanks. The v3 format looks good and I'll live with the fixed strings for the time being.

I hadn't considered using a helper class. I'll have a look at that too.

@YOU54F YOU54F added the v3 pact v3 specification label Aug 15, 2024
@YOU54F YOU54F changed the title Patten matching in provider_state Support params in provider_state (v3) Aug 15, 2024
@YOU54F
Copy link
Member

YOU54F commented Aug 15, 2024

closing as tracking under pact v3 epic

#318

@YOU54F YOU54F closed this as completed Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v3 pact v3 specification
Projects
None yet
Development

No branches or pull requests

3 participants