mirage 2.4.2 → 3.0.0.alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.simplecov +6 -0
- data/Gemfile +11 -3
- data/Gemfile.lock +41 -14
- data/VERSION +1 -1
- data/features/client/clear.feature +41 -50
- data/features/client/configure.feature +2 -2
- data/features/client/put.feature +17 -6
- data/features/client/requests.feature +5 -9
- data/features/client/start.feature +19 -11
- data/features/client/stop.feature +10 -44
- data/features/server/commandline_interface/start.feature +2 -14
- data/features/server/commandline_interface/stop.feature +6 -4
- data/features/server/logging.feature +2 -2
- data/features/server/prime.feature +11 -66
- data/features/server/requests/delete.feature +34 -33
- data/features/server/requests/get.feature +21 -18
- data/features/server/save_and_revert.feature +24 -11
- data/features/server/templates/delete.feature +29 -32
- data/features/server/templates/get.feature +44 -25
- data/features/server/templates/put/put.feature +55 -78
- data/features/server/templates/put/put_with_substitutions.feature +12 -32
- data/features/server/templates/put/required_content.feature +118 -0
- data/features/step_definitions/my_steps.rb +51 -6
- data/features/support/env.rb +1 -1
- data/features/support/hooks.rb +2 -5
- data/{lib/mirage/client → features/support}/web.rb +14 -3
- data/lib/mirage/client.rb +5 -2
- data/lib/mirage/client/client.rb +22 -129
- data/lib/mirage/client/request.rb +25 -0
- data/lib/mirage/client/requests.rb +13 -0
- data/lib/mirage/client/runner.rb +4 -4
- data/lib/mirage/client/template.rb +108 -0
- data/lib/mirage/client/template_configuration.rb +22 -0
- data/lib/mirage/client/templates.rb +26 -0
- data/mirage.gemspec +42 -22
- data/mirage_server.rb +1 -135
- data/rakefile +22 -7
- data/server/app.rb +4 -0
- data/server/binary_data_checker.rb +15 -0
- data/server/helpers.rb +28 -0
- data/server/mock_response.rb +140 -58
- data/server/server.rb +167 -0
- data/spec/{cli_bridge_spec.rb → client/cli_bridge_spec.rb} +15 -11
- data/spec/client/client_spec.rb +139 -0
- data/spec/client/request_spec.rb +52 -0
- data/spec/client/requests_spec.rb +10 -0
- data/spec/{runner_spec.rb → client/runner_spec.rb} +3 -3
- data/spec/client/template_configuration_spec.rb +32 -0
- data/spec/client/template_spec.rb +241 -0
- data/spec/client/templates_spec.rb +79 -0
- data/spec/resources/binary.file +0 -0
- data/spec/server/binary_data_checker_spec.rb +22 -0
- data/spec/server/helpers_spec.rb +34 -0
- data/spec/server/mock_response_spec.rb +526 -0
- data/spec/server/server_spec.rb +132 -0
- data/spec/spec_helper.rb +61 -2
- data/test.html +12 -0
- data/test.rb +20 -17
- data/todo.lst +2 -0
- data/views/index.haml +22 -0
- data/views/response.haml +24 -0
- metadata +134 -49
- data/features/server/templates/put/put_as_default.feature +0 -42
- data/features/server/templates/put/put_with_delay.feature +0 -8
- data/features/server/templates/put/put_with_pattern.feature +0 -80
- data/lib/mirage/client/response.rb +0 -29
- data/spec/client_spec.rb +0 -38
- data/views/index.erb +0 -28
@@ -1,42 +0,0 @@
|
|
1
|
-
Feature: A template can be configure as the default response for when there is no response found for a sub url.
|
2
|
-
I.e.
|
3
|
-
if a response is held for 'level1' and request comes in for 'level1/level2' the response for 'level1'
|
4
|
-
can be returned if nothing is held for 'level1/level2'
|
5
|
-
|
6
|
-
If a request is made and there is more than one response that could be appropriate then the closet is chosen.
|
7
|
-
|
8
|
-
E.g.
|
9
|
-
responses exist for: 'level1' and 'level1/level2'. If a response for 'level1/level2/level3 is made, then the response for
|
10
|
-
'level1/level2' will be returned as it is the most specific match out of the two.
|
11
|
-
|
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
|
-
|
14
|
-
Scenario: A default response is returned
|
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'
|
20
|
-
Then 'level 1' should be returned
|
21
|
-
|
22
|
-
|
23
|
-
Scenario: More than one potential default response exists
|
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'
|
36
|
-
Then 'level 2' should be returned
|
37
|
-
|
38
|
-
|
39
|
-
Scenario: There isnt a default response
|
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'
|
42
|
-
Then a 404 should be returned
|
@@ -1,8 +0,0 @@
|
|
1
|
-
Feature: Its possible introduce a delay before responding to a client with a particular response. This lets you simulate real world
|
2
|
-
conditions by making your application wait before receiving a response.
|
3
|
-
|
4
|
-
Scenario: Response with a delay
|
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'
|
8
|
-
Then it should take at least '4.2' seconds
|
@@ -1,80 +0,0 @@
|
|
1
|
-
Feature: Mirage can be configured to return particular responses conditionally based on if a prescribed pattern is found in
|
2
|
-
querystring or the body of a request.
|
3
|
-
|
4
|
-
Patterns can be either plain text or a regular expression
|
5
|
-
|
6
|
-
A response with a pattern is not considered the same a response at the same address that has either no pattern or a diffferent one.
|
7
|
-
This allows you to specify different behaviour depending on the request.
|
8
|
-
|
9
|
-
Background: There is already a default response for 'greeting'
|
10
|
-
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello Stranger' and headers:
|
11
|
-
| X-mirage-method | POST |
|
12
|
-
|
13
|
-
Scenario: A plain text pattern found in the request body
|
14
|
-
|
15
|
-
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello Leon, how are you?' and headers:
|
16
|
-
| X-mirage-pattern | <name>leon</name> |
|
17
|
-
| X-mirage-method | POST |
|
18
|
-
When I send POST to 'http://localhost:7001/mirage/responses/greeting' with request entity
|
19
|
-
"""
|
20
|
-
<greetingRequest>
|
21
|
-
<name>leon</name>
|
22
|
-
</greetingRequest>
|
23
|
-
"""
|
24
|
-
Then 'Hello Leon, how are you?' should be returned
|
25
|
-
|
26
|
-
|
27
|
-
Scenario: A regex based pattern found in the request body
|
28
|
-
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello Leon, how are you?' and headers:
|
29
|
-
| X-mirage-pattern | .*?leon<\/name> |
|
30
|
-
| X-mirage-method | POST |
|
31
|
-
When I send POST to 'http://localhost:7001/mirage/responses/greeting' with request entity
|
32
|
-
"""
|
33
|
-
<greetingRequest>
|
34
|
-
<name>leon</name>
|
35
|
-
</greetingRequest>
|
36
|
-
"""
|
37
|
-
Then 'Hello Leon, how are you?' should be returned
|
38
|
-
|
39
|
-
|
40
|
-
Scenario: A plain text pattern found in the query string
|
41
|
-
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello Leon, how are you?' and headers:
|
42
|
-
| X-mirage-pattern | leon |
|
43
|
-
| X-mirage-method | POST |
|
44
|
-
When I send POST to 'http://localhost:7001/mirage/responses/greeting' with parameters:
|
45
|
-
| name | leon |
|
46
|
-
Then 'Hello Leon, how are you?' should be returned
|
47
|
-
|
48
|
-
|
49
|
-
Scenario: A regex based pattern found in the query string
|
50
|
-
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello Leon, how are you?' and headers:
|
51
|
-
| X-mirage-pattern | name=[L\|l]eon |
|
52
|
-
| X-mirage-method | POST |
|
53
|
-
When I send POST to 'http://localhost:7001/mirage/responses/greeting' with parameters:
|
54
|
-
| name | leon |
|
55
|
-
|
56
|
-
Then 'Hello Leon, how are you?' should be returned
|
57
|
-
|
58
|
-
|
59
|
-
Scenario: The pattern is not matched
|
60
|
-
Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello Leon, how are you?' and headers:
|
61
|
-
| X-mirage-pattern | .*?leon<\/name> |
|
62
|
-
| X-mirage-method | POST |
|
63
|
-
When I send POST to 'http://localhost:7001/mirage/responses/greeting' with request entity
|
64
|
-
"""
|
65
|
-
<greetingRequest>
|
66
|
-
<name>jim</name>
|
67
|
-
</greetingRequest>
|
68
|
-
"""
|
69
|
-
|
70
|
-
Then 'Hello Stranger' should be returned
|
71
|
-
|
72
|
-
Scenario: Templates with different patterns on the same address
|
73
|
-
When I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello Leon, how are you?' and headers:
|
74
|
-
| X-mirage-pattern | 2 |
|
75
|
-
|
76
|
-
When I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello Leon, how are you?' and headers:
|
77
|
-
| X-mirage-pattern | 3 |
|
78
|
-
Then '3' should be returned
|
79
|
-
|
80
|
-
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'ostruct'
|
2
|
-
module Mirage
|
3
|
-
class Response
|
4
|
-
|
5
|
-
attr_accessor :content_type,:method, :pattern, :default, :status, :delay
|
6
|
-
attr_reader :value
|
7
|
-
|
8
|
-
def initialize response
|
9
|
-
@content_type = 'text/plain'
|
10
|
-
@value = response
|
11
|
-
@method = :get
|
12
|
-
@status = 200
|
13
|
-
@delay = 0
|
14
|
-
end
|
15
|
-
|
16
|
-
def headers
|
17
|
-
headers = {}
|
18
|
-
headers['Content-Type']=@content_type
|
19
|
-
headers['X-mirage-file'] = 'true' if @response.kind_of?(IO)
|
20
|
-
headers['X-mirage-method'] = @method
|
21
|
-
headers['X-mirage-pattern'] = @pattern if @pattern
|
22
|
-
headers['X-mirage-default'] = @default if @default == true
|
23
|
-
headers['X-mirage-status'] = @status
|
24
|
-
headers['X-mirage-delay'] = @delay
|
25
|
-
headers
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
data/spec/client_spec.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'mirage/client'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
describe Mirage::Client do
|
7
|
-
include Mirage
|
8
|
-
|
9
|
-
before :each do
|
10
|
-
@response = mock('response').as_null_object
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
it 'is configured to connect to local host port 7001 by default' do
|
15
|
-
client = Client.new
|
16
|
-
client.should_receive(:http_put).with(/localhost:7001/, anything, anything).and_return(@response)
|
17
|
-
client.put "greeting", "hello"
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'can be configured with a url pointing to Mirage' do
|
21
|
-
url = "http://url.for.mirage"
|
22
|
-
client = Client.new url
|
23
|
-
client.should_receive(:http_put).with(/#{url}/, anything, anything).and_return(@response)
|
24
|
-
client.put "greeting", "hello"
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'can be configured with a port refering to which port Mirage is running on on localhost' do
|
28
|
-
port = 9001
|
29
|
-
client = Client.new :port => port
|
30
|
-
client.should_receive(:http_put).with(/localhost:#{port}/, anything, anything).and_return(@response)
|
31
|
-
client.put "greeting", "hello"
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'raises an error if neither a port or url specified in the argument' do
|
35
|
-
expect{Client.new({})}.should raise_error()
|
36
|
-
expect{Client.new("rubbish")}.should raise_error()
|
37
|
-
end
|
38
|
-
end
|
data/views/index.erb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<!DOCTYPE html
|
3
|
-
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
6
|
-
<head>
|
7
|
-
<title>Mirage</title>
|
8
|
-
</head>
|
9
|
-
<body>
|
10
|
-
<h1>Welcome to Mirage</h1>
|
11
|
-
|
12
|
-
<p>Below are any responses you are currently hosting. Click the response itself to peek at it and click 'track' to view the last request that triggered it.<br/>
|
13
|
-
<br/>
|
14
|
-
Patterns and delays are shown for responses that have them.<br/>
|
15
|
-
<br/>
|
16
|
-
Responses with '*' at the end are default responses. I.e. they will be returned, where appropriate, for requests to a sub endpoint if a response is not found at that level.<br/>
|
17
|
-
<br/>
|
18
|
-
<strong>Note:</strong> if requests or responses contain xml, you will need to view page source to see it properly.</p>
|
19
|
-
|
20
|
-
<% unless @responses.empty? %>
|
21
|
-
<table border="1" width='100%'>
|
22
|
-
<% @responses.each do |key, response| %>
|
23
|
-
<tr><td><a id='peek_response_<%=response.response_id%>' href="/mirage/templates/<%=response.response_id%>"><%=key%></a></td><td><a id='track_response_<%=response.response_id%>' href="/mirage/requests/<%=response.response_id%>">track</a></td></tr>
|
24
|
-
<% end %>
|
25
|
-
</table>
|
26
|
-
<% end %>
|
27
|
-
</body>
|
28
|
-
</html>
|