mirage 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +50 -0
- data/README.md +93 -0
- data/bin/mirage +54 -0
- data/features/checking_for_requests.feature +74 -0
- data/features/clearing_requests_and_responses.feature +81 -0
- data/features/client/checking_for_requests.feature +20 -0
- data/features/client/clearing_responses.feature +75 -0
- data/features/client/getting_responses.feature +30 -0
- data/features/client/mirage_client.feature +36 -0
- data/features/client/peeking.feature +32 -0
- data/features/client/setting_responses.feature +91 -0
- data/features/client/snapshotting.feature +34 -0
- data/features/command_line_iterface.feature +39 -0
- data/features/default_responses.feature +91 -0
- data/features/file_hosting.feature +8 -0
- data/features/logging.feature +7 -0
- data/features/peeking_at_response.feature +24 -0
- data/features/resources/test.zip +0 -0
- data/features/response_templates.feature +45 -0
- data/features/root_responses.feature +47 -0
- data/features/setting_responses.feature +40 -0
- data/features/setting_responses_with_a_delay.feature +10 -0
- data/features/setting_responses_with_pattern_matching.feature +72 -0
- data/features/snapshotting.feature +25 -0
- data/features/step_definitions/my_steps.rb +127 -0
- data/features/support/env.rb +89 -0
- data/features/web_user_interface.feature +39 -0
- data/full_build.sh +100 -0
- data/lib/config.ru +5 -0
- data/lib/mirage.rb +14 -0
- data/lib/mirage/client.rb +140 -0
- data/lib/mirage/core.rb +206 -0
- data/lib/mirage/util.rb +40 -0
- data/lib/mirage/web.rb +65 -0
- data/lib/start_mirage.rb +15 -0
- data/lib/view/mirage/index.xhtml +23 -0
- data/mirage.gemspec +40 -0
- data/rakefile +50 -0
- metadata +199 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
Feature: the Mirage client provides a method for getting responses
|
2
|
+
There is no need to escape any parameters before using the client api as this is done for you.
|
3
|
+
|
4
|
+
Background:
|
5
|
+
Given the following gems are required to run the Mirage client test code:
|
6
|
+
"""
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rspec'
|
9
|
+
require 'mirage'
|
10
|
+
"""
|
11
|
+
And I post to 'http://localhost:7001/mirage/set/greeting' with parameters:
|
12
|
+
| response | hello |
|
13
|
+
|
14
|
+
Scenario: getting a response
|
15
|
+
Given I run
|
16
|
+
"""
|
17
|
+
Mirage::Client.new.get('greeting').should == 'hello'
|
18
|
+
"""
|
19
|
+
|
20
|
+
Scenario: getting a response that does not exist
|
21
|
+
Given I run
|
22
|
+
"""
|
23
|
+
begin
|
24
|
+
Mirage::Client.new.get('response_that_does_not_exits').should == 'hello'
|
25
|
+
fail("Error should have been thrown")
|
26
|
+
rescue Exception => e
|
27
|
+
e.is_a?(Mirage::ResponseNotFound).should == true
|
28
|
+
end
|
29
|
+
"""
|
30
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
@command_line
|
2
|
+
Feature: Interacting with Mirage is done via HTTP using REST style URLs and therefore you can interact with it in any language.
|
3
|
+
If however you are using Ruby, and you want to, you can use the Mirage Client that comes in the Mirage distribution.
|
4
|
+
|
5
|
+
By default the client is configured to connect to an instance of the Mirage server on localhost:7001 which is where
|
6
|
+
the Mirage server starts on by default.
|
7
|
+
|
8
|
+
Background:
|
9
|
+
Given the following gems are required to run the Mirage client test code:
|
10
|
+
"""
|
11
|
+
require 'rubygems'
|
12
|
+
require 'rspec'
|
13
|
+
require 'mirage'
|
14
|
+
"""
|
15
|
+
|
16
|
+
|
17
|
+
Scenario: checking if mirage is running
|
18
|
+
Then I run
|
19
|
+
"""
|
20
|
+
Mirage::Client.new.running?.should == false
|
21
|
+
"""
|
22
|
+
Given Mirage is running
|
23
|
+
Then I run
|
24
|
+
"""
|
25
|
+
Mirage::Client.new.running?.should == true
|
26
|
+
"""
|
27
|
+
|
28
|
+
|
29
|
+
Scenario: connecting to mirage running on a different url
|
30
|
+
Given I run 'mirage start -p 9001'
|
31
|
+
Then I run
|
32
|
+
"""
|
33
|
+
Mirage::Client.new("http://localhost:9001/mirage").running?.should == true
|
34
|
+
"""
|
35
|
+
|
36
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
Feature: the client can be used for peeking at responses hosted on Mirage.
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given the following gems are required to run the Mirage client test code:
|
5
|
+
"""
|
6
|
+
require 'rubygems'
|
7
|
+
require 'rspec'
|
8
|
+
require 'mirage'
|
9
|
+
"""
|
10
|
+
|
11
|
+
Scenario: peeking a response
|
12
|
+
Given I hit 'http://localhost:7001/mirage/set/greeting' with parameters:
|
13
|
+
| response | Hello |
|
14
|
+
|
15
|
+
When I run
|
16
|
+
"""
|
17
|
+
Mirage::Client.new.peek(1).should == 'Hello'
|
18
|
+
"""
|
19
|
+
|
20
|
+
When I hit 'http://localhost:7001/mirage/check/1'
|
21
|
+
Then a 404 should be returned
|
22
|
+
|
23
|
+
Scenario: getting a response that does not exist
|
24
|
+
Given I run
|
25
|
+
"""
|
26
|
+
begin
|
27
|
+
Mirage::Client.new.peek(2).should == 'this should not have happened'
|
28
|
+
fail("Error should have been thrown")
|
29
|
+
rescue Exception => e
|
30
|
+
e.is_a?(Mirage::ResponseNotFound).should == true
|
31
|
+
end
|
32
|
+
"""
|
@@ -0,0 +1,91 @@
|
|
1
|
+
Feature: the Mirage client provides methods for setting responses and loading default responses.
|
2
|
+
There is no need to escape any parameters before using the client api as this is done for you.
|
3
|
+
|
4
|
+
Background:
|
5
|
+
Given the following gems are required to run the Mirage client test code:
|
6
|
+
"""
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rspec'
|
9
|
+
require 'mirage'
|
10
|
+
"""
|
11
|
+
|
12
|
+
Scenario: Setting a basic response
|
13
|
+
Given I run
|
14
|
+
"""
|
15
|
+
Mirage::Client.new.set('greeting',:response => 'hello')
|
16
|
+
"""
|
17
|
+
When I hit 'http://localhost:7001/mirage/get/greeting'
|
18
|
+
Then 'hello' should be returned
|
19
|
+
|
20
|
+
Scenario: Setting a response with a pattern
|
21
|
+
Given I run
|
22
|
+
"""
|
23
|
+
Mirage::Client.new.set('greeting', :response => 'Hello Leon', :pattern => '.*?>leon</name>')
|
24
|
+
"""
|
25
|
+
When I hit 'http://localhost:7001/mirage/get/greeting'
|
26
|
+
Then a 404 should be returned
|
27
|
+
When I hit 'http://localhost:7001/mirage/get/greeting' with request body:
|
28
|
+
"""
|
29
|
+
<greetingRequest>
|
30
|
+
<name>leon</name>
|
31
|
+
</greetingRequest>
|
32
|
+
"""
|
33
|
+
Then 'Hello Leon' should be returned
|
34
|
+
|
35
|
+
Scenario: Loading default responses
|
36
|
+
Given Mirage is not running
|
37
|
+
And I run 'mirage start'
|
38
|
+
|
39
|
+
When the file 'defaults/default_greetings.rb' contains:
|
40
|
+
"""
|
41
|
+
Mirage.default do |mirage|
|
42
|
+
mirage.set('greeting', :response => 'hello')
|
43
|
+
mirage.set('leaving', :response => 'goodbye')
|
44
|
+
end
|
45
|
+
"""
|
46
|
+
And I run
|
47
|
+
"""
|
48
|
+
Mirage::Client.new.load_defaults
|
49
|
+
"""
|
50
|
+
And I hit 'http://localhost:7001/mirage/get/greeting'
|
51
|
+
Then 'hello' should be returned
|
52
|
+
|
53
|
+
When I hit 'http://localhost:7001/mirage/get/leaving'
|
54
|
+
Then 'goodbye' should be returned
|
55
|
+
|
56
|
+
|
57
|
+
Scenario: Setting defaults and one of the files has something bad in it
|
58
|
+
Given the file 'defaults/default_greetings.rb' contains:
|
59
|
+
"""
|
60
|
+
Something bad...
|
61
|
+
"""
|
62
|
+
When I run
|
63
|
+
"""
|
64
|
+
begin
|
65
|
+
Mirage::Client.new.load_defaults
|
66
|
+
fail("Error should have been thrown")
|
67
|
+
rescue Exception => e
|
68
|
+
e.is_a?(Mirage::InternalServerException).should == true
|
69
|
+
end
|
70
|
+
"""
|
71
|
+
|
72
|
+
|
73
|
+
Scenario: Setting a file as a response
|
74
|
+
Given I run
|
75
|
+
"""
|
76
|
+
Mirage::Client.new.set('download', :file => File.open('features/resources/test.zip'))
|
77
|
+
"""
|
78
|
+
When I hit 'http://localhost:7001/mirage/get/download'
|
79
|
+
Then the response should be a file the same as 'features/resources/test.zip'
|
80
|
+
|
81
|
+
|
82
|
+
Scenario: A response or file is not supplied
|
83
|
+
Given I run
|
84
|
+
"""
|
85
|
+
begin
|
86
|
+
Mirage::Client.new.set('download',{})
|
87
|
+
fail("Error should have been thrown")
|
88
|
+
rescue Exception => e
|
89
|
+
e.is_a?(Mirage::InternalServerException).should == true
|
90
|
+
end
|
91
|
+
"""
|
@@ -0,0 +1,34 @@
|
|
1
|
+
Feature: The Mirage client can be used to snaphsot and rollback the Mirage server
|
2
|
+
|
3
|
+
|
4
|
+
Background:
|
5
|
+
Given the following gems are required to run the Mirage client test code:
|
6
|
+
"""
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rspec'
|
9
|
+
require 'mirage'
|
10
|
+
"""
|
11
|
+
And I hit 'http://localhost:7001/mirage/set/greeting' with parameters:
|
12
|
+
| response | The default greeting |
|
13
|
+
|
14
|
+
|
15
|
+
Scenario: Taking a snapshot and rolling it back
|
16
|
+
Given I run
|
17
|
+
"""
|
18
|
+
Mirage::Client.new.snapshot
|
19
|
+
"""
|
20
|
+
And I hit 'http://localhost:7001/mirage/set/leaving' with parameters:
|
21
|
+
| response | Goodye |
|
22
|
+
|
23
|
+
And I hit 'http://localhost:7001/mirage/set/greeting' with parameters:
|
24
|
+
| response | Changed |
|
25
|
+
|
26
|
+
When I run
|
27
|
+
"""
|
28
|
+
Mirage::Client.new.rollback
|
29
|
+
"""
|
30
|
+
And I hit 'http://localhost:7001/mirage/get/leaving'
|
31
|
+
Then a 404 should be returned
|
32
|
+
|
33
|
+
When I hit 'http://localhost:7001/mirage/get/greeting'
|
34
|
+
Then 'The default greeting' should be returned
|
@@ -0,0 +1,39 @@
|
|
1
|
+
@command_line
|
2
|
+
Feature: Mirage is started from the command line.
|
3
|
+
Mirage logs to mirage.log at the path where Mirage is started from
|
4
|
+
|
5
|
+
|
6
|
+
Background: Mirage usage
|
7
|
+
Given usage information:
|
8
|
+
| Usage: mirage start\|stop [options] |
|
9
|
+
| -p, --port PORT |
|
10
|
+
| -d, --defaults DIR |
|
11
|
+
|
12
|
+
|
13
|
+
Scenario: Starting with help option
|
14
|
+
Given I run 'mirage start --help'
|
15
|
+
Then the usage information should be displayed
|
16
|
+
|
17
|
+
|
18
|
+
Scenario: Starting with an invalid option
|
19
|
+
Given I run 'mirage start --invalid-option'
|
20
|
+
Then the usage information should be displayed
|
21
|
+
|
22
|
+
|
23
|
+
Scenario: Starting mirage
|
24
|
+
Given Mirage is not running
|
25
|
+
When I run 'mirage start'
|
26
|
+
Then mirage should be running on 'http://localhost:7001/mirage'
|
27
|
+
And 'mirage.log' should exist
|
28
|
+
|
29
|
+
|
30
|
+
Scenario: Stopping Mirage
|
31
|
+
Given I run 'mirage start'
|
32
|
+
When I run 'mirage stop'
|
33
|
+
Then Connection should be refused to 'http://localhost:7001/mirage'
|
34
|
+
|
35
|
+
|
36
|
+
Scenario: Starting Mirage on a custom port
|
37
|
+
Given Mirage is not running
|
38
|
+
When I run 'mirage start -p 9001'
|
39
|
+
Then mirage should be running on 'http://localhost:9001/mirage'
|
@@ -0,0 +1,91 @@
|
|
1
|
+
@command_line
|
2
|
+
Feature: Mirage can be primed with a default responses.
|
3
|
+
By default, Mirage loads any rb files found in ./defaults on startup. Mirage can also be made to load default responses
|
4
|
+
from a directory of your choosing.
|
5
|
+
|
6
|
+
Defaults can also be added/reloaded after Mirage has started
|
7
|
+
|
8
|
+
|
9
|
+
Scenario: Mirage is started with defaults in the standard location.
|
10
|
+
Given the file 'defaults/default_greetings.rb' contains:
|
11
|
+
"""
|
12
|
+
Mirage.default do |mirage|
|
13
|
+
mirage.set('greeting', :response => 'hello')
|
14
|
+
mirage.set('leaving', :response => 'goodbye')
|
15
|
+
end
|
16
|
+
"""
|
17
|
+
And I run 'mirage start'
|
18
|
+
When I hit 'http://localhost:7001/mirage/get/greeting'
|
19
|
+
Then 'hello' should be returned
|
20
|
+
When I hit 'http://localhost:7001/mirage/get/leaving'
|
21
|
+
Then 'goodbye' should be returned
|
22
|
+
|
23
|
+
|
24
|
+
Scenario: Mirage is started pointing with a relative path for default responses
|
25
|
+
Given the file './custom_default_location/default_greetings.rb' contains:
|
26
|
+
"""
|
27
|
+
Mirage.default do |mirage|
|
28
|
+
mirage.set('greeting', :response => 'hello')
|
29
|
+
end
|
30
|
+
"""
|
31
|
+
And I run 'mirage start -d ./custom_default_location'
|
32
|
+
When I hit 'http://localhost:7001/mirage/get/greeting'
|
33
|
+
Then 'hello' should be returned
|
34
|
+
|
35
|
+
|
36
|
+
Scenario: Mirage is started pointing with a full path for default responses
|
37
|
+
Given the file '/tmp/defaults/default_greetings.rb' contains:
|
38
|
+
"""
|
39
|
+
Mirage.default do |mirage|
|
40
|
+
mirage.set('greeting', :response => 'hello')
|
41
|
+
end
|
42
|
+
"""
|
43
|
+
And I run 'mirage start -d /tmp/defaults'
|
44
|
+
When I hit 'http://localhost:7001/mirage/load_defaults'
|
45
|
+
And I hit 'http://localhost:7001/mirage/get/greeting'
|
46
|
+
Then 'hello' should be returned
|
47
|
+
|
48
|
+
|
49
|
+
Scenario: Reloading default responses after mirage has been started
|
50
|
+
Given the file 'defaults/default_greetings.rb' contains:
|
51
|
+
"""
|
52
|
+
Mirage.default do |mirage|
|
53
|
+
mirage.set('greeting', :response => 'hello')
|
54
|
+
end
|
55
|
+
"""
|
56
|
+
And I run 'mirage start'
|
57
|
+
And I hit 'http://localhost:7001/mirage/clear'
|
58
|
+
And I hit 'http://localhost:7001/mirage/set/a_new_response' with parameters:
|
59
|
+
| response | new response |
|
60
|
+
|
61
|
+
When I hit 'http://localhost:7001/mirage/load_defaults'
|
62
|
+
When I hit 'http://localhost:7001/mirage/get/greeting'
|
63
|
+
Then 'hello' should be returned
|
64
|
+
When I hit 'http://localhost:7001/mirage/get/a_new_response'
|
65
|
+
Then a 404 should be returned
|
66
|
+
|
67
|
+
|
68
|
+
Scenario: Mirage is started with a bad defaults file
|
69
|
+
Given the file 'defaults/default_greetings.rb' contains:
|
70
|
+
"""
|
71
|
+
A file with a mistake in it
|
72
|
+
"""
|
73
|
+
When I run 'mirage start'
|
74
|
+
Then I should see 'WARN: Unable to load default responses from: defaults/default_greetings.rb' on the command line
|
75
|
+
|
76
|
+
|
77
|
+
Scenario: Defaults with a mistake in them are reloaded after mirage has been started
|
78
|
+
Given I run 'mirage start'
|
79
|
+
When the file 'defaults/default_greetings.rb' contains:
|
80
|
+
"""
|
81
|
+
A file with a mistake in it
|
82
|
+
"""
|
83
|
+
And I hit 'http://localhost:7001/mirage/load_defaults'
|
84
|
+
Then a 500 should be returned
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Feature: Mirage can also be used to host files.
|
2
|
+
|
3
|
+
Scenario: A file is set as a response
|
4
|
+
Given I hit 'http://localhost:7001/mirage/set/some/location/download' with parameters:
|
5
|
+
| file | features/resources/test.zip |
|
6
|
+
|
7
|
+
When I hit 'http://localhost:7001/mirage/get/some/location/download'
|
8
|
+
Then the response should be a file the same as 'features/resources/test.zip'
|
@@ -0,0 +1,7 @@
|
|
1
|
+
Feature: Output from Mirage is stored in mirage.log.
|
2
|
+
This file is located at the root from which mirage is started.
|
3
|
+
|
4
|
+
Scenario: response is set.
|
5
|
+
Given I post to 'http://localhost:7001/mirage/set/greeting' with parameters:
|
6
|
+
| response | Hello |
|
7
|
+
Then 'mirage.log' should contain '/mirage/set/greeting?response=Hello'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Feature: If you want to see the content of a particular response without triggering then it can be peeked instead.
|
2
|
+
To do this, the responses unique id is required to identify it
|
3
|
+
|
4
|
+
|
5
|
+
Scenario: Peeking a text based response
|
6
|
+
Given I hit 'http://localhost:7001/mirage/set/greeting' with parameters:
|
7
|
+
| response | Hello |
|
8
|
+
|
9
|
+
When I hit 'http://localhost:7001/mirage/peek/1'
|
10
|
+
Then 'Hello' should be returned
|
11
|
+
|
12
|
+
|
13
|
+
Scenario: Peeking a file based response
|
14
|
+
Given I hit 'http://localhost:7001/mirage/set/download' with parameters:
|
15
|
+
| file | features/resources/test.zip |
|
16
|
+
When I hit 'http://localhost:7001/mirage/peek/1'
|
17
|
+
Then the response should be a file the same as 'features/resources/test.zip'
|
18
|
+
|
19
|
+
|
20
|
+
Scenario: Peeking a response that does not exist
|
21
|
+
When I hit 'http://localhost:7001/mirage/peek/1'
|
22
|
+
Then a 404 should be returned
|
23
|
+
|
24
|
+
|
Binary file
|
@@ -0,0 +1,45 @@
|
|
1
|
+
Feature: Parts of a response can be substitued for values found in the request body or query string.
|
2
|
+
This allows dynamic content to be sent back to a client.
|
3
|
+
|
4
|
+
To do this, substitution patterns are put in to the response. When the response is triggered, the patterns are used to search the request body
|
5
|
+
and then the query string for matches. Patterns can be either the name of a parameter found in the query string, or a regular expression with a single
|
6
|
+
matching group which is what is put in to the response.
|
7
|
+
|
8
|
+
|
9
|
+
Scenario: A response template populated from match found in the request body using a regex
|
10
|
+
Given I hit 'http://localhost:7001/mirage/set/greeting' with parameters:
|
11
|
+
| response | Hello ${<name>(.*?)</name>}, how are you? |
|
12
|
+
|
13
|
+
When I hit 'http://localhost:7001/mirage/get/greeting' with request body:
|
14
|
+
"""
|
15
|
+
<grettingRequest>
|
16
|
+
<name>Leon</name>
|
17
|
+
</greetingRequest>
|
18
|
+
"""
|
19
|
+
Then 'Hello Leon, how are you?' should be returned
|
20
|
+
|
21
|
+
|
22
|
+
Scenario: A response template populated from match found in the query string using a request parameter name
|
23
|
+
Given I hit 'http://localhost:7001/mirage/set/greeting' with parameters:
|
24
|
+
| response | Hello ${name}, how are you? |
|
25
|
+
|
26
|
+
When I hit 'http://localhost:7001/mirage/get/greeting' with parameters:
|
27
|
+
| name | Leon |
|
28
|
+
Then 'Hello Leon, how are you?' should be returned
|
29
|
+
|
30
|
+
Scenario: Response template populated from match found in the query string using a regex
|
31
|
+
Given I hit 'http://localhost:7001/mirage/set/greeting' with parameters:
|
32
|
+
| response | Hello ${name=([L\|l]eon)}, how are you? |
|
33
|
+
|
34
|
+
When I hit 'http://localhost:7001/mirage/get/greeting' with parameters:
|
35
|
+
| parameter | value |
|
36
|
+
| name | Leon |
|
37
|
+
Then 'Hello Leon, how are you?' should be returned
|
38
|
+
|
39
|
+
|
40
|
+
Scenario: No match is found in either the request body or query string
|
41
|
+
Given I hit 'http://localhost:7001/mirage/set/greeting' with parameters:
|
42
|
+
| response | Hello ${<name>(.*?)</name>}, how are you? |
|
43
|
+
|
44
|
+
When I hit 'http://localhost:7001/mirage/get/greeting'
|
45
|
+
Then 'Hello ${<name>(.*?)</name>}, how are you?' should be returned
|