mirage 3.0.9 → 3.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bcc4e3f498927b2de480bcc2f25e102245d63e65
4
- data.tar.gz: af0b4f30d39645bbce40384f53765489ac66718c
3
+ metadata.gz: 76e58c3eac183631006bdd36e2d7ba619d46e805
4
+ data.tar.gz: b0193298986161038a60c3b93bcdc5fbd7bd55f0
5
5
  SHA512:
6
- metadata.gz: e552a1b227624eab1adc290c98bde77a9d171d6bd82cd82bd70f13aa834b61c8254199806be62f983bdf1181697786da0767ee127dc1a2ab51bea51fdb058862
7
- data.tar.gz: 64362b27245db91411280f70ad39ea92c45f9d0c6ee9bd6ee0b67002837996967b3c7df7b3b556f3811c9bf85b89fcbe1a49df6418ac35a4a5d854ff412ecb34
6
+ metadata.gz: 6279f2660b94299109de7effa803276cd96421b13144759e464d5df5719a57683cb1699e224739d5f8dcb433e1f418ca40337f97969fbb0cb8714a209bec5a60
7
+ data.tar.gz: a956b41c885c0a7719c97dec4742113acf4edf44aa23aef486f90de3cb1b6e963b2b8e83fdaad356c55db5cf3078c4222e6a40668307a79ea374553026ddfe83
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.9
1
+ 3.0.10
data/mirage.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: mirage 3.0.9 ruby lib
5
+ # stub: mirage 3.0.10 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "mirage"
9
- s.version = "3.0.9"
9
+ s.version = "3.0.10"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Leon Davis"]
14
- s.date = "2014-12-08"
14
+ s.date = "2015-04-16"
15
15
  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."
16
16
  s.executables = ["mirage"]
17
17
  s.extra_rdoc_files = [
@@ -93,6 +93,7 @@ Gem::Specification.new do |s|
93
93
  "server/helpers/http_headers.rb",
94
94
  "server/helpers/template_requirements.rb",
95
95
  "server/mock_response.rb",
96
+ "server/mock_response_set.rb",
96
97
  "server/server.rb",
97
98
  "spec/client/cli_bridge_spec.rb",
98
99
  "spec/client/client_spec.rb",
@@ -110,6 +111,7 @@ Gem::Specification.new do |s|
110
111
  "spec/server/binary_data_checker_spec.rb",
111
112
  "spec/server/helpers/http_headers_spec.rb",
112
113
  "spec/server/helpers/template_requirements_spec.rb",
114
+ "spec/server/mock_response_set_spec.rb",
113
115
  "spec/server/mock_response_spec.rb",
114
116
  "spec/server/server_spec.rb",
115
117
  "spec/spec_helper.rb",
@@ -1,10 +1,10 @@
1
- class Hash
2
- alias_method :backup, :[]
3
-
4
- def [] desired_key
5
- result = backup(desired_key)
6
- return result unless result.nil?
7
- key, value = find{|key, value| key.is_a?(Regexp) && desired_key.is_a?(String) && key.match(desired_key) }
8
- value
9
- end
10
- end
1
+ #class Hash
2
+ # alias_method :backup, :[]
3
+ #
4
+ # def [] desired_key
5
+ # result = backup(desired_key)
6
+ # return result unless result.nil?
7
+ # key, value = find{|key, value| key.is_a?(Regexp) && desired_key.is_a?(String) && key.match(desired_key) }
8
+ # value
9
+ # end
10
+ #end
@@ -1,6 +1,9 @@
1
1
  require 'binary_data_checker'
2
2
 
3
3
  require 'hashie/mash'
4
+ require 'mock_response_set'
5
+
6
+
4
7
  module Mirage
5
8
  class ServerResponseNotFound < Exception
6
9
 
@@ -47,7 +50,7 @@ module Mirage
47
50
  options[:http_method].upcase!
48
51
  http_method = options[:http_method]
49
52
  default_responses = subdomains(options[:endpoint]).collect do |domain|
50
- if (responses_for_domain = responses[domain])
53
+ if (responses_for_domain = responses.fuzzy_find(domain))
51
54
  responses_for_domain[http_method].find_all { |response| response.default? } if responses_for_domain[http_method]
52
55
  end
53
56
  end.flatten.compact
@@ -64,7 +67,7 @@ module Mirage
64
67
  end
65
68
 
66
69
  def find(options)
67
- options[:response_set] = responses[options[:endpoint]]
70
+ options[:response_set] = responses.fuzzy_find(options[:endpoint])
68
71
  find_in_response_set(options) || raise(ServerResponseNotFound)
69
72
  end
70
73
 
@@ -139,7 +142,7 @@ module Mirage
139
142
  end
140
143
 
141
144
  def responses
142
- @responses ||={}
145
+ @responses ||= MockResponseSet.new
143
146
  end
144
147
 
145
148
  def snapshot
@@ -0,0 +1,10 @@
1
+ module Mirage
2
+ class MockResponseSet < Hash
3
+ def fuzzy_find desired_key
4
+ result = self[desired_key]
5
+ return result unless result.nil?
6
+ key, value = find{|key, value| key.is_a?(Regexp) && desired_key.is_a?(String) && key.match(desired_key) }
7
+ value
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+ require 'mock_response_set'
3
+ describe Mirage::MockResponseSet do
4
+
5
+ it 'extends Hash' do
6
+ expect(subject).to be_a(Hash)
7
+ end
8
+ describe '#fuzzy_find' do
9
+
10
+ let(:expected_greeting){'hello'}
11
+ let(:greeting_key){'/greeting'}
12
+
13
+ subject do
14
+ described_class.new.tap do |subject|
15
+ subject[greeting_key] = expected_greeting
16
+ end
17
+ end
18
+
19
+ context 'key is not a regex' do
20
+ context 'input is the same' do
21
+ it 'returns the stored value' do
22
+ expect(subject.fuzzy_find(greeting_key)).to eq(expected_greeting)
23
+ end
24
+ end
25
+
26
+ context 'input is different' do
27
+ it 'returns nil' do
28
+ expect(subject.fuzzy_find('/salutation')).to eq(nil)
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+
35
+ context 'key is a regular expression' do
36
+ subject do
37
+ described_class.new.tap do |subject|
38
+ subject[%r{.*ting}] = expected_greeting
39
+ end
40
+ end
41
+
42
+ context 'input is matches regex' do
43
+ it 'returns the stored value' do
44
+ expect(subject.fuzzy_find(greeting_key)).to eq(expected_greeting)
45
+ end
46
+ end
47
+
48
+ context 'input does not match regex' do
49
+ it 'returns nil' do
50
+ subject[%r{.*ting}] = expected_greeting
51
+ expect(subject.fuzzy_find('/salutation')).to eq(nil)
52
+ end
53
+
54
+ end
55
+ end
56
+ end
57
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mirage
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.9
4
+ version: 3.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leon Davis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-08 00:00:00.000000000 Z
11
+ date: 2015-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -263,6 +263,7 @@ files:
263
263
  - server/helpers/http_headers.rb
264
264
  - server/helpers/template_requirements.rb
265
265
  - server/mock_response.rb
266
+ - server/mock_response_set.rb
266
267
  - server/server.rb
267
268
  - spec/client/cli_bridge_spec.rb
268
269
  - spec/client/client_spec.rb
@@ -280,6 +281,7 @@ files:
280
281
  - spec/server/binary_data_checker_spec.rb
281
282
  - spec/server/helpers/http_headers_spec.rb
282
283
  - spec/server/helpers/template_requirements_spec.rb
284
+ - spec/server/mock_response_set_spec.rb
283
285
  - spec/server/mock_response_spec.rb
284
286
  - spec/server/server_spec.rb
285
287
  - spec/spec_helper.rb