mirage 3.0.0.alpha.10 → 3.0.0.alpha.11

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/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.0.alpha.10
1
+ 3.0.0.alpha.11
data/mirage.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "mirage"
8
- s.version = "3.0.0.alpha.10"
8
+ s.version = "3.0.0.alpha.11"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Leon Davis"]
12
- s.date = "2013-05-02"
12
+ s.date = "2013-05-07"
13
13
  s.description = "Mirage aids testing of your applications by hosting mock responses so that your applications do not have to talk to real endpoints. Its accessible via HTTP and has a RESTful interface."
14
14
  s.executables = ["mirage"]
15
15
  s.extra_rdoc_files = [
@@ -108,7 +108,7 @@ Gem::Specification.new do |s|
108
108
  s.licenses = ["MIT"]
109
109
  s.post_install_message = "\n===============================================================================\nThanks you for installing mirage. \n\nRun Mirage with:\n\nmirage start \n\nFor more information go to: https://github.com/lashd/mirage/wiki\n===============================================================================\n"
110
110
  s.require_paths = ["lib"]
111
- s.rubygems_version = "1.8.24"
111
+ s.rubygems_version = "1.8.25"
112
112
  s.summary = "Mirage is a easy mock server for testing your applications"
113
113
 
114
114
  if s.respond_to? :specification_version then
@@ -169,7 +169,9 @@ module Mirage
169
169
  @request_spec = Hashie::Mash.new request_defaults.merge(spec['request']||{})
170
170
  @response_spec = Hashie::Mash.new response_defaults.merge(spec['response']||{})
171
171
 
172
- @request_spec['headers'] = Hash[@request_spec['headers'].collect{|key, value| [key.downcase, value]}]
172
+ @request_spec['headers'] = Hash[@request_spec['headers'].collect{|key, value| [key.downcase, value.to_s]}]
173
+ @request_spec['parameters'] = Hash[@request_spec['parameters'].collect{|key, value| [key, value.to_s]}]
174
+ @request_spec['body_content'] = @request_spec['body_content'].collect{|value|value.to_s}
173
175
  @binary = BinaryDataChecker.contains_binary_data? @response_spec['body']
174
176
 
175
177
  MockResponse.add self
@@ -110,7 +110,7 @@ describe Mirage::MockResponse do
110
110
  response_spec = convert_keys_to_strings({:request => {:http_method => "post"}})
111
111
  response = MockResponse.new("greeting", response_spec)
112
112
 
113
- options = {:body => "", :params => {}, :endpoint => "greeting", :http_method => "post",:headers => {}}
113
+ options = {:body => "", :params => {}, :endpoint => "greeting", :http_method => "post", :headers => {}}
114
114
  MockResponse.find(options).should == response
115
115
  options[:http_method] = "get"
116
116
  expect { MockResponse.find(options) }.to raise_error(ServerResponseNotFound)
@@ -142,49 +142,15 @@ describe Mirage::MockResponse do
142
142
 
143
143
  end
144
144
 
145
- describe "matching on request parameters" do
146
- it 'should find the response if all required parameters are present' do
147
- get_spec = convert_keys_to_strings(
148
- {
149
- :request => {
150
- :http_method => "get",
151
- :parameters => {
152
- :firstname => "leon"
153
- }
154
- },
155
- :response => {
156
- :body => Base64.encode64("get response")
157
- }
158
- }
159
- )
160
-
161
- post_spec = convert_keys_to_strings(
162
- {
163
- :request => {
164
- :http_method => "post",
165
- :parameters => {
166
- :firstname => "leon"
167
- }
168
- },
169
- :response => {
170
- :body => Base64.encode64("post response")
171
- }
172
- }
173
- )
174
- get_response = MockResponse.new("greeting", get_spec)
175
- post_response = MockResponse.new("greeting", post_spec)
176
-
177
- options = {:body => "", :params => {"firstname" => "leon"}, :endpoint => "greeting", :http_method => "post",:headers => {}}
178
-
179
- MockResponse.find(options).should == post_response
180
- MockResponse.find(options.merge(:http_method => "get")).should == get_response
181
- end
182
-
183
- it 'should match request parameter values using regexps' do
184
- response_spec = convert_keys_to_strings(
145
+ describe 'matching' do
146
+ it 'should convert requirements in to strings before matching' do
147
+ requirement = 1234
148
+ spec = convert_keys_to_strings(
185
149
  {
186
150
  :request => {
187
- :parameters => {:firstname => "%r{leon.*}"}
151
+ :parameters => {:number => requirement},
152
+ :body_content => [requirement],
153
+ :headers => {:number => requirement}
188
154
  },
189
155
  :response => {
190
156
  :body => 'response'
@@ -192,107 +158,169 @@ describe Mirage::MockResponse do
192
158
 
193
159
  }
194
160
  )
195
- response = MockResponse.new("greeting", response_spec)
196
161
 
197
- options = {:body => "", :params => {"firstname" => "leon"}, :endpoint => "greeting", :http_method => "get",:headers => {}}
198
- MockResponse.find(options).should == response
199
- MockResponse.find(options.merge(:params => {"firstname" => "leonard"})).should == response
200
- expect { MockResponse.find(options.merge(:params => {"firstname" => "leo"})) }.to raise_error(ServerResponseNotFound)
201
- end
202
- end
162
+ MockResponse.new("greeting", spec)
163
+ options = {:headers => {'number' => '1234'},
164
+ :params => {'number' => "1234"},
165
+ :endpoint => "greeting",
166
+ :http_method => "get",
167
+ :body => "1234", }
203
168
 
204
- describe 'matching against request http_headers' do
205
- it 'should match using literals' do
206
- required_headers = {
207
- 'HEADER-1' => 'value1',
208
- 'HEADER-2' => 'value2'
209
- }
210
- spec = convert_keys_to_strings(
211
- {
212
- :request => {
213
- :headers => required_headers
214
- },
215
- :response => {
216
- :body => 'response'
217
- }
218
-
219
- }
220
- )
221
- response = MockResponse.new("greeting", spec)
169
+ expect { MockResponse.find(options) }.to_not raise_error
170
+ end
222
171
 
223
- options = {:body => "<name>leon</name>", :params => {}, :endpoint => "greeting", :http_method => "get", :headers => required_headers}
224
- MockResponse.find(options).should == response
225
- expect{MockResponse.find(options.merge(:headers => {}))}.to raise_error(ServerResponseNotFound)
172
+ describe "matching on request parameters" do
173
+ it 'should find the response if all required parameters are present' do
174
+ get_spec = convert_keys_to_strings(
175
+ {
176
+ :request => {
177
+ :http_method => "get",
178
+ :parameters => {
179
+ :firstname => "leon"
180
+ }
181
+ },
182
+ :response => {
183
+ :body => Base64.encode64("get response")
184
+ }
185
+ }
186
+ )
187
+
188
+ post_spec = convert_keys_to_strings(
189
+ {
190
+ :request => {
191
+ :http_method => "post",
192
+ :parameters => {
193
+ :firstname => "leon"
194
+ }
195
+ },
196
+ :response => {
197
+ :body => Base64.encode64("post response")
198
+ }
199
+ }
200
+ )
201
+ get_response = MockResponse.new("greeting", get_spec)
202
+ post_response = MockResponse.new("greeting", post_spec)
203
+
204
+ options = {:body => "", :params => {"firstname" => "leon"}, :endpoint => "greeting", :http_method => "post", :headers => {}}
205
+
206
+ MockResponse.find(options).should == post_response
207
+ MockResponse.find(options.merge(:http_method => "get")).should == get_response
208
+ end
226
209
 
210
+ it 'should match request parameter values using regexps' do
211
+ response_spec = convert_keys_to_strings(
212
+ {
213
+ :request => {
214
+ :parameters => {:firstname => "%r{leon.*}"}
215
+ },
216
+ :response => {
217
+ :body => 'response'
218
+ }
219
+
220
+ }
221
+ )
222
+ response = MockResponse.new("greeting", response_spec)
223
+
224
+ options = {:body => "", :params => {"firstname" => "leon"}, :endpoint => "greeting", :http_method => "get", :headers => {}}
225
+ MockResponse.find(options).should == response
226
+ MockResponse.find(options.merge(:params => {"firstname" => "leonard"})).should == response
227
+ expect { MockResponse.find(options.merge(:params => {"firstname" => "leo"})) }.to raise_error(ServerResponseNotFound)
228
+ end
227
229
  end
228
230
 
229
- it 'should match using regex' do
230
- required_headers = {
231
- 'CONTENT-TYPE' => '%r{.*/json}',
232
- }
233
- spec = convert_keys_to_strings(
234
- {
235
- :request => {
236
- :headers => required_headers
237
- },
238
- :response => {
239
- :body => 'response'
240
- }
231
+ describe 'matching against request http_headers' do
232
+ it 'should match using literals' do
233
+ required_headers = {
234
+ 'HEADER-1' => 'value1',
235
+ 'HEADER-2' => 'value2'
236
+ }
237
+ spec = convert_keys_to_strings(
238
+ {
239
+ :request => {
240
+ :headers => required_headers
241
+ },
242
+ :response => {
243
+ :body => 'response'
244
+ }
245
+
246
+ }
247
+ )
248
+ response = MockResponse.new("greeting", spec)
249
+
250
+ options = {:body => "<name>leon</name>", :params => {}, :endpoint => "greeting", :http_method => "get", :headers => required_headers}
251
+ MockResponse.find(options).should == response
252
+ expect { MockResponse.find(options.merge(:headers => {})) }.to raise_error(ServerResponseNotFound)
241
253
 
242
- }
243
- )
244
- response = MockResponse.new("greeting", spec)
254
+ end
245
255
 
246
- options = {:body => "<name>leon</name>", :params => {}, :endpoint => "greeting", :http_method => "get", :headers => {'CONTENT-TYPE' => 'application/json'}}
247
- MockResponse.find(options).should == response
248
- expect{MockResponse.find(options.merge(:headers => {'CONTENT-TYPE' => 'text/xml'}))}.to raise_error(ServerResponseNotFound)
256
+ it 'should match using regex' do
257
+ required_headers = {
258
+ 'CONTENT-TYPE' => '%r{.*/json}',
259
+ }
260
+ spec = convert_keys_to_strings(
261
+ {
262
+ :request => {
263
+ :headers => required_headers
264
+ },
265
+ :response => {
266
+ :body => 'response'
267
+ }
268
+
269
+ }
270
+ )
271
+ response = MockResponse.new("greeting", spec)
272
+
273
+ options = {:body => "<name>leon</name>", :params => {}, :endpoint => "greeting", :http_method => "get", :headers => {'CONTENT-TYPE' => 'application/json'}}
274
+ MockResponse.find(options).should == response
275
+ expect { MockResponse.find(options.merge(:headers => {'CONTENT-TYPE' => 'text/xml'})) }.to raise_error(ServerResponseNotFound)
249
276
 
277
+ end
250
278
  end
251
- end
252
279
 
253
- describe 'matching against the request body' do
254
- it 'should match required fragments in the request body' do
280
+ describe 'matching against the request body' do
281
+ it 'should match required fragments in the request body' do
255
282
 
256
- response_spec = convert_keys_to_strings(
257
- {
258
- :request => {
259
- :body_content => %w(leon)
260
- },
261
- :response => {
262
- :body => 'response'
263
- }
283
+ response_spec = convert_keys_to_strings(
284
+ {
285
+ :request => {
286
+ :body_content => %w(leon)
287
+ },
288
+ :response => {
289
+ :body => 'response'
290
+ }
264
291
 
265
- }
266
- )
292
+ }
293
+ )
267
294
 
268
- response = MockResponse.new("greeting", response_spec)
295
+ response = MockResponse.new("greeting", response_spec)
269
296
 
270
- options = {:body => "<name>leon</name>", :params => {}, :endpoint => "greeting", :http_method => "get", :headers => {} }
297
+ options = {:body => "<name>leon</name>", :params => {}, :endpoint => "greeting", :http_method => "get", :headers => {}}
271
298
 
272
- MockResponse.find(options).should == response
273
- expect { MockResponse.find(options.merge(:body => "<name>jeff</name>")) }.to raise_error(ServerResponseNotFound)
274
- end
299
+ MockResponse.find(options).should == response
300
+ expect { MockResponse.find(options.merge(:body => "<name>jeff</name>")) }.to raise_error(ServerResponseNotFound)
301
+ end
275
302
 
276
- it 'should use regexs to match required fragements in the request body' do
277
- response_spec = convert_keys_to_strings(
278
- {
279
- :request => {
280
- :body_content => %w(%r{leon.*})
281
- },
282
- :response => {
283
- :body => 'response'
284
- }
303
+ it 'should use regexs to match required fragements in the request body' do
304
+ response_spec = convert_keys_to_strings(
305
+ {
306
+ :request => {
307
+ :body_content => %w(%r{leon.*})
308
+ },
309
+ :response => {
310
+ :body => 'response'
311
+ }
285
312
 
286
- }
287
- )
313
+ }
314
+ )
288
315
 
289
- response = MockResponse.new("greeting", response_spec)
316
+ response = MockResponse.new("greeting", response_spec)
290
317
 
291
318
 
292
- options = {:body => "<name>leon</name>", :params => {}, :endpoint => "greeting", :http_method => "get", :headers => {} }
293
- MockResponse.find(options).should == response
294
- MockResponse.find(options.merge(:body => "<name>leonard</name>")).should == response
295
- expect { MockResponse.find(options.merge(:body => "<name>jeff</name>")) }.to raise_error(ServerResponseNotFound)
319
+ options = {:body => "<name>leon</name>", :params => {}, :endpoint => "greeting", :http_method => "get", :headers => {}}
320
+ MockResponse.find(options).should == response
321
+ MockResponse.find(options.merge(:body => "<name>leonard</name>")).should == response
322
+ expect { MockResponse.find(options.merge(:body => "<name>jeff</name>")) }.to raise_error(ServerResponseNotFound)
323
+ end
296
324
  end
297
325
  end
298
326
 
@@ -427,7 +455,7 @@ describe Mirage::MockResponse do
427
455
 
428
456
  MockResponse.new("greeting", default_response_spec)
429
457
  expected_response = MockResponse.new("greeting", specific_response_spec)
430
- options = {:body => "<action>login</action>", :params => {"name" => "leon"}, :endpoint => "greeting", :http_method => "get",:headers => {}}
458
+ options = {:body => "<action>login</action>", :params => {"name" => "leon"}, :endpoint => "greeting", :http_method => "get", :headers => {}}
431
459
  MockResponse.find(options).should == expected_response
432
460
  end
433
461
  end
@@ -449,7 +477,7 @@ describe Mirage::MockResponse do
449
477
 
450
478
 
451
479
  response = MockResponse.new("greeting", response_spec)
452
- options = {:body => "<action>login</action>", :params => {"name" => "leon"}, :endpoint => "greeting", :http_method => "post",:headers => {}}
480
+ options = {:body => "<action>login</action>", :params => {"name" => "leon"}, :endpoint => "greeting", :http_method => "post", :headers => {}}
453
481
  MockResponse.find(options).should == response
454
482
 
455
483
  options[:http_method] = 'get'
@@ -478,7 +506,7 @@ describe Mirage::MockResponse do
478
506
  end
479
507
 
480
508
  it 'should raise an exception when a response is not found' do
481
- expect { MockResponse.find(:body => "<action>login</action>", :params => {:name => "leon"}, :endpoint => "greeting", :http_method => "post",:headers => {}) }.to raise_error(ServerResponseNotFound)
509
+ expect { MockResponse.find(:body => "<action>login</action>", :params => {:name => "leon"}, :endpoint => "greeting", :http_method => "post", :headers => {}) }.to raise_error(ServerResponseNotFound)
482
510
  end
483
511
 
484
512
  it 'should return all responses' do
@@ -493,7 +521,7 @@ describe Mirage::MockResponse do
493
521
  it 'most appropriate response under parent resource and same http method' do
494
522
  level1_response = MockResponse.new("level1", convert_keys_to_strings({:response => {:body => "level1", :default => true}}))
495
523
  MockResponse.new("level1/level2", convert_keys_to_strings({:response => {:body => "level2", :default => true}, :request => {:body_content => %w(body)}}))
496
- MockResponse.find_default(:body => "", :http_method => "get", :endpoint => "level1/level2/level3", :params =>{}, :headers =>{}).should == level1_response
524
+ MockResponse.find_default(:body => "", :http_method => "get", :endpoint => "level1/level2/level3", :params => {}, :headers => {}).should == level1_response
497
525
  end
498
526
  end
499
527
 
@@ -513,7 +541,7 @@ describe Mirage::MockResponse do
513
541
  :parameters => {
514
542
  :name => "leon"
515
543
  },
516
- :headers =>{
544
+ :headers => {
517
545
  :header => 'header'
518
546
  },
519
547
  :http_method => "post"
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.10
4
+ version: 3.0.0.alpha.11
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-02 00:00:00.000000000 Z
12
+ date: 2013-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
@@ -349,7 +349,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
349
349
  version: '0'
350
350
  segments:
351
351
  - 0
352
- hash: 3670135109747540376
352
+ hash: -378399899441393951
353
353
  required_rubygems_version: !ruby/object:Gem::Requirement
354
354
  none: false
355
355
  requirements:
@@ -358,7 +358,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
358
358
  version: 1.3.1
359
359
  requirements: []
360
360
  rubyforge_project:
361
- rubygems_version: 1.8.24
361
+ rubygems_version: 1.8.25
362
362
  signing_key:
363
363
  specification_version: 3
364
364
  summary: Mirage is a easy mock server for testing your applications