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
@@ -0,0 +1,45 @@
|
|
1
|
+
Feature: Deleting
|
2
|
+
When a template is deleted, any tracked request data is also removed.
|
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
|
+
Scenario: Deleting all templates
|
29
|
+
Given DELETE is sent to '/templates'
|
30
|
+
When GET is sent to '/responses/greeting'
|
31
|
+
Then a 404 should be returned
|
32
|
+
When GET is sent to '/responses/leaving'
|
33
|
+
Then a 404 should be returned
|
34
|
+
|
35
|
+
|
36
|
+
Scenario: Deleting a particular template
|
37
|
+
Given DELETE is sent to '/templates/1'
|
38
|
+
|
39
|
+
When GET is sent to '/responses/greeting'
|
40
|
+
Then a 404 should be returned
|
41
|
+
|
42
|
+
When GET is sent to '/responses/leaving'
|
43
|
+
Then a 200 should be returned
|
44
|
+
|
45
|
+
|
@@ -1,4 +1,5 @@
|
|
1
|
-
Feature:
|
1
|
+
Feature: Retrieving
|
2
|
+
Templates can be retrieved by using the ID that was returned when they were created
|
2
3
|
|
3
4
|
|
4
5
|
Scenario: Retrieving a template
|
@@ -23,11 +24,14 @@ Feature: Templates can be retrieved by using the ID that was returned when they
|
|
23
24
|
}
|
24
25
|
}
|
25
26
|
"""
|
26
|
-
And the template is sent using PUT to '
|
27
|
-
When GET is sent to '
|
28
|
-
Then the following should be returned:
|
27
|
+
And the template is sent using PUT to '/templates/greeting'
|
28
|
+
When GET is sent to '/templates/1'
|
29
|
+
Then the following json should be returned:
|
29
30
|
"""
|
30
31
|
{
|
32
|
+
"id": 1,
|
33
|
+
"endpoint": "greeting",
|
34
|
+
"requests_url": "http://localhost:7001/requests/1",
|
31
35
|
"response":{
|
32
36
|
"default":false,
|
33
37
|
"body":"Hello",
|
@@ -39,8 +43,8 @@ Feature: Templates can be retrieved by using the ID that was returned when they
|
|
39
43
|
"parameters":{
|
40
44
|
|
41
45
|
},
|
46
|
+
"headers":{},
|
42
47
|
"body_content":[
|
43
|
-
|
44
48
|
],
|
45
49
|
"http_method":"get"
|
46
50
|
}
|
@@ -0,0 +1,77 @@
|
|
1
|
+
Feature: Creating a Template
|
2
|
+
Mirage can be configured with Templates. Templates describe the characteristics of responses that should be returned to a client. In addition to this a templates also describe the conditions under which a template may be used to generate a response.
|
3
|
+
|
4
|
+
On setting a template, a unique id is returned. This is a key that can be used to manage the Template.
|
5
|
+
|
6
|
+
Templates can be configured to respond to either, GET, POST, PUT, or DELETE.
|
7
|
+
|
8
|
+
More than one Template can be placed at the same resource address as long as they have different request contraints. In this case they are given different IDs. For example if two templates are configured to respond to request using different HTTP methods then they will not overwrite each other but both be stored.
|
9
|
+
|
10
|
+
Requirements can be specified as required when configuring a Template:
|
11
|
+
* request parameters
|
12
|
+
* body content
|
13
|
+
* HTTP Headers
|
14
|
+
* HTTP Method
|
15
|
+
|
16
|
+
The following attributes of a response can be configured
|
17
|
+
* HTTP status code
|
18
|
+
* Whether this template is to be treated as the default response if a match is not found for a sub URI
|
19
|
+
* A delay before the response is returned to the client. This is in seconds and floats are accepted
|
20
|
+
* Content-Type
|
21
|
+
|
22
|
+
Things to note:
|
23
|
+
---------------
|
24
|
+
The body attribute of the response should be Base64 encoded. This is so that you may specify binary data if that is what you would like to send back to clients.
|
25
|
+
|
26
|
+
|
27
|
+
Scenario: Setting a Template on Mirage
|
28
|
+
Given the following Template JSON:
|
29
|
+
"""
|
30
|
+
{
|
31
|
+
"request":{
|
32
|
+
"parameters":{},
|
33
|
+
"http_method":"get",
|
34
|
+
"headers": {},
|
35
|
+
"body_content":[]
|
36
|
+
},
|
37
|
+
"response":{
|
38
|
+
"default":false,
|
39
|
+
"body":"SGVsbG8=",
|
40
|
+
"delay":0,
|
41
|
+
"content_type":"text/plain",
|
42
|
+
"status":200
|
43
|
+
}
|
44
|
+
}
|
45
|
+
"""
|
46
|
+
When the template is sent using PUT to '/templates/greeting'
|
47
|
+
Then '{"id":1}' should be returned
|
48
|
+
|
49
|
+
When GET is sent to '/responses/greeting'
|
50
|
+
Then 'Hello' should be returned
|
51
|
+
And a 200 should be returned
|
52
|
+
|
53
|
+
|
54
|
+
Scenario: Template defaults
|
55
|
+
Given the following Template JSON:
|
56
|
+
"""
|
57
|
+
{}
|
58
|
+
"""
|
59
|
+
When the template is sent using PUT to '/templates/greeting'
|
60
|
+
Then the template request specification should have the following set:
|
61
|
+
| Setting | Default |
|
62
|
+
| parameters | none |
|
63
|
+
| body content | none |
|
64
|
+
| headers | none |
|
65
|
+
| HTTP method | GET |
|
66
|
+
And the template response specification should have the following set:
|
67
|
+
| Setting | Default |
|
68
|
+
| default | false |
|
69
|
+
| body | none |
|
70
|
+
| content_type | text/plain |
|
71
|
+
| delay | 0 |
|
72
|
+
| status | 200 |
|
73
|
+
|
74
|
+
Scenario: Making a request that is unmatched
|
75
|
+
When GET is sent to '/responses/unmatched'
|
76
|
+
Then a 404 should be returned
|
77
|
+
|
@@ -1,4 +1,5 @@
|
|
1
|
-
Feature:
|
1
|
+
Feature: Substituting values from requests in to a template
|
2
|
+
Parts of a response can be substitued for values found in the request body or query string.
|
2
3
|
This allows dynamic content to be sent back to a client.
|
3
4
|
|
4
5
|
To do this, substitution, matchers must be put in the the response value.
|
@@ -15,7 +16,7 @@ Feature: Parts of a response can be substitued for values found in the request b
|
|
15
16
|
}
|
16
17
|
"""
|
17
18
|
And 'response.body' is base64 encoded
|
18
|
-
And the template is sent using PUT to '
|
19
|
-
When I send GET to '
|
19
|
+
And the template is sent using PUT to '/templates/greeting'
|
20
|
+
When I send GET to '/responses/greeting' with parameters:
|
20
21
|
|name|Joe |
|
21
22
|
Then 'Hello Joe' should be returned
|
@@ -1,4 +1,5 @@
|
|
1
|
-
Feature:
|
1
|
+
Feature: Placing requirements on requests
|
2
|
+
If you want Mirage to be choosy when using a Template to generate a response the following can have requirements placed on them when looking for a suitable to Template to generate responses:
|
2
3
|
|
3
4
|
* request parameters
|
4
5
|
* body content
|
@@ -27,29 +28,28 @@ Feature: Templates set requirements on the following in order for them to be use
|
|
27
28
|
}
|
28
29
|
"""
|
29
30
|
And 'response.body' is base64 encoded
|
30
|
-
And the template is sent using PUT to '
|
31
|
+
And the template is sent using PUT to '/templates/greeting'
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
# And the template is sent using PUT to 'http://localhost:7001/mirage/templates/greeting'
|
33
|
+
Scenario: Configuring a template with requirements on HTTP headers
|
34
|
+
Given the following template template:
|
35
|
+
"""
|
36
|
+
{
|
37
|
+
"request":{
|
38
|
+
"parameters":{},
|
39
|
+
"http_method":"get",
|
40
|
+
"body_content":[]
|
41
|
+
},
|
42
|
+
"response":{
|
43
|
+
"default":false,
|
44
|
+
"body":"Hello Stranger",
|
45
|
+
"delay":0,
|
46
|
+
"content_type":"text/plain",
|
47
|
+
"status":200
|
48
|
+
}
|
49
|
+
}
|
50
|
+
"""
|
51
|
+
And 'response.body' is base64 encoded
|
52
|
+
And the template is sent using PUT to '/templates/greeting'
|
53
53
|
|
54
54
|
|
55
55
|
Scenario: Configuring a template with requirements on request parameters
|
@@ -74,9 +74,9 @@ Feature: Templates set requirements on the following in order for them to be use
|
|
74
74
|
}
|
75
75
|
"""
|
76
76
|
And 'response.body' is base64 encoded
|
77
|
-
And the template is sent using PUT to '
|
77
|
+
And the template is sent using PUT to '/templates/greeting'
|
78
78
|
|
79
|
-
When I send GET to '
|
79
|
+
When I send GET to '/responses/greeting' with parameters:
|
80
80
|
|firstname|Joe |
|
81
81
|
|surname |Blogs|
|
82
82
|
Then 'Hello Joe' should be returned
|
@@ -100,17 +100,9 @@ Feature: Templates set requirements on the following in order for them to be use
|
|
100
100
|
}
|
101
101
|
"""
|
102
102
|
And 'response.body' is base64 encoded
|
103
|
-
And the template is sent using PUT to '
|
103
|
+
And the template is sent using PUT to '/templates/greeting'
|
104
104
|
|
105
|
-
When I send POST to '
|
106
|
-
"""
|
107
|
-
{
|
108
|
-
"credentials" : {
|
109
|
-
"username" : "Joe",
|
110
|
-
"password" : "Blogs"
|
111
|
-
}
|
112
|
-
}
|
113
|
-
"""
|
105
|
+
When I send POST to '/responses/greeting' with body '{"username":"Joe Blogs"}'
|
114
106
|
Then 'Hello Joe' should be returned
|
115
107
|
|
116
108
|
|
@@ -1,4 +1,5 @@
|
|
1
|
-
Feature:
|
1
|
+
Feature: Web interface
|
2
|
+
Mirage's home page allows you to see what response are currently being hosted.
|
2
3
|
From this page you can:
|
3
4
|
- Peek at a responses content
|
4
5
|
- Track the response to see if a request has been made to it
|
@@ -6,26 +7,26 @@ Feature: Mirage's home page allows you to see what response are currently being
|
|
6
7
|
#TODO tests needed for displaying pattern and delay values and http method
|
7
8
|
|
8
9
|
Background: There are already a couple of responses hosted on he Mirage server
|
9
|
-
Given I send PUT to '
|
10
|
+
Given I send PUT to '/templates/greeting' with body 'hello' and headers:
|
10
11
|
| X-mirage-default | true |
|
11
12
|
| X-mirage-method | POST |
|
12
|
-
And I send PUT to '
|
13
|
+
And I send PUT to '/templates/leaving' with body 'goodbye'
|
13
14
|
|
14
15
|
Scenario: Using the home page to see what response are being hosted
|
15
|
-
Given I goto '
|
16
|
+
Given I goto ''
|
16
17
|
Then I should see 'greeting/*'
|
17
18
|
Then I should see 'leaving'
|
18
19
|
|
19
20
|
Scenario: Using the home page to peek at a response
|
20
|
-
Given I goto '
|
21
|
+
Given I goto ''
|
21
22
|
When I click 'peek_response_1'
|
22
23
|
Then I should see 'hello'
|
23
24
|
|
24
25
|
Scenario: Using the home page to track if a request has been made
|
25
|
-
Given I send POST to '
|
26
|
+
Given I send POST to '/responses/greeting' with request entity
|
26
27
|
"""
|
27
28
|
Yo!
|
28
29
|
"""
|
29
|
-
Given I goto '
|
30
|
+
Given I goto ''
|
30
31
|
When I click 'track_response_1'
|
31
32
|
Then I should see 'Yo!'
|
@@ -3,7 +3,7 @@ module CLIBridge
|
|
3
3
|
def mirage_process_ids ports
|
4
4
|
mirage_instances = {}
|
5
5
|
["Mirage Server", "mirage_server", "mirage server"].each do |process_name|
|
6
|
-
processes_with_name(process_name).
|
6
|
+
processes_with_name(process_name).each_line.collect { |line| line.chomp }.each do |process_line|
|
7
7
|
pid = process_line.split(' ')[1]
|
8
8
|
port = process_line[/port (\d+)/, 1]
|
9
9
|
mirage_instances[port] = pid
|
data/lib/mirage/client/client.rb
CHANGED
@@ -9,24 +9,33 @@ module Mirage
|
|
9
9
|
|
10
10
|
attr_reader :url
|
11
11
|
|
12
|
-
def initialize options={:url => "http://localhost:7001
|
12
|
+
def initialize options={:url => "http://localhost:7001"}, &block
|
13
13
|
if options.is_a?(String) && options =~ URI.regexp
|
14
14
|
warn("Client.new(url): Deprecated usage, please use :url => url | :port => port")
|
15
15
|
@url = options
|
16
16
|
elsif options.kind_of?(Hash) && options[:port]
|
17
|
-
@url = "http://localhost:#{options[:port]}
|
17
|
+
@url = "http://localhost:#{options[:port]}"
|
18
18
|
elsif options.kind_of?(Hash) && options[:url]
|
19
19
|
@url = options[:url]
|
20
20
|
else
|
21
21
|
raise "specify a valid URL or port"
|
22
22
|
end
|
23
23
|
|
24
|
+
@templates = Templates.new(@url)
|
25
|
+
@templates.default_config &block if block
|
26
|
+
end
|
27
|
+
|
28
|
+
def configure &block
|
24
29
|
templates.default_config &block if block
|
25
30
|
end
|
26
31
|
|
32
|
+
def reset
|
33
|
+
templates.default_config.reset
|
34
|
+
end
|
35
|
+
|
27
36
|
def templates id=nil
|
28
37
|
return Template.get("#{@url}/templates/#{id}") if id
|
29
|
-
|
38
|
+
@templates
|
30
39
|
end
|
31
40
|
|
32
41
|
def requests id=nil
|
@@ -57,5 +66,9 @@ module Mirage
|
|
57
66
|
def == client
|
58
67
|
client.instance_of?(Client) && self.url == client.url
|
59
68
|
end
|
69
|
+
|
70
|
+
def running?
|
71
|
+
Mirage.running? @url
|
72
|
+
end
|
60
73
|
end
|
61
74
|
end
|
data/lib/mirage/client/error.rb
CHANGED
data/lib/mirage/client/runner.rb
CHANGED
@@ -42,7 +42,7 @@ module Mirage
|
|
42
42
|
# Mirage.running? :port => port -> boolean indicating whether Mirage is running on *locally* on the given port
|
43
43
|
# Mirage.running? url -> boolean indicating whether Mirage is running on the given URL
|
44
44
|
def running? options_or_url = {:port => 7001}
|
45
|
-
url = options_or_url.kind_of?(Hash) ? "http://localhost:#{options_or_url[:port]}
|
45
|
+
url = options_or_url.kind_of?(Hash) ? "http://localhost:#{options_or_url[:port]}" : options_or_url
|
46
46
|
HTTParty.get(url) and return true
|
47
47
|
rescue Errno::ECONNREFUSED
|
48
48
|
return false
|
@@ -18,12 +18,14 @@ module Mirage
|
|
18
18
|
alias_method :backedup_get, :get
|
19
19
|
|
20
20
|
def get url
|
21
|
-
|
21
|
+
response = backedup_get(url, :format => :json)
|
22
|
+
raise ResponseNotFound if response.code == 404
|
23
|
+
response_hashie = Hashie::Mash.new response
|
22
24
|
|
23
25
|
response_config = response_hashie.response
|
24
26
|
request_config = response_hashie.request
|
25
27
|
|
26
|
-
template = new(response_hashie.endpoint, response_config.body)
|
28
|
+
template = new(response_hashie.endpoint, Base64.decode64(response_config.body))
|
27
29
|
|
28
30
|
template.id response_hashie.id
|
29
31
|
template.default response_config['default']
|
@@ -29,6 +29,16 @@ module Mirage
|
|
29
29
|
@caller_binding.send method, *args, &block if @caller_binding
|
30
30
|
end
|
31
31
|
|
32
|
+
def == config
|
33
|
+
config.is_a?(Configuration) &&
|
34
|
+
http_method == config.http_method &&
|
35
|
+
status == config.status &&
|
36
|
+
delay == config.delay &&
|
37
|
+
content_type == config.content_type &&
|
38
|
+
default == config.default
|
39
|
+
|
40
|
+
end
|
41
|
+
|
32
42
|
end
|
33
43
|
end
|
34
44
|
end
|
@@ -49,16 +49,15 @@ module Mirage
|
|
49
49
|
:status => status,
|
50
50
|
:default => default,
|
51
51
|
:content_type => content_type,
|
52
|
-
:headers => headers
|
53
|
-
|
52
|
+
:headers => headers,
|
53
|
+
:delay => delay
|
54
54
|
},
|
55
55
|
:request => {
|
56
56
|
:parameters => encode_regexs(required_parameters),
|
57
57
|
:headers => encode_regexs(required_headers),
|
58
58
|
:body_content => encode_regexs(required_body_content),
|
59
59
|
:http_method => http_method,
|
60
|
-
}
|
61
|
-
:delay => delay
|
60
|
+
}
|
62
61
|
}.to_json
|
63
62
|
end
|
64
63
|
|