mirage 3.0.0.alpha.11 → 3.0.0.alpha.12
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/features/.nav +19 -0
- data/features/client/clear.feature +15 -23
- data/features/client/configure.feature +24 -28
- data/features/client/preview_responses.feature +4 -4
- data/features/client/put.feature +49 -62
- data/features/client/requests.feature +1 -1
- data/features/client/running.feature +2 -2
- data/features/client/save_and_revert.feature +5 -8
- data/features/client/start.feature +3 -3
- data/features/client/stop.feature +8 -8
- data/features/commandline_interface/help.feature +17 -0
- data/features/commandline_interface/readme.md +1 -0
- data/features/{server/commandline_interface → commandline_interface}/start.feature +4 -4
- data/features/{server/commandline_interface → commandline_interface}/stop.feature +22 -24
- data/features/{server/logging.feature → logging.feature} +2 -2
- data/features/{server/prime.feature → prime.feature} +4 -3
- data/features/readme.md +7 -0
- data/features/requests/delete.feature +48 -0
- data/features/{server/requests → requests}/get.feature +6 -5
- data/features/{server/save_and_revert.feature → save_and_revert.feature} +5 -5
- data/features/step_definitions/my_steps.rb +47 -12
- data/features/support/command_line.rb +1 -1
- data/features/templates/delete.feature +45 -0
- data/features/{server/templates → templates}/get.feature +9 -5
- data/features/templates/put.feature +77 -0
- data/features/{server/templates/put → templates}/put_with_substitutions.feature +4 -3
- data/features/templates/readme.md +7 -0
- data/features/{server/templates/put → templates}/required_content.feature +27 -35
- data/features/{server/web_user_interface.feature → web_user_interface.feature} +8 -7
- data/lib/mirage/client/cli_bridge.rb +1 -1
- data/lib/mirage/client/client.rb +16 -3
- data/lib/mirage/client/error.rb +1 -1
- data/lib/mirage/client/runner.rb +1 -1
- data/lib/mirage/client/template.rb +4 -2
- data/lib/mirage/client/template/configuration.rb +10 -0
- data/lib/mirage/client/template/model/instance_methods.rb +3 -4
- data/lib/mirage/client/templates.rb +1 -1
- data/mirage.gemspec +21 -17
- data/mirage_server.rb +1 -1
- data/server/mock_response.rb +18 -17
- data/server/server.rb +15 -15
- data/spec/client/client_spec.rb +44 -10
- data/spec/client/template/model/common_methods_spec.rb +1 -1
- data/spec/client/template/model/instance_methods_spec.rb +2 -2
- data/spec/client/template_spec.rb +11 -4
- data/spec/client/templates_spec.rb +10 -4
- data/spec/server/server_spec.rb +23 -23
- data/test.rb +2 -19
- metadata +22 -18
- data/features/server/commandline_interface/help.feature +0 -16
- data/features/server/requests/delete.feature +0 -47
- data/features/server/templates/delete.feature +0 -44
- data/features/server/templates/put/put.feature +0 -62
@@ -18,7 +18,7 @@ Feature: The client API can be used to start Mirage.
|
|
18
18
|
"""
|
19
19
|
Mirage.start
|
20
20
|
"""
|
21
|
-
Then mirage should be running on 'http://localhost:7001
|
21
|
+
Then mirage should be running on 'http://localhost:7001'
|
22
22
|
|
23
23
|
|
24
24
|
Scenario: Starting Mirage on a custom port
|
@@ -26,7 +26,7 @@ Feature: The client API can be used to start Mirage.
|
|
26
26
|
"""
|
27
27
|
Mirage.start :port => 9001
|
28
28
|
"""
|
29
|
-
Then mirage should be running on 'http://localhost:9001
|
29
|
+
Then mirage should be running on 'http://localhost:9001'
|
30
30
|
|
31
31
|
|
32
32
|
Scenario: Specifying a custom templates directory.
|
@@ -40,5 +40,5 @@ Feature: The client API can be used to start Mirage.
|
|
40
40
|
"""
|
41
41
|
Mirage.start :defaults => './custom_responses_location'
|
42
42
|
"""
|
43
|
-
And GET is sent to '
|
43
|
+
And GET is sent to '/responses/greeting'
|
44
44
|
Then 'hello' should be returned
|
@@ -14,7 +14,7 @@ Feature:The client API can be used to stop instances of Mirage running on localh
|
|
14
14
|
"""
|
15
15
|
Mirage.stop
|
16
16
|
"""
|
17
|
-
Then Connection should be refused to 'http://localhost:7001
|
17
|
+
Then Connection should be refused to 'http://localhost:7001'
|
18
18
|
|
19
19
|
|
20
20
|
Scenario: Stopping Mirage on custom port
|
@@ -23,7 +23,7 @@ Feature:The client API can be used to stop instances of Mirage running on localh
|
|
23
23
|
"""
|
24
24
|
Mirage.stop :port => 9001
|
25
25
|
"""
|
26
|
-
Then mirage should not be running on 'http://localhost:9001
|
26
|
+
Then mirage should not be running on 'http://localhost:9001'
|
27
27
|
|
28
28
|
Scenario: Stopping multiple instances of Mirage
|
29
29
|
Given I run 'mirage start -p 7001'
|
@@ -33,9 +33,9 @@ Feature:The client API can be used to stop instances of Mirage running on localh
|
|
33
33
|
"""
|
34
34
|
Mirage.stop :port => [9001,10001]
|
35
35
|
"""
|
36
|
-
Then mirage should be running on 'http://localhost:7001
|
37
|
-
Then mirage should not be running on 'http://localhost:9001
|
38
|
-
Then mirage should not be running on 'http://localhost:10001
|
36
|
+
Then mirage should be running on 'http://localhost:7001'
|
37
|
+
Then mirage should not be running on 'http://localhost:9001'
|
38
|
+
Then mirage should not be running on 'http://localhost:10001'
|
39
39
|
|
40
40
|
|
41
41
|
Scenario: Stopping all instances of Mirage
|
@@ -46,6 +46,6 @@ Feature:The client API can be used to stop instances of Mirage running on localh
|
|
46
46
|
"""
|
47
47
|
Mirage.stop :all
|
48
48
|
"""
|
49
|
-
Then mirage should not be running on 'http://localhost:7001
|
50
|
-
Then mirage should not be running on 'http://localhost:9001
|
51
|
-
Then mirage should not be running on 'http://localhost:10001
|
49
|
+
Then mirage should not be running on 'http://localhost:7001'
|
50
|
+
Then mirage should not be running on 'http://localhost:9001'
|
51
|
+
Then mirage should not be running on 'http://localhost:10001'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
@command_line
|
2
|
+
Feature: Help
|
3
|
+
Mirage is started from the command line. Mirage logs to mirage.log at the path where Mirage is started from.
|
4
|
+
|
5
|
+
|
6
|
+
Background: Mirage usage
|
7
|
+
Given usage information:
|
8
|
+
"""
|
9
|
+
mirage help [TASK] # Describe available tasks or one specific task
|
10
|
+
mirage start # Starts mirage
|
11
|
+
mirage stop # Stops mirage
|
12
|
+
"""
|
13
|
+
|
14
|
+
|
15
|
+
Scenario: Starting with help option
|
16
|
+
Given I run 'mirage help'
|
17
|
+
Then the usage information should be displayed
|
@@ -0,0 +1 @@
|
|
1
|
+
Mirage has a fully functional commandline interface check it out!
|
@@ -1,6 +1,6 @@
|
|
1
1
|
@command_line
|
2
|
-
Feature: Mirage
|
3
|
-
more than instance of Mirage can be started on different ports at the same time.
|
2
|
+
Feature: Starting Mirage
|
3
|
+
Mirage is started from the command line. more than instance of Mirage can be started on different ports at the same time.
|
4
4
|
|
5
5
|
By default mirage runs on port 7001.
|
6
6
|
|
@@ -8,11 +8,11 @@ Feature: Mirage is started from the command line.
|
|
8
8
|
Scenario: Starting mirage
|
9
9
|
Given Mirage is not running
|
10
10
|
When I run 'mirage start'
|
11
|
-
Then mirage should be running on 'http://localhost:7001
|
11
|
+
Then mirage should be running on 'http://localhost:7001'
|
12
12
|
And 'mirage.log' should exist
|
13
13
|
|
14
14
|
|
15
15
|
Scenario: Starting Mirage on a custom port
|
16
16
|
Given Mirage is not running
|
17
17
|
When I run 'mirage start -p 9001'
|
18
|
-
Then mirage should be running on 'http://localhost:9001
|
18
|
+
Then mirage should be running on 'http://localhost:9001'
|
@@ -1,44 +1,42 @@
|
|
1
1
|
@command_line
|
2
|
-
Feature: Mirage
|
2
|
+
Feature: Stopping Mirage
|
3
|
+
Mirage can be stopped from the commandline
|
3
4
|
If more than one instance of Mirage is running, you will be asked to supply the ports which represent the running instances
|
4
5
|
of mirage that you wish to stop.
|
5
6
|
|
6
|
-
Scenario: Stopping a single instance
|
7
|
+
Scenario: Stopping a single instance of Mirage
|
7
8
|
Given I run 'mirage start -p 7001'
|
8
9
|
When I run 'mirage stop'
|
9
|
-
Then mirage should not be running on 'http://localhost:7001
|
10
|
+
Then mirage should not be running on 'http://localhost:7001'
|
10
11
|
|
11
|
-
|
12
|
-
Scenario: Calling stop when there is more than one instance running
|
13
|
-
Given I run 'mirage start -p 7001'
|
14
|
-
Given I run 'mirage start -p 9001'
|
15
|
-
When I run 'mirage stop'
|
16
|
-
Then I should see 'Mirage is running on ports 7001, 9001. Please run mirage stop -p [PORT(s)] instead' on the command line
|
17
|
-
And mirage should be running on 'http://localhost:7001/mirage'
|
18
|
-
And mirage should be running on 'http://localhost:9001/mirage'
|
19
|
-
|
20
|
-
|
21
|
-
Scenario: stopping on a single instance using the port
|
12
|
+
Scenario: Stopping an instance running on a given port
|
22
13
|
Given I run 'mirage start -p 7001'
|
23
14
|
And I run 'mirage start -p 9001'
|
24
15
|
When I run 'mirage stop -p 7001'
|
25
|
-
Then mirage should be running on 'http://localhost:9001
|
26
|
-
Then mirage should not be running on 'http://localhost:7001
|
16
|
+
Then mirage should be running on 'http://localhost:9001'
|
17
|
+
Then mirage should not be running on 'http://localhost:7001'
|
27
18
|
|
28
|
-
Scenario:
|
19
|
+
Scenario: Stopping more than one instance
|
29
20
|
Given I run 'mirage start -p 7001'
|
30
21
|
And I run 'mirage start -p 9001'
|
31
22
|
And I run 'mirage start -p 10001'
|
32
23
|
When I run 'mirage stop -p 7001 9001'
|
33
|
-
Then mirage should be running on 'http://localhost:10001
|
34
|
-
Then mirage should not be running on 'http://localhost:7001
|
35
|
-
Then mirage should not be running on 'http://localhost:9001
|
24
|
+
Then mirage should be running on 'http://localhost:10001'
|
25
|
+
Then mirage should not be running on 'http://localhost:7001'
|
26
|
+
Then mirage should not be running on 'http://localhost:9001'
|
36
27
|
|
37
|
-
Scenario:
|
28
|
+
Scenario: Stopping all running instances
|
38
29
|
Given I run 'mirage start -p 7001'
|
39
30
|
And I run 'mirage start -p 9001'
|
40
31
|
When I run 'mirage stop -p all'
|
41
|
-
Then mirage should not be running on 'http://localhost:10001
|
42
|
-
Then mirage should not be running on 'http://localhost:7001
|
43
|
-
Then mirage should not be running on 'http://localhost:9001
|
32
|
+
Then mirage should not be running on 'http://localhost:10001'
|
33
|
+
Then mirage should not be running on 'http://localhost:7001'
|
34
|
+
Then mirage should not be running on 'http://localhost:9001'
|
44
35
|
|
36
|
+
Scenario: Calling stop when there is more than one instance running
|
37
|
+
Given I run 'mirage start -p 7001'
|
38
|
+
Given I run 'mirage start -p 9001'
|
39
|
+
When I run 'mirage stop'
|
40
|
+
Then I should see 'Mirage is running on ports 7001, 9001. Please run mirage stop -p [PORT(s)] instead' on the command line
|
41
|
+
And mirage should be running on 'http://localhost:7001'
|
42
|
+
And mirage should be running on 'http://localhost:9001'
|
@@ -2,5 +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: Mirage logs request
|
5
|
-
Given GET is sent to '
|
6
|
-
Then mirage.log should contain '/
|
5
|
+
Given GET is sent to '/templates/greeting'
|
6
|
+
Then mirage.log should contain '/templates/greeting'
|
@@ -1,6 +1,7 @@
|
|
1
1
|
#TODO - rename responses directory to templates
|
2
2
|
@command_line
|
3
|
-
Feature:
|
3
|
+
Feature: Preloading templates
|
4
|
+
Mirage can be primed with a set of templates.
|
4
5
|
By default, Mirage loads any .rb files found in ./responses on startup. Mirage can also be made to load responses from a directory
|
5
6
|
of your choosing by using the -d/--defaults option
|
6
7
|
|
@@ -17,7 +18,7 @@ Feature: Mirage can be primed with a set of templates.
|
|
17
18
|
end
|
18
19
|
"""
|
19
20
|
And I run 'mirage start'
|
20
|
-
When GET is sent to '
|
21
|
+
When GET is sent to '/responses/greeting'
|
21
22
|
Then 'hello' should be returned
|
22
23
|
|
23
24
|
|
@@ -30,5 +31,5 @@ Feature: Mirage can be primed with a set of templates.
|
|
30
31
|
end
|
31
32
|
"""
|
32
33
|
And I run 'mirage start --defaults /tmp/responses'
|
33
|
-
And GET is sent to '
|
34
|
+
And GET is sent to '/responses/greeting'
|
34
35
|
Then 'hello' should be returned
|
data/features/readme.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Mirage in an open source project that can be used to mock HTTP services. It facilitates application development in environments where external systems aren't easily accessed or can't be made to behave in a repeatable way.
|
2
|
+
|
3
|
+
At its core, Mirage is a web application with a restful interface that can be configured with responses. The descriptors for these response are called [Templates](/lashd/mirage/docs/templates).
|
4
|
+
|
5
|
+
If you're using Ruby then Mirage has a [client](/lashd/mirage/docs/client) to get you going straight away.
|
6
|
+
|
7
|
+
If you're using another language, then the interface to Mirage is simple and it would be great to see clients emerging other languages too. If you need any help please ask! :)
|
@@ -0,0 +1,48 @@
|
|
1
|
+
Feature: Deleting tracked requests
|
2
|
+
Tracked request data can be deleted
|
3
|
+
|
4
|
+
Background: The MockServer has already got a response for greeting and leaving on it.
|
5
|
+
Given the following template template:
|
6
|
+
"""
|
7
|
+
{
|
8
|
+
"response":{
|
9
|
+
"body":"Hello"
|
10
|
+
}
|
11
|
+
}
|
12
|
+
"""
|
13
|
+
And 'response.body' is base64 encoded
|
14
|
+
And the template is sent using PUT to '/templates/greeting'
|
15
|
+
|
16
|
+
Given the following template template:
|
17
|
+
"""
|
18
|
+
{
|
19
|
+
"response":{
|
20
|
+
"body":"Goodbye"
|
21
|
+
}
|
22
|
+
}
|
23
|
+
"""
|
24
|
+
And 'response.body' is base64 encoded
|
25
|
+
And the template is sent using PUT to '/templates/leaving'
|
26
|
+
|
27
|
+
|
28
|
+
And GET is sent to '/responses/greeting'
|
29
|
+
And GET is sent to '/responses/leaving'
|
30
|
+
|
31
|
+
|
32
|
+
Scenario: Deleting all requests
|
33
|
+
And DELETE is sent to '/requests'
|
34
|
+
|
35
|
+
When GET is sent to '/requests/1'
|
36
|
+
Then a 404 should be returned
|
37
|
+
When GET is sent to '/requests/2'
|
38
|
+
Then a 404 should be returned
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
Scenario: Deleting a stored request for a particular response
|
43
|
+
And DELETE is sent to '/requests/1'
|
44
|
+
|
45
|
+
When GET is sent to '/requests/1'
|
46
|
+
Then a 404 should be returned
|
47
|
+
When GET is sent to '/requests/2'
|
48
|
+
Then a 200 should be returned
|
@@ -1,4 +1,5 @@
|
|
1
|
-
Feature:
|
1
|
+
Feature: Checking tracked requests
|
2
|
+
After a response has been served from Mirage, the request that triggered it can be retrieved. This is useful
|
2
3
|
for testing that the correct information was sent by your application code.
|
3
4
|
|
4
5
|
Use a template's ID to retrieve the last request that was last received.
|
@@ -17,19 +18,19 @@ Feature: After a response has been served from Mirage, the request that triggere
|
|
17
18
|
}
|
18
19
|
"""
|
19
20
|
And 'response.body' is base64 encoded
|
20
|
-
And the template is sent using PUT to '
|
21
|
+
And the template is sent using PUT to '/templates/greeting'
|
21
22
|
|
22
23
|
|
23
24
|
Scenario: Getting request data when the data was in the body.
|
24
|
-
Given I send POST to '
|
25
|
+
Given I send POST to '/responses/greeting' with request entity
|
25
26
|
"""
|
26
27
|
Hello Mirage
|
27
28
|
"""
|
28
|
-
When GET is sent to '
|
29
|
+
When GET is sent to '/requests/1'
|
29
30
|
Then request data should have been retrieved
|
30
31
|
|
31
32
|
|
32
33
|
Scenario: Getting request data for a template that has not yet served a response.
|
33
|
-
Given GET is sent to '
|
34
|
+
Given GET is sent to '/requests/1'
|
34
35
|
Then a 404 should be returned
|
35
36
|
|
@@ -13,11 +13,11 @@ Feature: Having set up the Mirage with a number of defaults, your tests may cont
|
|
13
13
|
}
|
14
14
|
"""
|
15
15
|
And 'response.body' is base64 encoded
|
16
|
-
And the template is sent using PUT to '
|
16
|
+
And the template is sent using PUT to '/templates/greeting'
|
17
17
|
|
18
18
|
|
19
19
|
Scenario: Saving Mirage and reverting it
|
20
|
-
Given PUT is sent to '
|
20
|
+
Given PUT is sent to '/backup'
|
21
21
|
And the following template template:
|
22
22
|
"""
|
23
23
|
{
|
@@ -27,9 +27,9 @@ Feature: Having set up the Mirage with a number of defaults, your tests may cont
|
|
27
27
|
}
|
28
28
|
"""
|
29
29
|
And 'response.body' is base64 encoded
|
30
|
-
And the template is sent using PUT to '
|
30
|
+
And the template is sent using PUT to '/templates/greeting'
|
31
31
|
|
32
|
-
When PUT is sent to '
|
33
|
-
And GET is sent to '
|
32
|
+
When PUT is sent to '/'
|
33
|
+
And GET is sent to '/responses/greeting'
|
34
34
|
|
35
35
|
Then 'The default greeting' should be returned
|
@@ -66,11 +66,11 @@ Given /^the file '(.*)' contains:$/ do |file_path, content|
|
|
66
66
|
end
|
67
67
|
|
68
68
|
Then /^the usage information should be displayed$/ do
|
69
|
-
@usage.
|
69
|
+
@usage.each_line { |line| @commandline_output.should include(line) }
|
70
70
|
end
|
71
71
|
|
72
|
-
Given /^usage information:$/ do |
|
73
|
-
@usage =
|
72
|
+
Given /^usage information:$/ do |usage|
|
73
|
+
@usage = normalise(usage.to_s)
|
74
74
|
end
|
75
75
|
|
76
76
|
Then /^I run$/ do |text|
|
@@ -88,8 +88,8 @@ Given /^the following gems are required to run the Mirage client test code:$/ do
|
|
88
88
|
@code_snippet = text.gsub("\"", "\\\\\"")
|
89
89
|
end
|
90
90
|
|
91
|
-
When /^I send (POST|PUT) to '(
|
92
|
-
|
91
|
+
When /^I send (POST|PUT) to '(.*)' with request entity$/ do |method, endpoint, entity|
|
92
|
+
url = "http://localhost:7001#{endpoint}"
|
93
93
|
@response = case method
|
94
94
|
when 'POST'
|
95
95
|
then
|
@@ -100,8 +100,9 @@ When /^I send (POST|PUT) to '(http:\/\/localhost:7001\/mirage\/(.*?))' with requ
|
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
-
When /^(GET|PUT|POST|OPTIONS|HEAD|DELETE) is sent to '(
|
103
|
+
When /^(GET|PUT|POST|OPTIONS|HEAD|DELETE) is sent to '([^']*)'$/ do |method, endpoint|
|
104
104
|
start_time = Time.now
|
105
|
+
url = "http://localhost:7001#{endpoint}"
|
105
106
|
@response = case method
|
106
107
|
when 'GET' then
|
107
108
|
http_get(url)
|
@@ -120,7 +121,8 @@ When /^(GET|PUT|POST|OPTIONS|HEAD|DELETE) is sent to '(http:\/\/localhost:\d{4}\
|
|
120
121
|
end
|
121
122
|
|
122
123
|
|
123
|
-
When /^I send (PUT|POST) to '(
|
124
|
+
When /^I send (PUT|POST) to '(.*)' with body '(.*)'$/ do |method, endpoint, body|
|
125
|
+
url = "http://localhost:7001#{endpoint}"
|
124
126
|
start_time = Time.now
|
125
127
|
@response = case method
|
126
128
|
when 'PUT'
|
@@ -132,7 +134,8 @@ When /^I send (PUT|POST) to '(http:\/\/localhost:7001\/mirage\/([^']*))' with bo
|
|
132
134
|
@response_time = Time.now - start_time
|
133
135
|
end
|
134
136
|
|
135
|
-
When /^I send PUT to '(
|
137
|
+
When /^I send PUT to '(.*)' with body '([^']*)' and headers:$/ do |endpoint, body, table|
|
138
|
+
url = "http://localhost:7001#{endpoint}"
|
136
139
|
headers = {}
|
137
140
|
table.raw.each do |row|
|
138
141
|
parameter, value = row[0], row[1]
|
@@ -166,8 +169,10 @@ When /^I click '(.*)'$/ do |thing|
|
|
166
169
|
@page = @page.links.find { |link| link.attributes['id'] == thing }.click
|
167
170
|
end
|
168
171
|
|
169
|
-
When /^I send (GET|POST) to '(
|
172
|
+
When /^I send (GET|POST) to '(.*)' with parameters:$/ do |http_method, endpoint, table|
|
173
|
+
|
170
174
|
|
175
|
+
url = "http://localhost:7001#{endpoint}"
|
171
176
|
parameters = {}
|
172
177
|
table.raw.each do |row|
|
173
178
|
parameter, value = row[0].to_sym, row[1]
|
@@ -199,7 +204,8 @@ Given /^I send PUT to '(http:\/\/localhost:7001\/mirage\/(.*?))' with file: ([^'
|
|
199
204
|
end
|
200
205
|
end
|
201
206
|
|
202
|
-
Given /^I send PUT to '(
|
207
|
+
Given /^I send PUT to '(.*?)' with body '([^']*)' and parameters:$/ do |endpoint, body, table|
|
208
|
+
url = "http://localhost:7001#{endpoint}"
|
203
209
|
headers = {}
|
204
210
|
table.raw.each do |row|
|
205
211
|
parameter, value = row[0], row[1]
|
@@ -227,8 +233,9 @@ end
|
|
227
233
|
When /^'(.*)' is base64 encoded$/ do |template_component|
|
228
234
|
@response_template.send(:eval, "#{template_component}=Base64.encode64(#{template_component})")
|
229
235
|
end
|
230
|
-
When /^the template is sent using PUT to '(
|
231
|
-
|
236
|
+
When /^the template is sent using PUT to '(.*?)'$/ do |endpoint|
|
237
|
+
|
238
|
+
@response = http_put("http://localhost:7001#{endpoint}", @response_template.to_hash.to_json, :headers => {"Content-Type" => "application/json"})
|
232
239
|
end
|
233
240
|
Given /^a template for '(.*)' has been set with a value of '(.*)'$/ do |endpoint, value|
|
234
241
|
$mirage.templates.put(endpoint, value)
|
@@ -240,4 +247,32 @@ Then /^request data should have been retrieved$/ do
|
|
240
247
|
request_data.include?('headers').should == true
|
241
248
|
request_data.include?('body').should == true
|
242
249
|
request_data.include?('request_url').should == true
|
250
|
+
end
|
251
|
+
Given(/^the following Template JSON:$/) do |text|
|
252
|
+
@response_template = Hashie::Mash.new(JSON.parse(text))
|
253
|
+
end
|
254
|
+
Then(/^the template (request|response) specification should have the following set:$/) do |spec, table|
|
255
|
+
template_json = JSON.parse(http_get("http://localhost:7001/templates/#{JSON.parse(@response.body)['id']}").body)
|
256
|
+
request_specification = template_json[spec]
|
257
|
+
request_specification.size.should==table.hashes.size
|
258
|
+
table.hashes.each do |hash|
|
259
|
+
default = request_specification[hash['Setting'].downcase.gsub(' ', '_')]
|
260
|
+
case required_default = hash['Default']
|
261
|
+
when 'none'
|
262
|
+
case default
|
263
|
+
when Array
|
264
|
+
default.should == []
|
265
|
+
when Hash
|
266
|
+
default.should == {}
|
267
|
+
else
|
268
|
+
default.should == ""
|
269
|
+
|
270
|
+
end
|
271
|
+
else
|
272
|
+
default.to_s.downcase.should == required_default.downcase
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
Then(/^the following json should be returned:$/) do |text|
|
277
|
+
JSON.parse(text).should == JSON.parse(@response.body)
|
243
278
|
end
|