Skip to content

Commit

Permalink
#80 update the readmes for array like matching with min/max
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Holshausen committed May 9, 2015
1 parent 7a6ff83 commit f96f1eb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
25 changes: 25 additions & 0 deletions pact-jvm-consumer-groovy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,31 @@ Defines a matcher that accepts ISO and SMTP timestamps. If the value is not prov

Defines a matcher that accepts UUIDs. A random one will be generated if no value is provided.

### Ensuring all items in a list match an example (2.2.0+)

Lots of the time you might not know the number of items that will be in a list, but you want to ensure that the list
has a minimum or maximum size and that each item in the list matches a given example. You can do this with the `eachLike`,
`minLike` and `maxLike` functions.

| function | description |
|----------|-------------|
| `eachLike()` | Ensure that each item in the list matches the provided example |
| `maxLike(integer max)` | Ensure that each item in the list matches the provided example and the list is no bigger than the provided max |
| `minLike(integer min)` | Ensure that each item in the list matches the provided example and the list is no smaller than the provided min |

For example:

```groovy
withBody {
users minLike(1) {
id identifier
name string('Fred')
}
}
```

This will ensure that the user list is never empty and that each user has an identifier that is a number and a name that is a string.

## Changing the directory pact files are written to (2.1.9+)

By default, pact files are written to `target/pacts`, but this can be overwritten with the `pact.rootDir` system property.
Expand Down
28 changes: 26 additions & 2 deletions pact-jvm-consumer-junit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,32 @@ PactDslJsonBody body = new PactDslJsonBody()
.timestamp();
```

#### Ensuring all items in a list match an example (2.2.0+)

Lots of the time you might not know the number of items that will be in a list, but you want to ensure that the list
has a minimum or maximum size and that each item in the list matches a given example. You can do this with the `arrayLike`,
`minArrayLike` and `maxArrayLike` functions.

| function | description |
|----------|-------------|
| `arrayLike` | Ensure that each item in the list matches the provided example |
| `maxArrayLike` | Ensure that each item in the list matches the provided example and the list is no bigger than the provided max |
| `minArrayLike` | Ensure that each item in the list matches the provided example and the list is no smaller than the provided min |

For example:

```java
DslPart body = new PactDslJsonBody()
.minArrayLike("users")
.id()
.stringType("name")
.closeObject()
.closeArray();
```

This will ensure that the users list is never empty and that each user has an identifier that is a number and a name that is a string.


### Matching on paths (version 2.1.5+)

You can use regular expressions to match incoming requests. The DSL has a `matchPath` method for this. You can provide
Expand All @@ -247,8 +273,6 @@ For example:
.body("{\"hello\": \"harry\"}")
```

##

## Debugging pact failures

When the test runs, Pact will start a mock provider that will listen for requests and match them against the expectations
Expand Down

0 comments on commit f96f1eb

Please sign in to comment.