mirage 2.0.8 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -1,4 +1,4 @@
1
- V2.0.8 - tidy up code, still a lot to do :)
1
+ V2.0.8/9 - tidy up code, still a lot to do :)
2
2
  V2.0.7 - fix missing dependency on waitforit gem
3
3
  V2.0.1/2/3 - tidying up code
4
4
  V2.0.0 - Converted to restful interface
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.8
1
+ 2.0.9
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "mirage"
8
- s.version = "2.0.8"
8
+ s.version = "2.0.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Leon Davis"]
12
- s.date = "2011-12-14"
12
+ s.date = "2011-12-15"
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 = [
@@ -51,6 +51,7 @@ Gem::Specification.new do |s|
51
51
  "mirage.gemspec",
52
52
  "mirage_server.rb",
53
53
  "rakefile",
54
+ "server/extensions/hash.rb",
54
55
  "server/extensions/object.rb",
55
56
  "server/mock_response.rb",
56
57
  "server/util.rb",
@@ -7,6 +7,7 @@ $LOAD_PATH.unshift("#{ROOT_DIR}/server")
7
7
  require 'sinatra/base'
8
8
 
9
9
  require 'extensions/object'
10
+ require 'extensions/hash'
10
11
  require 'mock_response'
11
12
  require 'util'
12
13
 
@@ -85,7 +86,7 @@ module Mirage
85
86
 
86
87
  get '/mirage/templates/:id' do
87
88
  response = MockResponse.find(response_id)
88
- return 404 if response.is_a? Array
89
+ return 404 if response.nil? || response.is_a?(Array)
89
90
  send_response(response)
90
91
  end
91
92
 
@@ -0,0 +1,10 @@
1
+ class Hash
2
+ alias_method :backup, :[]
3
+
4
+ def [] desired_key
5
+ result = backup(desired_key)
6
+ return result if result
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
@@ -18,23 +18,11 @@ module Mirage
18
18
  end
19
19
 
20
20
  def find id
21
- responses.values.each do |response_sets|
22
- response_sets.values.each do |response_set|
23
- response_set.values.each do |response|
24
- return response if response.response_id == id
25
- end
26
- end
27
- end
21
+ response_set_containing(id).values.find { |response| response.response_id == id }
28
22
  end
29
23
 
30
- def delete(response_id)
31
- responses.values.each do |response_sets|
32
- response_sets.values.each do |response_set|
33
- response_set.each do |method, response|
34
- response_set.delete(method) if response.response_id == response_id
35
- end
36
- end
37
- end
24
+ def delete(id)
25
+ response_set_containing(id).delete_if { |http_method, response| response.response_id == id }
38
26
  end
39
27
 
40
28
  def clear
@@ -47,17 +35,13 @@ module Mirage
47
35
  end
48
36
 
49
37
  def revert
50
- responses.clear and responses.replace(snapshot.deep_clone)
38
+ clear and responses.replace(snapshot.deep_clone)
51
39
  end
52
40
 
53
41
  def all
54
42
  all_responses = []
55
- responses.values.each do |response_sets|
56
- response_sets.values.each do |response_set|
57
- response_set.values.each do |response|
58
- all_responses << response
59
- end
60
- end
43
+ response_sets.each do |response_set|
44
+ response_set.values.each{|response|all_responses << response}
61
45
  end
62
46
  all_responses
63
47
  end
@@ -74,16 +58,19 @@ module Mirage
74
58
  private
75
59
  def find_response(body, query_string, response_set, http_method)
76
60
  return unless response_set
77
- http_method = http_method.upcase
78
- pattern_match = response_set.keys.find_all { |pattern| pattern != :basic }.find { |pattern| (body =~ pattern || query_string =~ pattern) }
79
-
80
- if pattern_match
81
- record = response_set[pattern_match][http_method]
82
- else
83
- record = response_set[:basic]
84
- record = record[http_method] if record
61
+ response_set = response_set[body] || response_set[query_string] || response_set[:basic]
62
+ response_set[http_method.upcase] if response_set
63
+ end
64
+
65
+ def response_set_containing id
66
+ response_sets.each do |response_set|
67
+ return response_set if response_set.find { |key, response| response.response_id == id }
85
68
  end
86
- record
69
+ {}
70
+ end
71
+
72
+ def response_sets
73
+ responses.values.collect { |response_sets| response_sets.values }.flatten
87
74
  end
88
75
 
89
76
  def find_default_responses(name)
data/test.rb CHANGED
@@ -1,8 +1,22 @@
1
- hash = Hash.new do |hash, key|
2
- hash[key] = Hash.new do |patterns_hash, pattern|
3
- patterns_hash[pattern] = {:blah => 'foo'}
1
+ class Hash
2
+ alias_method :backup, :[]
3
+
4
+ def [] desired_key
5
+ result = backup(desired_key)
6
+ return result if result
7
+ key, value = find{|key, value| key.is_a?(Regexp) && desired_key.is_a?(String) && key.match(desired_key) }
8
+ value
4
9
  end
5
10
  end
6
- hash = hash['thing']['whatever']
11
+ hash = {/hello/ => 'hello', :foo => 'bar'}
12
+
13
+ #def hash.[] desired_key
14
+ # key, value = find{|key, value| key.match(desired_key)}
15
+ # value
16
+ #end
17
+
18
+
19
+ puts hash['hello']
20
+ puts hash[:foo]
7
21
 
8
- puts hash
22
+ Marshal.dump(hash)
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: 2.0.8
4
+ version: 2.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-14 00:00:00.000000000Z
12
+ date: 2011-12-15 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
- requirement: &21161500 !ruby/object:Gem::Requirement
16
+ requirement: &15932480 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *21161500
24
+ version_requirements: *15932480
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: childprocess
27
- requirement: &21160920 !ruby/object:Gem::Requirement
27
+ requirement: &15931880 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.1'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *21160920
35
+ version_requirements: *15931880
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: waitforit
38
- requirement: &21160360 !ruby/object:Gem::Requirement
38
+ requirement: &15931260 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *21160360
46
+ version_requirements: *15931260
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &21159720 !ruby/object:Gem::Requirement
49
+ requirement: &15930660 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *21159720
57
+ version_requirements: *15930660
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: cucumber
60
- requirement: &21159100 !ruby/object:Gem::Requirement
60
+ requirement: &15929900 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *21159100
68
+ version_requirements: *15929900
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
- requirement: &21158480 !ruby/object:Gem::Requirement
71
+ requirement: &15929260 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - =
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 2.6.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *21158480
79
+ version_requirements: *15929260
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: jeweler
82
- requirement: &21157860 !ruby/object:Gem::Requirement
82
+ requirement: &15928640 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 1.5.2
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *21157860
90
+ version_requirements: *15928640
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: sinatra-contrib
93
- requirement: &21154260 !ruby/object:Gem::Requirement
93
+ requirement: &15839740 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *21154260
101
+ version_requirements: *15839740
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: mechanize
104
- requirement: &21153660 !ruby/object:Gem::Requirement
104
+ requirement: &15838740 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - =
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 1.0.0
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *21153660
112
+ version_requirements: *15838740
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: gemcutter
115
- requirement: &21153000 !ruby/object:Gem::Requirement
115
+ requirement: &15838020 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *21153000
123
+ version_requirements: *15838020
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: nokogiri
126
- requirement: &21152460 !ruby/object:Gem::Requirement
126
+ requirement: &15837380 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - =
@@ -131,7 +131,7 @@ dependencies:
131
131
  version: 1.4.7
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *21152460
134
+ version_requirements: *15837380
135
135
  description: Mirage aids testing of your applications by hosting mock responses so
136
136
  that your applications do not have to talk to real endpoints. Its accessible via
137
137
  HTTP and has a RESTful interface.
@@ -177,6 +177,7 @@ files:
177
177
  - mirage.gemspec
178
178
  - mirage_server.rb
179
179
  - rakefile
180
+ - server/extensions/hash.rb
180
181
  - server/extensions/object.rb
181
182
  - server/mock_response.rb
182
183
  - server/util.rb
@@ -199,7 +200,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
199
200
  version: '0'
200
201
  segments:
201
202
  - 0
202
- hash: 2115174176244193400
203
+ hash: 3612992217465972196
203
204
  required_rubygems_version: !ruby/object:Gem::Requirement
204
205
  none: false
205
206
  requirements: