mirage 3.0.0.alpha.11 → 3.0.0.alpha.12

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.
Files changed (56) hide show
  1. data/Gemfile +1 -1
  2. data/Gemfile.lock +1 -1
  3. data/VERSION +1 -1
  4. data/features/.nav +19 -0
  5. data/features/client/clear.feature +15 -23
  6. data/features/client/configure.feature +24 -28
  7. data/features/client/preview_responses.feature +4 -4
  8. data/features/client/put.feature +49 -62
  9. data/features/client/requests.feature +1 -1
  10. data/features/client/running.feature +2 -2
  11. data/features/client/save_and_revert.feature +5 -8
  12. data/features/client/start.feature +3 -3
  13. data/features/client/stop.feature +8 -8
  14. data/features/commandline_interface/help.feature +17 -0
  15. data/features/commandline_interface/readme.md +1 -0
  16. data/features/{server/commandline_interface → commandline_interface}/start.feature +4 -4
  17. data/features/{server/commandline_interface → commandline_interface}/stop.feature +22 -24
  18. data/features/{server/logging.feature → logging.feature} +2 -2
  19. data/features/{server/prime.feature → prime.feature} +4 -3
  20. data/features/readme.md +7 -0
  21. data/features/requests/delete.feature +48 -0
  22. data/features/{server/requests → requests}/get.feature +6 -5
  23. data/features/{server/save_and_revert.feature → save_and_revert.feature} +5 -5
  24. data/features/step_definitions/my_steps.rb +47 -12
  25. data/features/support/command_line.rb +1 -1
  26. data/features/templates/delete.feature +45 -0
  27. data/features/{server/templates → templates}/get.feature +9 -5
  28. data/features/templates/put.feature +77 -0
  29. data/features/{server/templates/put → templates}/put_with_substitutions.feature +4 -3
  30. data/features/templates/readme.md +7 -0
  31. data/features/{server/templates/put → templates}/required_content.feature +27 -35
  32. data/features/{server/web_user_interface.feature → web_user_interface.feature} +8 -7
  33. data/lib/mirage/client/cli_bridge.rb +1 -1
  34. data/lib/mirage/client/client.rb +16 -3
  35. data/lib/mirage/client/error.rb +1 -1
  36. data/lib/mirage/client/runner.rb +1 -1
  37. data/lib/mirage/client/template.rb +4 -2
  38. data/lib/mirage/client/template/configuration.rb +10 -0
  39. data/lib/mirage/client/template/model/instance_methods.rb +3 -4
  40. data/lib/mirage/client/templates.rb +1 -1
  41. data/mirage.gemspec +21 -17
  42. data/mirage_server.rb +1 -1
  43. data/server/mock_response.rb +18 -17
  44. data/server/server.rb +15 -15
  45. data/spec/client/client_spec.rb +44 -10
  46. data/spec/client/template/model/common_methods_spec.rb +1 -1
  47. data/spec/client/template/model/instance_methods_spec.rb +2 -2
  48. data/spec/client/template_spec.rb +11 -4
  49. data/spec/client/templates_spec.rb +10 -4
  50. data/spec/server/server_spec.rb +23 -23
  51. data/test.rb +2 -19
  52. metadata +22 -18
  53. data/features/server/commandline_interface/help.feature +0 -16
  54. data/features/server/requests/delete.feature +0 -47
  55. data/features/server/templates/delete.feature +0 -44
  56. data/features/server/templates/put/put.feature +0 -62
@@ -93,6 +93,8 @@ describe 'templates' do
93
93
  Class.new do
94
94
  extend Template::Model
95
95
  endpoint endpoint
96
+ def create
97
+ end
96
98
  end
97
99
  end
98
100
  before :each do
@@ -101,7 +103,14 @@ describe 'templates' do
101
103
  end
102
104
  it 'should take a model as a parameter' do
103
105
  template = model_class.new
104
- template.should_receive(:create)
106
+ @templates.put template
107
+ template.endpoint.should == "#{@base_url}/templates/#{endpoint}"
108
+ end
109
+
110
+ it 'should prepend base url to the endpoint unless it is set already' do
111
+ template = model_class.new
112
+ @templates.put template
113
+ template.endpoint.should == "#{@base_url}/templates/#{endpoint}"
105
114
  @templates.put template
106
115
  template.endpoint.should == "#{@base_url}/templates/#{endpoint}"
107
116
  end
@@ -126,7 +135,6 @@ describe 'templates' do
126
135
  Template.should_receive(:new).and_return template
127
136
  template.stub(:create).and_return(template)
128
137
  @templates.put('endpoint', 'value') do |response|
129
- puts response
130
138
  outer_method_call
131
139
  end
132
140
  end
@@ -156,8 +164,6 @@ describe 'templates' do
156
164
  it 'should create a template' do
157
165
  @templates.put(endpoint, value)
158
166
  end
159
-
160
-
161
167
  end
162
168
 
163
169
  describe 'block parameter that can be used for template customisation' do
@@ -19,15 +19,15 @@ describe "Mirage Server" do
19
19
  spec = {"somekeys" => 'some_values'}
20
20
 
21
21
  Mirage::MockResponse.should_receive(:new).with(endpoint, spec).and_return(@mock_response)
22
- put('/mirage/templates/greeting', spec.to_json)
22
+ put('/templates/greeting', spec.to_json)
23
23
  end
24
24
 
25
25
  it 'should set the requests url against the template that is created' do
26
26
  method = 'post'
27
27
  response_id = 1
28
28
  Mirage::MockResponse.should_receive(:new).and_return(@mock_response)
29
- put('/mirage/templates/greeting', {:request => {:http_method => method}}.to_json)
30
- @mock_response.requests_url.should == "http://example.org/mirage/requests/#{response_id}"
29
+ put('/templates/greeting', {:request => {:http_method => method}}.to_json)
30
+ @mock_response.requests_url.should == "http://example.org/requests/#{response_id}"
31
31
  end
32
32
 
33
33
  end
@@ -43,14 +43,14 @@ describe "Mirage Server" do
43
43
  parameters = {"key" => 'value'}
44
44
 
45
45
  Mirage::MockResponse.should_receive(:find).with(@options.merge(:params => parameters)).and_return(Mirage::MockResponse.new(@endpoint, {:response => {:body => "hello"}}))
46
- get("/mirage/responses/#{@endpoint}", parameters)
46
+ get("/responses/#{@endpoint}", parameters)
47
47
  end
48
48
 
49
49
  it 'should use the request body' do
50
50
  body = 'body'
51
51
 
52
52
  Mirage::MockResponse.should_receive(:find).with(@options.merge(:body => body)).and_return(Mirage::MockResponse.new(@endpoint, {:response => {:body => "hello"}}))
53
- post("/mirage/responses/#{@endpoint}", body)
53
+ post("/responses/#{@endpoint}", body)
54
54
  end
55
55
 
56
56
  it 'should use headers' do
@@ -61,7 +61,7 @@ describe "Mirage Server" do
61
61
  end
62
62
 
63
63
  Mirage::MockResponse.should_receive(:find).with(@options.merge(:headers => headers)).and_return(Mirage::MockResponse.new(@endpoint, {:response => {:body => "hello"}}))
64
- get("/mirage/responses/#{@endpoint}")
64
+ get("/responses/#{@endpoint}")
65
65
  end
66
66
 
67
67
  it 'should return the default response if a specific match is not found' do
@@ -76,8 +76,8 @@ describe "Mirage Server" do
76
76
  :body => "hello leon"
77
77
  }
78
78
  }
79
- put("/mirage/templates/#{@endpoint}", response_template.to_json)
80
- post("/mirage/responses/#{@endpoint}")
79
+ put("/templates/#{@endpoint}", response_template.to_json)
80
+ post("/responses/#{@endpoint}")
81
81
  end
82
82
  end
83
83
 
@@ -86,26 +86,26 @@ describe "Mirage Server" do
86
86
  describe "operations" do
87
87
  describe 'resolving responses' do
88
88
  it 'should return the default response' do
89
- put('/mirage/templates/level1', {:response => {:body => Base64.encode64("level1")}}.to_json)
90
- put('/mirage/templates/level1/level2', {:response => {:body => Base64.encode64("level2"), :default => true}}.to_json)
91
- get('/mirage/responses/level1/level2/level3').body.should == "level2"
89
+ put('/templates/level1', {:response => {:body => Base64.encode64("level1")}}.to_json)
90
+ put('/templates/level1/level2', {:response => {:body => Base64.encode64("level2"), :default => true}}.to_json)
91
+ get('/responses/level1/level2/level3').body.should == "level2"
92
92
  end
93
93
 
94
94
  it 'should set any headers specified' do
95
95
  headers = {header: 'value'}
96
- put('/mirage/templates/greeting', {:response => {headers: headers, :body => ''}}.to_json)
97
- get('/mirage/responses/greeting').headers['header'].should == 'value'
96
+ put('/templates/greeting', {:response => {headers: headers, :body => ''}}.to_json)
97
+ get('/responses/greeting').headers['header'].should == 'value'
98
98
  end
99
99
  end
100
100
 
101
101
  describe 'checking templates' do
102
102
  it 'should return the descriptor for a template' do
103
103
  response_body = "hello"
104
- response_id = JSON.parse(put('/mirage/templates/greeting', {:response => {:body => Base64.encode64(response_body)}}.to_json).body)['id']
105
- template = JSON.parse(get("/mirage/templates/#{response_id}").body)
104
+ response_id = JSON.parse(put('/templates/greeting', {:response => {:body => Base64.encode64(response_body)}}.to_json).body)['id']
105
+ template = JSON.parse(get("/templates/#{response_id}").body)
106
106
  template.should == JSON.parse({:endpoint => "greeting",
107
107
  :id => response_id,
108
- :requests_url => "http://example.org/mirage/requests/#{response_id}",
108
+ :requests_url => "http://example.org/requests/#{response_id}",
109
109
  :request => {:parameters => {}, :http_method => "get", :body_content => [], :headers => {}},
110
110
  :response => {:default => false,
111
111
  :body => Base64.encode64(response_body),
@@ -117,25 +117,25 @@ describe "Mirage Server" do
117
117
  end
118
118
 
119
119
  it 'should return tracked request data' do
120
- response_id = JSON.parse(put('/mirage/templates/greeting', {:request => {:http_method => :post}, :response => {:body => Base64.encode64("hello")}}.to_json).body)['id']
120
+ response_id = JSON.parse(put('/templates/greeting', {:request => {:http_method => :post}, :response => {:body => Base64.encode64("hello")}}.to_json).body)['id']
121
121
 
122
122
 
123
123
  header "MYHEADER", "my_header_value"
124
- post("/mirage/responses/greeting?param=value", 'body')
125
- request_data = JSON.parse(get("/mirage/requests/#{response_id}").body)
124
+ post("/responses/greeting?param=value", 'body')
125
+ request_data = JSON.parse(get("/requests/#{response_id}").body)
126
126
 
127
127
  request_data['parameters'].should == {'param' => 'value'}
128
128
  request_data['headers']["MYHEADER"].should == "my_header_value"
129
129
  request_data['body'].should == "body"
130
- request_data['request_url'].should == "http://example.org/mirage/requests/#{response_id}"
130
+ request_data['request_url'].should == "http://example.org/requests/#{response_id}"
131
131
 
132
132
  end
133
133
 
134
134
 
135
135
  it 'should delete a template' do
136
- response_id = JSON.parse(put('/mirage/templates/greeting', {:response => {:body => Base64.encode64("hello")}}.to_json).body)['id']
137
- delete("/mirage/templates/#{response_id}")
138
- expect { get("/mirage/templates/#{response_id}") }.to raise_error(Mirage::ServerResponseNotFound)
136
+ response_id = JSON.parse(put('/templates/greeting', {:response => {:body => Base64.encode64("hello")}}.to_json).body)['id']
137
+ delete("/templates/#{response_id}")
138
+ expect { get("/templates/#{response_id}") }.to raise_error(Mirage::ServerResponseNotFound)
139
139
  end
140
140
  end
141
141
  end
data/test.rb CHANGED
@@ -1,20 +1,3 @@
1
- require './lib/mirage/client'
1
+ require '/home/team/Projects/mirage/lib/mirage/client'
2
2
 
3
-
4
- Mirage.stop
5
- mirage = Mirage.start
6
-
7
-
8
- mirage.put('FindCis.do', 'value1') do
9
- http_method :post
10
- content_type "text/xml"
11
- required_body_content ['value']
12
- status 200
13
- end
14
-
15
- mirage.put('FindCis.do', 'value2') do
16
- http_method :post
17
- content_type "text/xml"
18
- required_body_content ['value']
19
- status 200
20
- end
3
+ puts "{\"id\":1,\"endpoint\":\"greeting\",\"requests_url\":\"http://localhost:7001/requests/1\",\"response\":{\"default\":false,\"body\":\"Hello\",\"delay\":0,\"content_type\":\"text/plain\",\"status\":200},\"request\":{\"parameters\":{},\"body_content\":[],\"http_method\":\"get\",\"headers\":{}}}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mirage
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.alpha.11
4
+ version: 3.0.0.alpha.12
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-07 00:00:00.000000000 Z
12
+ date: 2013-08-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
@@ -253,6 +253,7 @@ files:
253
253
  - README.md
254
254
  - VERSION
255
255
  - bin/mirage
256
+ - features/.nav
256
257
  - features/client/clear.feature
257
258
  - features/client/configure.feature
258
259
  - features/client/preview_responses.feature
@@ -262,26 +263,29 @@ files:
262
263
  - features/client/save_and_revert.feature
263
264
  - features/client/start.feature
264
265
  - features/client/stop.feature
265
- - features/server/commandline_interface/help.feature
266
- - features/server/commandline_interface/start.feature
267
- - features/server/commandline_interface/stop.feature
268
- - features/server/logging.feature
269
- - features/server/prime.feature
270
- - features/server/requests/delete.feature
271
- - features/server/requests/get.feature
272
- - features/server/save_and_revert.feature
273
- - features/server/templates/delete.feature
274
- - features/server/templates/get.feature
275
- - features/server/templates/put/put.feature
276
- - features/server/templates/put/put_with_substitutions.feature
277
- - features/server/templates/put/required_content.feature
278
- - features/server/web_user_interface.feature
266
+ - features/commandline_interface/help.feature
267
+ - features/commandline_interface/readme.md
268
+ - features/commandline_interface/start.feature
269
+ - features/commandline_interface/stop.feature
270
+ - features/logging.feature
271
+ - features/prime.feature
272
+ - features/readme.md
273
+ - features/requests/delete.feature
274
+ - features/requests/get.feature
275
+ - features/save_and_revert.feature
279
276
  - features/step_definitions/my_steps.rb
280
277
  - features/support/command_line.rb
281
278
  - features/support/env.rb
282
279
  - features/support/hooks.rb
283
280
  - features/support/mirage.rb
284
281
  - features/support/web.rb
282
+ - features/templates/delete.feature
283
+ - features/templates/get.feature
284
+ - features/templates/put.feature
285
+ - features/templates/put_with_substitutions.feature
286
+ - features/templates/readme.md
287
+ - features/templates/required_content.feature
288
+ - features/web_user_interface.feature
285
289
  - full_build.sh
286
290
  - lib/mirage/client.rb
287
291
  - lib/mirage/client/cli_bridge.rb
@@ -349,7 +353,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
349
353
  version: '0'
350
354
  segments:
351
355
  - 0
352
- hash: -378399899441393951
356
+ hash: 158416820586937306
353
357
  required_rubygems_version: !ruby/object:Gem::Requirement
354
358
  none: false
355
359
  requirements:
@@ -358,7 +362,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
358
362
  version: 1.3.1
359
363
  requirements: []
360
364
  rubyforge_project:
361
- rubygems_version: 1.8.25
365
+ rubygems_version: 1.8.24
362
366
  signing_key:
363
367
  specification_version: 3
364
368
  summary: Mirage is a easy mock server for testing your applications
@@ -1,16 +0,0 @@
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
- | Tasks: |
9
- | mirage help [TASK] # Describe available tasks or one specific task |
10
- # | mirage start # Starts mirage |
11
- # | mirage stop -p, --port=[port_1 port_2\|all] # stops mirage |
12
-
13
-
14
- Scenario: Starting with help option
15
- Given I run 'mirage help'
16
- Then the usage information should be displayed
@@ -1,47 +0,0 @@
1
- Feature: Tracked request data can be deleted
2
-
3
- Background: The MockServer has already got a response for greeting and leaving on it.
4
- Given the following template template:
5
- """
6
- {
7
- "response":{
8
- "body":"Hello"
9
- }
10
- }
11
- """
12
- And 'response.body' is base64 encoded
13
- And the template is sent using PUT to 'http://localhost:7001/mirage/templates/greeting'
14
-
15
- Given the following template template:
16
- """
17
- {
18
- "response":{
19
- "body":"Goodbye"
20
- }
21
- }
22
- """
23
- And 'response.body' is base64 encoded
24
- And the template is sent using PUT to 'http://localhost:7001/mirage/templates/leaving'
25
-
26
-
27
- And GET is sent to 'http://localhost:7001/mirage/responses/greeting'
28
- And GET is sent to 'http://localhost:7001/mirage/responses/leaving'
29
-
30
-
31
- Scenario: Deleting all requests
32
- And DELETE is sent to 'http://localhost:7001/mirage/requests'
33
-
34
- When GET is sent to 'http://localhost:7001/mirage/requests/1'
35
- Then a 404 should be returned
36
- When GET is sent to 'http://localhost:7001/mirage/requests/2'
37
- Then a 404 should be returned
38
-
39
-
40
-
41
- Scenario: Deleting a stored request for a particular response
42
- And DELETE is sent to 'http://localhost:7001/mirage/requests/1'
43
-
44
- When GET is sent to 'http://localhost:7001/mirage/requests/1'
45
- Then a 404 should be returned
46
- When GET is sent to 'http://localhost:7001/mirage/requests/2'
47
- Then a 200 should be returned
@@ -1,44 +0,0 @@
1
- Feature: When a template is deleted, any tracked request data is also removed.
2
-
3
- Background: The MockServer has already got a response for greeting and leaving on it.
4
- Given the following template template:
5
- """
6
- {
7
- "response":{
8
- "body":"Hello"
9
- }
10
- }
11
- """
12
- And 'response.body' is base64 encoded
13
- And the template is sent using PUT to 'http://localhost:7001/mirage/templates/greeting'
14
-
15
- Given the following template template:
16
- """
17
- {
18
- "response":{
19
- "body":"Goodbye"
20
- }
21
- }
22
- """
23
- And 'response.body' is base64 encoded
24
- And the template is sent using PUT to 'http://localhost:7001/mirage/templates/leaving'
25
-
26
-
27
- Scenario: Deleting all templates
28
- Given DELETE is sent to 'http://localhost:7001/mirage/templates'
29
- When GET is sent to 'http://localhost:7001/mirage/responses/greeting'
30
- Then a 404 should be returned
31
- When GET is sent to 'http://localhost:7001/mirage/responses/leaving'
32
- Then a 404 should be returned
33
-
34
-
35
- Scenario: Deleting a particular template
36
- Given DELETE is sent to 'http://localhost:7001/mirage/templates/1'
37
-
38
- When GET is sent to 'http://localhost:7001/mirage/responses/greeting'
39
- Then a 404 should be returned
40
-
41
- When GET is sent to 'http://localhost:7001/mirage/responses/leaving'
42
- Then a 200 should be returned
43
-
44
-
@@ -1,62 +0,0 @@
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 returned. 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 resource 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
- The following can be configured as required in order to invoke a response:
8
- * request parameters
9
- * body content - defaults to text/plain
10
- * HTTP Headers
11
- * HTTP Method - defaults to HTTP GET
12
-
13
- The following attributes of a response can be configured
14
- * HTTP status code - defaults to 200
15
- * Whether this template is to be treated as the default response if a match is not found for a sub URI
16
- * A delay before the response is returned to the client. This is in seconds, floats are accepted
17
- * Content-Type
18
-
19
- Request defaults
20
- |required request parameters | none |
21
- |required body content | none |
22
- |require HTTP headers | none |
23
- |required HTTP method | GET |
24
-
25
- Response defaults
26
- | HTTP status code | 200 |
27
- | treat as default | false |
28
- | delay | 0 |
29
- | Content-Type | text/plain |
30
-
31
-
32
- Scenario: Setting a template on mirage
33
- Given the following template template:
34
- """
35
- {
36
- "request":{
37
- "parameters":{},
38
- "http_method":"get",
39
- "headers": {},
40
- "body_content":[]
41
- },
42
- "response":{
43
- "default":false,
44
- "body":"Hello",
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 'http://localhost:7001/mirage/templates/greeting'
53
- And '{"id":1}' should be returned
54
-
55
- When GET is sent to 'http://localhost:7001/mirage/responses/greeting'
56
- Then 'Hello' should be returned
57
- And a 200 should be returned
58
-
59
- Scenario: Making a request that is unmatched
60
- When GET is sent to 'http://localhost:7001/mirage/responses/unmatched'
61
- Then a 404 should be returned
62
-