forked from pact-foundation/pact-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scratchpad.rb
52 lines (40 loc) · 1.59 KB
/
scratchpad.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Ideas for expectation DSL
Unfortunately RSpec has already stolen the method "example".
Could use:
eg
ex
my_provider.
given("a thing exists").
upon_receiving("a request for a thing").with({:method => 'get', :path => '/thing'})
will_respond_with({:body => {
name: ex("Fred"),
age: eg 29,
mobile: eg("0415 134 234", /\d{4} \d{3} \d{3}/),
dob: eg("1983-02-28", match: /\d\d\d\d-\d\d-\d\d/),
driver_licence_number: eg(12345678, size: 8),
children: eg([{name: 'Mary'}])
}})
eg([ {name: 'Mary'} ]) should match any array where every element has a name String
eg([ {name: example('Mary', size: 4) } ]) should match any array where every element has a 4 letter name
eg("Fred") could return Pact::Term.new(:matcher => /.+/, :generate => 'Fred')
eg(29) could return Pact::Term.new(:matcher => /\d+/, :generate => 29)
Need a way to specify a literal empty hash, rather than a hash that matches anything as {} currently does.
{:something => literal({}) }
{:something => actual({}) }
{:something => empty_hash }
# Slightly unintuitive behaviour: {} matches any hash, but [] only matches an empty array (or does now we've changed the code). Should [] match any array? How do we then specify an empty array?
{:something => literal([]) }
{:something => actual([]) }
{:something => empty_array }
Pact.build do
{
status: 200,
headers: exactly({
}),
body: including({
age: literal('12'),
phoneNumber: example("0415 134 234", /\d{4} \d{3} \d{3}/),
favouriteColors:
})
}
end