mirage 2.0.0.alpha3 → 2.0.0.alpha4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. data/Gemfile +1 -2
  2. data/VERSION +1 -1
  3. data/bin/mirage +1 -1
  4. data/features/client/clear.feature +1 -1
  5. data/features/client/mirage_client.feature +1 -1
  6. data/features/client/{set.feature → put.feature} +20 -11
  7. data/features/client/{track.feature → request.feature} +2 -2
  8. data/features/client/{peek.feature → response.feature} +12 -12
  9. data/features/client/save_and_revert.feature +1 -1
  10. data/features/server/prime.feature +5 -5
  11. data/features/server/requests/delete.feature +46 -0
  12. data/features/server/requests/get.feature +32 -0
  13. data/features/server/templates/delete.feature +47 -0
  14. data/features/server/{peek.feature → templates/get.feature} +0 -0
  15. data/features/server/{set.feature → templates/put/put.feature} +29 -19
  16. data/features/server/{set_default_response.feature → templates/put/put_as_default.feature} +1 -1
  17. data/features/server/{set_with_a_delay.feature → templates/put/put_with_delay.feature} +0 -0
  18. data/features/server/{set_with_a_pattern.feature → templates/put/put_with_pattern.feature} +14 -1
  19. data/features/server/{response_templates.feature → templates/put/put_with_substitutions.feature} +0 -0
  20. data/features/step_definitions/my_steps.rb +15 -15
  21. data/features/support/env.rb +1 -1
  22. data/lib/mirage/client.rb +21 -17
  23. data/lib/mirage/core.rb +12 -3
  24. data/lib/mirage/server.rb +17 -0
  25. data/lib/mirage/web.rb +4 -4
  26. data/lib/start_mirage.rb +12 -17
  27. data/mirage.gemspec +32 -25
  28. metadata +41 -51
  29. data/features/server/clear.feature +0 -93
  30. data/features/server/track_requests.feature +0 -71
  31. data/lib/mirage.rb +0 -18
data/Gemfile CHANGED
@@ -1,11 +1,10 @@
1
1
  source :rubygems
2
2
 
3
- gem 'rack', '~> 1.1.0'
4
3
  gem 'sinatra'
5
4
  gem 'childprocess', '~> 0.1'
6
5
 
7
6
  group :development do
8
- gem 'rake', '0.9.0'
7
+ gem 'rake'
9
8
  gem 'cucumber'
10
9
  gem 'gherkin', '2.3.9'
11
10
  gem 'rspec'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0.alpha3
1
+ 2.0.0.alpha4
data/bin/mirage CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'rubygems'
3
3
  $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib")
4
- require 'mirage'
4
+ require 'mirage/client'
5
5
  require 'childprocess'
6
6
  include Mirage::Util
7
7
  RUBY_CMD = RUBY_PLATFORM == 'java' ? 'jruby' : 'ruby'
@@ -5,7 +5,7 @@ Feature: The client can be used for clearing responses from Mirage
5
5
  """
6
6
  require 'rubygems'
7
7
  require 'rspec'
8
- require 'mirage'
8
+ require 'mirage/client'
9
9
  """
10
10
 
11
11
  And I send PUT to 'http://localhost:7001/mirage/templates/greeting' with request entity
@@ -10,7 +10,7 @@ Feature: Interacting with Mirage is done via HTTP using REST style URLs and the
10
10
  """
11
11
  require 'rubygems'
12
12
  require 'rspec'
13
- require 'mirage'
13
+ require 'mirage/client'
14
14
  """
15
15
 
16
16
 
@@ -8,14 +8,14 @@ Feature: the Mirage client provides methods for setting responses and loading de
8
8
  """
9
9
  require 'rubygems'
10
10
  require 'rspec'
11
- require 'mirage'
11
+ require 'mirage/client'
12
12
  """
13
13
 
14
14
 
15
15
  Scenario: Setting a basic response
16
16
  Given I run
17
17
  """
18
- Mirage::Client.new.set('greeting','hello')
18
+ Mirage::Client.new.put('greeting','hello')
19
19
  """
20
20
  When I send GET to 'http://localhost:7001/mirage/responses/greeting'
21
21
  Then 'hello' should be returned
@@ -23,7 +23,7 @@ Feature: the Mirage client provides methods for setting responses and loading de
23
23
  Scenario: Setting the method that a response should be returned on
24
24
  Given I run
25
25
  """
26
- Mirage::Client.new.set('greeting', 'Hello Leon') do |response|
26
+ Mirage::Client.new.put('greeting', 'Hello Leon') do |response|
27
27
  response.method = 'POST'
28
28
  end
29
29
  """
@@ -36,7 +36,7 @@ Feature: the Mirage client provides methods for setting responses and loading de
36
36
  Scenario Outline: Setting a response with a pattern
37
37
  Given I run
38
38
  """
39
- Mirage::Client.new.set('greeting', 'Hello Leon') do |response|
39
+ Mirage::Client.new.put('greeting', 'Hello Leon') do |response|
40
40
  response.method = 'POST'
41
41
  response.pattern = <pattern>
42
42
  end
@@ -55,11 +55,22 @@ Feature: the Mirage client provides methods for setting responses and loading de
55
55
  | /.*?>leon<\\/name>/ |
56
56
  | 'leon' |
57
57
 
58
+ Scenario: setting a response as default
59
+ Given I run
60
+ """
61
+ Mirage::Client.new.put('greeting', 'default greeting') do |response|
62
+ response.default = true
63
+ end
64
+ """
65
+ When I send GET to 'http://localhost:7001/mirage/responses/greeting/for/joel'
66
+ Then 'default greeting' should be returned
67
+
68
+
58
69
 
59
70
  Scenario: Setting the content type
60
71
  Given I run
61
72
  """
62
- Mirage::Client.new.set('greeting', '<xml></xml>') do |response|
73
+ Mirage::Client.new.put('greeting', '<xml></xml>') do |response|
63
74
  response.content_type = 'text/xml'
64
75
  end
65
76
  """
@@ -73,8 +84,8 @@ Feature: the Mirage client provides methods for setting responses and loading de
73
84
  When the file 'responses/default_greetings.rb' contains:
74
85
  """
75
86
  Mirage.prime do |mirage|
76
- mirage.set('greeting', 'hello')
77
- mirage.set('leaving', 'goodbye')
87
+ mirage.put('greeting', 'hello')
88
+ mirage.put('leaving', 'goodbye')
78
89
  end
79
90
  """
80
91
  And I run
@@ -95,7 +106,7 @@ Feature: the Mirage client provides methods for setting responses and loading de
95
106
  And I run
96
107
  """
97
108
  puts Dir.pwd
98
- Mirage::Client.new.set('greeting', File.open('scratch/response_file')) do |response|
109
+ Mirage::Client.new.put('greeting', File.open('scratch/response_file')) do |response|
99
110
  response.method = 'POST'
100
111
  end
101
112
  """
@@ -122,13 +133,11 @@ Feature: the Mirage client provides methods for setting responses and loading de
122
133
  e.is_a?(Mirage::InternalServerException).should == true
123
134
  end
124
135
  """
125
- #
126
- #
127
136
 
128
137
  Scenario: Setting a file as a response
129
138
  Given I run
130
139
  """
131
- Mirage::Client.new.set('download', File.open('README.md'))
140
+ Mirage::Client.new.put('download', File.open('README.md'))
132
141
  """
133
142
  When I send GET to 'http://localhost:7001/mirage/responses/download'
134
143
  Then the response should be the same as the content of 'README.md'
@@ -5,7 +5,7 @@ Feature: Requests made to the Mirage Server can be tracked using the Mirage clie
5
5
  """
6
6
  require 'rubygems'
7
7
  require 'rspec'
8
- require 'mirage'
8
+ require 'mirage/client'
9
9
  """
10
10
 
11
11
  Scenario: The MockServer returns a response
@@ -18,5 +18,5 @@ Feature: Requests made to the Mirage Server can be tracked using the Mirage clie
18
18
  | name | leon |
19
19
  Then I run
20
20
  """
21
- Mirage::Client.new.track(1).should == 'name=leon'
21
+ Mirage::Client.new.request(1).should == 'name=leon'
22
22
  """
@@ -5,25 +5,25 @@ Feature: the client can be used for peeking at responses hosted on Mirage.
5
5
  """
6
6
  require 'rubygems'
7
7
  require 'rspec'
8
- require 'mirage'
8
+ require 'mirage/client'
9
9
  """
10
10
 
11
- # Scenario: peeking a response
12
- # Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello'
13
- #
14
- # When I run
15
- # """
16
- # Mirage::Client.new.peek(1).should == 'Hello'
17
- # """
18
- #
19
- # When I send GET to 'http://localhost:7001/mirage/requests/1'
20
- # Then a 404 should be returned
11
+ Scenario: peeking a response
12
+ Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello'
13
+
14
+ When I run
15
+ """
16
+ Mirage::Client.new.response(1).should == 'Hello'
17
+ """
18
+
19
+ When I send GET to 'http://localhost:7001/mirage/requests/1'
20
+ Then a 404 should be returned
21
21
 
22
22
  Scenario: getting a response that does not exist
23
23
  Given I run
24
24
  """
25
25
  begin
26
- Mirage::Client.new.peek(2).should == 'this should not have happened'
26
+ Mirage::Client.new.response(2).should == 'this should not have happened'
27
27
  fail("Error should have been thrown")
28
28
  rescue Exception => e
29
29
  puts e
@@ -6,7 +6,7 @@ Feature: The Mirage client can be used to snaphsot and rollback the Mirage serve
6
6
  """
7
7
  require 'rubygems'
8
8
  require 'rspec'
9
- require 'mirage'
9
+ require 'mirage/client'
10
10
  """
11
11
  And I send PUT to 'http://localhost:7001/mirage/templates/greeting' with request entity
12
12
  """
@@ -12,8 +12,8 @@ Feature: Mirage can be primed with a set of responses.
12
12
  Given the file 'responses/default_greetings.rb' contains:
13
13
  """
14
14
  Mirage.prime do |mirage|
15
- mirage.set('greeting', 'hello')
16
- mirage.set('leaving', 'goodbye')
15
+ mirage.put('greeting', 'hello')
16
+ mirage.put('leaving', 'goodbye')
17
17
  end
18
18
  """
19
19
  And I run 'mirage start'
@@ -27,7 +27,7 @@ Feature: Mirage can be primed with a set of responses.
27
27
  Given the file './custom_responses_location/default_greetings.rb' contains:
28
28
  """
29
29
  Mirage.prime do |mirage|
30
- mirage.set('greeting', 'hello')
30
+ mirage.put('greeting', 'hello')
31
31
  end
32
32
  """
33
33
  And I run 'mirage start -d ./custom_responses_location'
@@ -39,7 +39,7 @@ Feature: Mirage can be primed with a set of responses.
39
39
  Given the file '/tmp/responses/default_greetings.rb' contains:
40
40
  """
41
41
  Mirage.prime do |mirage|
42
- mirage.set('greeting', 'hello')
42
+ mirage.put('greeting', 'hello')
43
43
  end
44
44
  """
45
45
  And I run 'mirage start -d /tmp/responses'
@@ -52,7 +52,7 @@ Feature: Mirage can be primed with a set of responses.
52
52
  Given the file 'responses/default_greetings.rb' contains:
53
53
  """
54
54
  Mirage.prime do |mirage|
55
- mirage.set('greeting', 'hello')
55
+ mirage.put('greeting', 'hello')
56
56
  end
57
57
  """
58
58
  And I run 'mirage start'
@@ -0,0 +1,46 @@
1
+ Feature: Request data can be deleted.
2
+
3
+ Background: The MockServer has already got a response for greeting and leaving on it.
4
+ Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello'
5
+ And I send GET to 'http://localhost:7001/mirage/responses/greeting'
6
+
7
+ And I send PUT to 'http://localhost:7001/mirage/templates/leaving' with body 'Goodbye'
8
+ And I send GET to 'http://localhost:7001/mirage/responses/leaving'
9
+
10
+
11
+ Scenario: Deleting all requests
12
+ And I send DELETE to 'http://localhost:7001/mirage/requests'
13
+
14
+ When I send GET to 'http://localhost:7001/mirage/requests/1'
15
+ Then a 404 should be returned
16
+ When I send GET to 'http://localhost:7001/mirage/responses/greeting'
17
+ Then a 200 should be returned
18
+ When I send GET to 'http://localhost:7001/mirage/templates/1'
19
+ Then a 200 should be returned
20
+
21
+
22
+ When I send GET to 'http://localhost:7001/mirage/requests/2'
23
+ Then a 404 should be returned
24
+ When I send GET to 'http://localhost:7001/mirage/responses/leaving'
25
+ Then a 200 should be returned
26
+ When I send GET to 'http://localhost:7001/mirage/templates/2'
27
+ Then a 200 should be returned
28
+
29
+
30
+ Scenario: Deleting a stored request for a prticular response
31
+ And I send DELETE to 'http://localhost:7001/mirage/requests/1'
32
+
33
+ When I send GET to 'http://localhost:7001/mirage/requests/1'
34
+ Then a 404 should be returned
35
+ When I send GET to 'http://localhost:7001/mirage/responses/greeting'
36
+ Then a 200 should be returned
37
+ When I send GET to 'http://localhost:7001/mirage/templates/1'
38
+ Then a 200 should be returned
39
+
40
+
41
+ When I send GET to 'http://localhost:7001/mirage/requests/2'
42
+ Then a 200 should be returned
43
+ When I send GET to 'http://localhost:7001/mirage/responses/leaving'
44
+ Then a 200 should be returned
45
+ When I send GET to 'http://localhost:7001/mirage/templates/2'
46
+ Then a 200 should be returned
@@ -0,0 +1,32 @@
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 putting a respons template on to Mirage, a unique id is returned which can be used to look up the last request made to get that response.
5
+
6
+ If the request body contains content this is stored. Otherwise it is the query string that is stored.
7
+
8
+ Background: A template has already be put on Mirage
9
+ Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello' and headers:
10
+ | X-mirage-method | POST |
11
+
12
+
13
+ Scenario: Getting request data when the data was in the body.
14
+ Given I send POST to 'http://localhost:7001/mirage/responses/greeting' with request entity
15
+ """
16
+ Hello Mirage
17
+ """
18
+ When I send GET to 'http://localhost:7001/mirage/requests/1'
19
+ Then 'Hello Mirage' should be returned
20
+
21
+
22
+ Scenario: Getting request data when the data was in the query string.
23
+ Given I send POST to 'http://localhost:7001/mirage/responses/greeting' with parameters:
24
+ | surname | Davis |
25
+ | firstname | Leon |
26
+ When I send GET to 'http://localhost:7001/mirage/requests/1'
27
+ Then 'surname=Davis&firstname=Leon' should be returned
28
+
29
+
30
+ Scenario: Getting request data for a template that has not been served yet.
31
+ Given I send GET to 'http://localhost:7001/mirage/requests/1'
32
+ Then a 404 should be returned
@@ -0,0 +1,47 @@
1
+ Feature: Templates can be deleted, doing so means that the coresponding response is no longer hosted and it
2
+ also deletes any associated request data.
3
+
4
+
5
+ Background: The MockServer has already got a response for greeting and leaving on it.
6
+ Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello'
7
+ And I send GET to 'http://localhost:7001/mirage/responses/greeting'
8
+
9
+ And I send PUT to 'http://localhost:7001/mirage/templates/leaving' with body 'Goodbye'
10
+ And I send GET to 'http://localhost:7001/mirage/responses/leaving'
11
+
12
+
13
+ Scenario: Deleting all templates
14
+ Given I send DELETE to 'http://localhost:7001/mirage/templates'
15
+
16
+ When I send GET to 'http://localhost:7001/mirage/requests/1'
17
+ Then a 404 should be returned
18
+ When I send GET to 'http://localhost:7001/mirage/responses/greeting'
19
+ Then a 404 should be returned
20
+ When I send GET to 'http://localhost:7001/mirage/templates/1'
21
+ Then a 404 should be returned
22
+
23
+ When I send GET to 'http://localhost:7001/mirage/requests/2'
24
+ Then a 404 should be returned
25
+ When I send GET to 'http://localhost:7001/mirage/responses/leaving'
26
+ Then a 404 should be returned
27
+ When I send GET to 'http://localhost:7001/mirage/templates/2'
28
+ Then a 404 should be returned
29
+
30
+
31
+ Scenario: Deleting a particular template
32
+ Given I send DELETE to 'http://localhost:7001/mirage/templates/1'
33
+
34
+ When I send GET to 'http://localhost:7001/mirage/templates/1'
35
+ Then a 404 should be returned
36
+ When I send GET to 'http://localhost:7001/mirage/responses/greeting'
37
+ Then a 404 should be returned
38
+ When I send GET to 'http://localhost:7001/mirage/requests/1'
39
+ Then a 404 should be returned
40
+
41
+ When I send GET to 'http://localhost:7001/mirage/requests/2'
42
+ Then a 200 should be returned
43
+ When I send GET to 'http://localhost:7001/mirage/responses/leaving'
44
+ Then a 200 should be returned
45
+ When I send GET to 'http://localhost:7001/mirage/templates/2'
46
+ Then a 200 should be returned
47
+
@@ -1,32 +1,32 @@
1
- Feature: Mirage can be configured with responses to be returned with the correct end point is hit.
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
-
4
- Usage:
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)
1
+ Feature: Mirage can be configured with templates that are returned when addressed from ${mirage_url}/responses
2
+ On setting a template, a unique id is retuned. This is a key that can be used to manage the template.
3
+
4
+ Templates can be configured to respond to either, GET, POST, PUT, or DELETE. If you put more than one template to the same address
5
+ but configure them to respond to different HTTP methods, then they are held as seperate resources and are assigned different ids.
6
+
7
+ Templates can have following attributes configured by setting the following HTTP headers:
8
+ X-mirage-pattern (optional) = criteria for when a response should be returned. see put_with_pattern.feature
9
+ X-mirage-delay (optional) = the amount of time in seconds that mirage should wait for before responding (defaults to 0)
10
+ X-mirage-method (optional) = http method that this response applies to. Can be set to GET, POST, PUT or DELETE. Templates are configured to respond to GET requests by default
11
+ X-mirage-default (optional) = set whether the reponse can act as a default response, see put_as_default.feature (defaults to false)
14
12
  content-type (optional) = Set the content type to be returned
15
13
 
16
14
 
17
- Scenario: Setting a response without any selection criteria
15
+ Scenario: A template without any selection criteria
18
16
  Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello'
19
17
 
20
18
  When I send GET to 'http://localhost:7001/mirage/responses/greeting'
21
19
  Then 'Hello' should be returned
20
+
22
21
 
23
- Scenario: A response hosted on a longer url
22
+ Scenario: A template put under a deeper address
24
23
  Given I send PUT to 'http://localhost:7001/mirage/templates/say/hello/to/me' with body 'Hello to me'
25
24
 
26
25
  When I send GET to 'http://localhost:7001/mirage/responses/say/hello/to/me'
27
26
  Then 'Hello to me' should be returned
27
+
28
28
 
29
- Scenario: Content type is set
29
+ Scenario: Setting the content-type header
30
30
  Given I send PUT to 'http://localhost:7001/mirage/templates/say/hello/to/me' with body '<xml></xml>' and headers:
31
31
  |content-type|text/xml|
32
32
 
@@ -35,23 +35,33 @@ Feature: Mirage can be configured with responses to be returned with the correct
35
35
  And the response 'content-type' should be 'text/xml'
36
36
 
37
37
 
38
- Scenario: The same endpoint is set more than once
38
+ Scenario: Putting a template to the same resource
39
39
  Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hello'
40
40
  Then '1' should be returned
41
41
 
42
42
  Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'Hi'
43
43
  Then '1' should be returned
44
+
45
+
44
46
 
45
47
 
46
- Scenario Outline: Response set to respond to different http methods
48
+ Scenario Outline: Templates is configured to respond to different http methods
47
49
  Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'GET' and headers:
48
50
  | X-mirage-method | GET |
51
+ And '1' should be returned
52
+
49
53
  Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'POST' and headers:
50
54
  | X-mirage-method | POST |
55
+ And '2' should be returned
56
+
51
57
  Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'DELETE' and headers:
52
58
  | X-mirage-method | DELETE |
59
+ And '3' should be returned
60
+
53
61
  Given I send PUT to 'http://localhost:7001/mirage/templates/greeting' with body 'PUT' and headers:
54
62
  | X-mirage-method | PUT |
63
+ And '4' should be returned
64
+
55
65
  When I send <method> to 'http://localhost:7001/mirage/responses/greeting'
56
66
  Then '<method>' should be returned
57
67
  Examples:
@@ -62,6 +72,6 @@ Feature: Mirage can be configured with responses to be returned with the correct
62
72
  | DELETE |
63
73
 
64
74
 
65
- Scenario: Getting a response that does not exist
75
+ Scenario: Getting a response for a template resources that does not exist
66
76
  When I send GET to 'http://localhost:7001/mirage/responses/response_that_does_not_exist'
67
77
  Then a 404 should be returned