mirage 1.3.6 → 2.0.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +7 -4
- data/VERSION +1 -1
- data/bin/mirage +2 -0
- data/features/client/clear.feature +38 -20
- data/features/client/peek.feature +11 -11
- data/features/client/save_and_revert.feature +14 -8
- data/features/client/set.feature +59 -13
- data/features/client/track.feature +5 -3
- data/features/server/clear.feature +59 -47
- data/features/server/logging.feature +2 -3
- data/features/server/peek.feature +12 -10
- data/features/server/prime.feature +15 -13
- data/features/server/response_templates.feature +9 -16
- data/features/server/save_and_revert.feature +11 -14
- data/features/server/set.feature +44 -17
- data/features/server/set_default_response.feature +19 -25
- data/features/server/set_with_a_delay.feature +3 -5
- data/features/server/set_with_a_pattern.feature +24 -29
- data/features/server/track_requests.feature +71 -0
- data/features/server/web_user_interface.feature +7 -8
- data/features/step_definitions/my_steps.rb +83 -28
- data/features/support/env.rb +0 -14
- data/lib/mirage.rb +3 -0
- data/lib/mirage/client.rb +48 -43
- data/lib/mirage/core.rb +65 -152
- data/lib/mirage/mock_response.rb +49 -0
- data/lib/mirage/mock_responses_collection.rb +109 -0
- data/lib/mirage/object.rb +5 -0
- data/lib/mirage/web.rb +37 -28
- data/lib/start_mirage.rb +27 -5
- data/lib/{view/mirage/index.xhtml → views/index.erb} +5 -5
- data/mirage.gemspec +7 -7
- metadata +57 -23
- data/features/client/get.feature +0 -46
- data/features/server/file_responses.feature +0 -8
- data/features/server/track.feature +0 -74
@@ -2,6 +2,5 @@ Feature: Output from Mirage is stored in mirage.log.
|
|
2
2
|
This file is located at the root from which mirage is started.
|
3
3
|
|
4
4
|
Scenario: response is set.
|
5
|
-
Given I
|
6
|
-
|
7
|
-
Then mirage.log should contain '/mirage/set/greeting?response=Hello'
|
5
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello'
|
6
|
+
Then mirage.log should contain '/mirage/templates/greeting'
|
@@ -1,25 +1,27 @@
|
|
1
1
|
Feature: If you want to see the content of a particular response without triggering then it can be peeked instead.
|
2
2
|
To do this, the responses unique id is required to identify it
|
3
|
+
|
3
4
|
|
4
|
-
|
5
|
+
#TODO should return headers as well
|
5
6
|
Scenario: Peeking a text based response
|
6
|
-
Given I
|
7
|
-
|
|
7
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/xml' with body '<xml></xml>' and headers:
|
8
|
+
| content-type | text/xml |
|
8
9
|
|
9
|
-
When I
|
10
|
-
Then '
|
10
|
+
When I send GET to 'http://localhost:7001/mirage/templates/1'
|
11
|
+
Then '<xml></xml>' should be returned
|
12
|
+
And the response 'content-type' should be 'text/xml'
|
11
13
|
|
12
14
|
|
13
15
|
Scenario: Peeking a file based response
|
14
|
-
Given I
|
15
|
-
|
|
16
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/some/location/download' with file: README.md and headers:
|
17
|
+
| X-mirage-file | true |
|
16
18
|
|
17
|
-
When I
|
18
|
-
Then the response should be
|
19
|
+
When I send GET to 'http://localhost:7001/mirage/templates/1'
|
20
|
+
Then the response should be the same as the content of 'README.md'
|
19
21
|
|
20
22
|
|
21
23
|
Scenario: Peeking a response that does not exist
|
22
|
-
When I
|
24
|
+
When I send GET to 'http://localhost:7001/mirage/templates/1'
|
23
25
|
Then a 404 should be returned
|
24
26
|
|
25
27
|
|
@@ -17,9 +17,9 @@ Feature: Mirage can be primed with a set of responses.
|
|
17
17
|
end
|
18
18
|
"""
|
19
19
|
And I run 'mirage start'
|
20
|
-
When I
|
20
|
+
When I send GET to 'http://localhost:7001/mirage/responses/greeting'
|
21
21
|
Then 'hello' should be returned
|
22
|
-
When I
|
22
|
+
When I send GET to 'http://localhost:7001/mirage/responses/leaving'
|
23
23
|
Then 'goodbye' should be returned
|
24
24
|
|
25
25
|
|
@@ -31,7 +31,7 @@ Feature: Mirage can be primed with a set of responses.
|
|
31
31
|
end
|
32
32
|
"""
|
33
33
|
And I run 'mirage start -d ./custom_responses_location'
|
34
|
-
When I
|
34
|
+
When I send GET to 'http://localhost:7001/mirage/responses/greeting'
|
35
35
|
Then 'hello' should be returned
|
36
36
|
|
37
37
|
|
@@ -43,8 +43,8 @@ Feature: Mirage can be primed with a set of responses.
|
|
43
43
|
end
|
44
44
|
"""
|
45
45
|
And I run 'mirage start -d /tmp/responses'
|
46
|
-
When I
|
47
|
-
And I
|
46
|
+
When I send PUT to 'http://localhost:7001/mirage/defaults'
|
47
|
+
And I send GET to 'http://localhost:7001/mirage/responses/greeting'
|
48
48
|
Then 'hello' should be returned
|
49
49
|
|
50
50
|
|
@@ -56,14 +56,16 @@ Feature: Mirage can be primed with a set of responses.
|
|
56
56
|
end
|
57
57
|
"""
|
58
58
|
And I run 'mirage start'
|
59
|
-
And I
|
60
|
-
And I
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
59
|
+
And I send DELETE to 'http://localhost:7001/mirage/templates'
|
60
|
+
And I send PUT to 'http://localhost:7001/mirage/templates/a_new_response' with request entity
|
61
|
+
"""
|
62
|
+
new response
|
63
|
+
"""
|
64
|
+
|
65
|
+
When I send PUT to 'http://localhost:7001/mirage/defaults'
|
66
|
+
When I send GET to 'http://localhost:7001/mirage/responses/greeting'
|
65
67
|
Then 'hello' should be returned
|
66
|
-
When I
|
68
|
+
When I send GET to 'http://localhost:7001/mirage/responses/a_new_response'
|
67
69
|
Then a 404 should be returned
|
68
70
|
|
69
71
|
|
@@ -82,7 +84,7 @@ Feature: Mirage can be primed with a set of responses.
|
|
82
84
|
"""
|
83
85
|
A file with a mistake in it
|
84
86
|
"""
|
85
|
-
And I
|
87
|
+
And I send PUT to 'http://localhost:7001/mirage/defaults'
|
86
88
|
Then a 500 should be returned
|
87
89
|
|
88
90
|
|
@@ -7,10 +7,9 @@ Feature: Parts of a response can be substitued for values found in the request b
|
|
7
7
|
|
8
8
|
|
9
9
|
Scenario: A response template populated from matches found in the request body using a regex
|
10
|
-
Given I
|
11
|
-
|
|
12
|
-
|
13
|
-
When I hit 'http://localhost:7001/mirage/get/greeting' with request body:
|
10
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello ${<firstname>(.*?)</firstname>} ${<surname>(.*?)</surname>}, how are you?' and headers:
|
11
|
+
| X-mirage-method | POST |
|
12
|
+
When I send POST to 'http://localhost:7001/mirage/responses/greeting' with request entity
|
14
13
|
"""
|
15
14
|
<grettingRequest>
|
16
15
|
<firstname>Leon</firstname>
|
@@ -21,27 +20,21 @@ Feature: Parts of a response can be substitued for values found in the request b
|
|
21
20
|
|
22
21
|
|
23
22
|
Scenario: A response template populated from match found in the query string using a request parameter name
|
24
|
-
Given I
|
25
|
-
|
26
|
-
|
27
|
-
When I hit 'http://localhost:7001/mirage/get/greeting' with parameters:
|
23
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello ${name}, how are you?'
|
24
|
+
When I send GET to 'http://localhost:7001/mirage/responses/greeting' with parameters:
|
28
25
|
| name | Leon |
|
29
26
|
Then 'Hello Leon, how are you?' should be returned
|
30
27
|
|
31
28
|
|
32
29
|
Scenario: Response template populated from match found in the query string using a regex
|
33
|
-
Given I
|
34
|
-
|
35
|
-
|
36
|
-
When I hit 'http://localhost:7001/mirage/get/greeting' with parameters:
|
30
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello ${name=([L\|l]eon)}, how are you?'
|
31
|
+
When I send GET to 'http://localhost:7001/mirage/responses/greeting' with parameters:
|
37
32
|
| parameter | value |
|
38
33
|
| name | Leon |
|
39
34
|
Then 'Hello Leon, how are you?' should be returned
|
40
35
|
|
41
36
|
|
42
37
|
Scenario: No match is found in either the request body or query string
|
43
|
-
Given I
|
44
|
-
|
45
|
-
|
46
|
-
When I hit 'http://localhost:7001/mirage/get/greeting'
|
38
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello ${<name>(.*?)</name>}, how are you?'
|
39
|
+
When I send GET to 'http://localhost:7001/mirage/responses/greeting'
|
47
40
|
Then 'Hello ${<name>(.*?)</name>}, how are you?' should be returned
|
@@ -4,22 +4,19 @@ Feature: Having set up the Mirage with a number of defaults, your tests may cont
|
|
4
4
|
Mirage provides the ability to save of its current state and to revert it back to that state.
|
5
5
|
|
6
6
|
Background: The MockServer has been setup with some default responses
|
7
|
-
Given I
|
8
|
-
| response | The default greeting |
|
9
|
-
|
7
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'The default greeting'
|
10
8
|
|
9
|
+
|
11
10
|
Scenario: Saving Mirage and reverting it
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
When I hit 'http://localhost:7001/mirage/get/leaving'
|
11
|
+
And I send PUT to 'http://localhost:7001/mirage/backup'
|
12
|
+
|
13
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/leaving' with body 'Goodbye'
|
14
|
+
And I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Changed'
|
15
|
+
|
16
|
+
And I send PUT to 'http://localhost:7001/mirage'
|
17
|
+
|
18
|
+
When I send GET to 'http://localhost:7001/mirage/responses/leaving'
|
22
19
|
Then a 404 should be returned
|
23
20
|
|
24
|
-
When I
|
21
|
+
When I send GET to 'http://localhost:7001/mirage/responses/greeting'
|
25
22
|
Then 'The default greeting' should be returned
|
data/features/server/set.feature
CHANGED
@@ -1,40 +1,67 @@
|
|
1
|
-
Feature: Mirage can be configured with
|
1
|
+
Feature: Mirage can be configured with responses to be returned with the correct end point is hit.
|
2
2
|
On setting a response, a unique id is retuned. This is a key that can be used to manage the response. E.g. clearing or peek at it.
|
3
3
|
|
4
4
|
Usage:
|
5
|
-
|
5
|
+
HTTP METHOD: PUT -> /mirage/responses/your/response
|
6
|
+
Content type -> application/json
|
7
|
+
|
8
|
+
content:
|
9
|
+
response (mandatatory) = your response
|
10
|
+
pattern (optional) = criteria for when a response should be returned. see set_with_a_pattern.feature
|
11
|
+
delay (optional) = the amount of time in seconds that mirage should wait for before responding (defaults to 0)
|
12
|
+
method (optional) = http method that this response applies to. (defaults to get if not supplied)
|
13
|
+
default (optional) = set whether the reponse can act as a default response, see set_default_response.feature (defaults to false)
|
14
|
+
content-type = Set the content type to be returned
|
6
15
|
|
7
16
|
|
8
17
|
Scenario: Setting a response without any selection criteria
|
9
|
-
Given I
|
10
|
-
| response | Hello, how are you? |
|
18
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello'
|
11
19
|
|
12
|
-
When I
|
13
|
-
Then 'Hello
|
20
|
+
When I send GET to 'http://localhost:7001/mirage/responses/greeting'
|
21
|
+
Then 'Hello' should be returned
|
14
22
|
|
15
23
|
Scenario: A response hosted on a longer url
|
16
|
-
Given I
|
17
|
-
| response | Hello to me |
|
24
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/say/hello/to/me' with body 'Hello to me'
|
18
25
|
|
19
|
-
When I
|
26
|
+
When I send GET to 'http://localhost:7001/mirage/responses/say/hello/to/me'
|
20
27
|
Then 'Hello to me' should be returned
|
21
28
|
|
29
|
+
Scenario: Content type is set
|
30
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/say/hello/to/me' with body '<xml></xml>' and headers:
|
31
|
+
|content-type|text/xml|
|
32
|
+
|
33
|
+
When I send GET to 'http://localhost:7001/mirage/responses/say/hello/to/me'
|
34
|
+
Then '<xml></xml>' should be returned
|
35
|
+
And the response 'content-type' should be 'text/xml'
|
36
|
+
|
22
37
|
|
23
38
|
Scenario: The same endpoint is set more than once
|
24
|
-
Given I
|
25
|
-
| response | Hello |
|
39
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello'
|
26
40
|
Then '1' should be returned
|
27
41
|
|
28
|
-
Given I
|
29
|
-
| response | Hi |
|
42
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hi'
|
30
43
|
Then '1' should be returned
|
31
44
|
|
32
45
|
|
33
|
-
Scenario:
|
34
|
-
Given I
|
35
|
-
|
46
|
+
Scenario Outline: Response set to respond to different http methods
|
47
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'GET' and headers:
|
48
|
+
| X-mirage-method | GET |
|
49
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'POST' and headers:
|
50
|
+
| X-mirage-method | POST |
|
51
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'DELETE' and headers:
|
52
|
+
| X-mirage-method | DELETE |
|
53
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'PUT' and headers:
|
54
|
+
| X-mirage-method | PUT |
|
55
|
+
When I send <method> to 'http://localhost:7001/mirage/responses/greeting'
|
56
|
+
Then '<method>' should be returned
|
57
|
+
Examples:
|
58
|
+
| method |
|
59
|
+
| GET |
|
60
|
+
| POST |
|
61
|
+
| PUT |
|
62
|
+
| DELETE |
|
36
63
|
|
37
64
|
|
38
65
|
Scenario: Getting a response that does not exist
|
39
|
-
When I
|
66
|
+
When I send GET to 'http://localhost:7001/mirage/responses/response_that_does_not_exist'
|
40
67
|
Then a 404 should be returned
|
@@ -12,37 +12,31 @@ Feature: Mirage can respond with a 'default' response when a when the response r
|
|
12
12
|
Root responses can cause unexpected behaviour and so in order to qualify as a default reponse a client must knowingly mark it as one.
|
13
13
|
|
14
14
|
Scenario: A default response is returned
|
15
|
-
Given I
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
When I hit 'http://localhost:7001/mirage/get/level1/level2'
|
15
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/level0/level1' with body 'another level'
|
16
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/level1' with body 'level 1' and headers:
|
17
|
+
| X-mirage-default | true |
|
18
|
+
|
19
|
+
When I send GET to 'http://localhost:7001/mirage/responses/level1/level2'
|
22
20
|
Then 'level 1' should be returned
|
23
21
|
|
24
22
|
|
25
23
|
Scenario: More than one potential default response exists
|
26
|
-
Given I
|
27
|
-
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
| default |
|
32
|
-
|
33
|
-
|
|
34
|
-
|
35
|
-
|
|
36
|
-
|
37
|
-
|
38
|
-
| default | true |
|
39
|
-
|
40
|
-
When I hit 'http://localhost:7001/mirage/get/level1/level2/level3/level4'
|
24
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/level1' with body 'level 1' and headers:
|
25
|
+
| X-mirage-default | true |
|
26
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/level1/level2' with body 'level 2' and headers:
|
27
|
+
| X-mirage-default | true |
|
28
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/level1/level2/level3' with body 'level 3' and headers:
|
29
|
+
| X-mirage-default | false |
|
30
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/level1/level2/level3/level4' with body 'level 4' and headers:
|
31
|
+
| X-mirage-pattern | a pattern that wont be matched |
|
32
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/leve11/level2/level3/level4/level5' with body 'level 5' and headers:
|
33
|
+
| X-mirage-default | true |
|
34
|
+
|
35
|
+
When I send GET to 'http://localhost:7001/mirage/responses/level1/level2/level3/level4'
|
41
36
|
Then 'level 2' should be returned
|
42
37
|
|
43
38
|
|
44
39
|
Scenario: There isnt a default response
|
45
|
-
Given I
|
46
|
-
|
47
|
-
When I hit 'http://localhost:7001/mirage/get/level1/level2'
|
40
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/level1' with body 'level 1'
|
41
|
+
When I send GET to 'http://localhost:7001/mirage/responses/level1/level2'
|
48
42
|
Then a 404 should be returned
|
@@ -2,9 +2,7 @@ Feature: Its possible introduce a delay before responding to a client with a par
|
|
2
2
|
conditions by making your application wait before receiving a response.
|
3
3
|
|
4
4
|
Scenario: Response with a delay
|
5
|
-
Given I
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
When I hit 'http://localhost:7001/mirage/get/an_appology'
|
5
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/an_appology' with body 'Sorry' and headers:
|
6
|
+
| X-mirage-delay | 4.2 |
|
7
|
+
When I send GET to 'http://localhost:7001/mirage/responses/an_appology'
|
10
8
|
Then it should take at least '4.2' seconds
|
@@ -4,15 +4,15 @@ Feature: Mirage can be configured to return particular responses conditionally b
|
|
4
4
|
Patterns can be either plain text or a regular expression
|
5
5
|
|
6
6
|
Background: There is already a default response for 'greeting'
|
7
|
-
Given I
|
8
|
-
|
|
9
|
-
|
7
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello Stranger' and headers:
|
8
|
+
| X-mirage-method | POST |
|
10
9
|
|
11
10
|
Scenario: A plain text pattern found in the request body
|
12
|
-
|
13
|
-
|
14
|
-
| pattern
|
15
|
-
|
11
|
+
|
12
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello Leon, how are you?' and headers:
|
13
|
+
| X-mirage-pattern | <name>leon</name> |
|
14
|
+
| X-mirage-method | POST |
|
15
|
+
When I send POST to 'http://localhost:7001/mirage/responses/greeting' with request entity
|
16
16
|
"""
|
17
17
|
<greetingRequest>
|
18
18
|
<name>leon</name>
|
@@ -22,11 +22,10 @@ Feature: Mirage can be configured to return particular responses conditionally b
|
|
22
22
|
|
23
23
|
|
24
24
|
Scenario: A regex based pattern found in the request body
|
25
|
-
Given I
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
29
|
-
When I hit 'http://localhost:7001/mirage/get/greeting' with request body:
|
25
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello Leon, how are you?' and headers:
|
26
|
+
| X-mirage-pattern | .*?leon<\/name> |
|
27
|
+
| X-mirage-method | POST |
|
28
|
+
When I send POST to 'http://localhost:7001/mirage/responses/greeting' with request entity
|
30
29
|
"""
|
31
30
|
<greetingRequest>
|
32
31
|
<name>leon</name>
|
@@ -36,37 +35,33 @@ Feature: Mirage can be configured to return particular responses conditionally b
|
|
36
35
|
|
37
36
|
|
38
37
|
Scenario: A plain text pattern found in the query string
|
39
|
-
Given I
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
43
|
-
When I hit 'http://localhost:7001/mirage/get/greeting' with parameters:
|
38
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello Leon, how are you?' and headers:
|
39
|
+
| X-mirage-pattern | leon |
|
40
|
+
| X-mirage-method | POST |
|
41
|
+
When I send POST to 'http://localhost:7001/mirage/responses/greeting' with parameters:
|
44
42
|
| name | leon |
|
45
|
-
|
46
43
|
Then 'Hello Leon, how are you?' should be returned
|
47
44
|
|
48
45
|
|
49
46
|
Scenario: A regex based pattern found in the query string
|
50
|
-
Given I
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
54
|
-
When I hit 'http://localhost:7001/mirage/get/greeting' with parameters:
|
47
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello Leon, how are you?' and headers:
|
48
|
+
| X-mirage-pattern | name=[L\|l]eon |
|
49
|
+
| X-mirage-method | POST |
|
50
|
+
When I send POST to 'http://localhost:7001/mirage/responses/greeting' with parameters:
|
55
51
|
| name | leon |
|
56
52
|
|
57
53
|
Then 'Hello Leon, how are you?' should be returned
|
58
54
|
|
59
55
|
|
60
56
|
Scenario: The pattern is not matched
|
61
|
-
Given I
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
65
|
-
When I hit 'http://localhost:7001/mirage/get/greeting' with request body:
|
57
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello Leon, how are you?' and headers:
|
58
|
+
| X-mirage-pattern | .*?leon<\/name> |
|
59
|
+
| X-mirage-method | POST |
|
60
|
+
When I send POST to 'http://localhost:7001/mirage/responses/greeting' with request entity
|
66
61
|
"""
|
67
62
|
<greetingRequest>
|
68
63
|
<name>jim</name>
|
69
64
|
</greetingRequest>
|
70
65
|
"""
|
71
66
|
|
72
|
-
Then 'Hello Stranger
|
67
|
+
Then 'Hello Stranger' should be returned
|
@@ -0,0 +1,71 @@
|
|
1
|
+
Feature: After a response has been served from Mirage, the content of the request that triggered it can be retrieved. This is useful
|
2
|
+
for testing that the correct information was sent to the endpoint.
|
3
|
+
|
4
|
+
On setting a response, a unique id is returned which can be used to look up the last request made to get that response.
|
5
|
+
|
6
|
+
If the the response is reset then the same id is returned in order to make it easier to keep track of.
|
7
|
+
|
8
|
+
Responses hosted on the same endpoint but with a pattern are considered unique and so get their own ID.
|
9
|
+
|
10
|
+
If the request body contains content this is stored. Otherwise it is the query string that is stored.
|
11
|
+
|
12
|
+
If a response is 'peeked' this does not count as a request that should be stored.
|
13
|
+
|
14
|
+
Background: There is a response already on Mirage
|
15
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello' and headers:
|
16
|
+
| X-mirage-method | POST |
|
17
|
+
|
18
|
+
|
19
|
+
Scenario: Tracking a response that was triggered by a request that had content in the body
|
20
|
+
Given I send POST to 'http://localhost:7001/mirage/responses/greeting' with request entity
|
21
|
+
"""
|
22
|
+
Hello Mirage
|
23
|
+
"""
|
24
|
+
When I send GET to 'http://localhost:7001/mirage/requests/1'
|
25
|
+
Then 'Hello Mirage' should be returned
|
26
|
+
|
27
|
+
|
28
|
+
Scenario: Tracking a response that was triggered by a request with a query string
|
29
|
+
Given I send POST to 'http://localhost:7001/mirage/responses/greeting' with parameters:
|
30
|
+
| surname | Davis |
|
31
|
+
| firstname | Leon |
|
32
|
+
When I send GET to 'http://localhost:7001/mirage/requests/1'
|
33
|
+
Then 'surname=Davis&firstname=Leon' should be returned
|
34
|
+
|
35
|
+
|
36
|
+
Scenario: Tracking a response that has not been served yet
|
37
|
+
Given I send GET to 'http://localhost:7001/mirage/requests/1'
|
38
|
+
Then a 404 should be returned
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
Scenario: A response is peeked at
|
43
|
+
Given I send POST to 'http://localhost:7001/mirage/responses/greeting' with request entity
|
44
|
+
"""
|
45
|
+
Hello
|
46
|
+
"""
|
47
|
+
And I send GET to 'http://localhost:7001/mirage/templates/1'
|
48
|
+
When I send GET to 'http://localhost:7001/mirage/requests/1'
|
49
|
+
Then 'Hello' should be returned
|
50
|
+
|
51
|
+
|
52
|
+
Scenario: A default response and one for the same endpoint with a pattern are set
|
53
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello who ever you are'
|
54
|
+
Then '2' should be returned
|
55
|
+
|
56
|
+
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello' and headers:
|
57
|
+
| X-mirage-pattern | Leon |
|
58
|
+
Then '3' should be returned
|
59
|
+
|
60
|
+
When I send GET to 'http://localhost:7001/mirage/responses/greeting' with parameters:
|
61
|
+
| name | Joel |
|
62
|
+
And I send GET to 'http://localhost:7001/mirage/responses/greeting' with parameters:
|
63
|
+
| name | Leon |
|
64
|
+
|
65
|
+
And I send GET to 'http://localhost:7001/mirage/requests/2'
|
66
|
+
Then 'name=Joel' should be returned
|
67
|
+
|
68
|
+
And I send GET to 'http://localhost:7001/mirage/requests/3'
|
69
|
+
Then 'name=Leon' should be returned
|
70
|
+
|
71
|
+
|