mirage 3.0.3 → 3.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/mirage.gemspec +2 -2
- data/server/server.rb +52 -23
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0.
|
1
|
+
3.0.4
|
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.
|
8
|
+
s.version = "3.0.4"
|
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 = "2013-
|
12
|
+
s.date = "2013-11-18"
|
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 = [
|
data/server/server.rb
CHANGED
@@ -7,12 +7,14 @@ module Mirage
|
|
7
7
|
|
8
8
|
REQUESTS = {}
|
9
9
|
|
10
|
-
|
11
10
|
helpers Mirage::Server::Helpers
|
12
11
|
|
13
12
|
put '/templates/*' do |name|
|
14
13
|
content_type :json
|
15
|
-
mock_response =
|
14
|
+
mock_response = synchronize do
|
15
|
+
MockResponse.new(name, JSON.parse(request.body.read))
|
16
|
+
end
|
17
|
+
|
16
18
|
mock_response.requests_url = request.url.gsub("/templates/#{name}", "/requests/#{mock_response.response_id}")
|
17
19
|
{:id => mock_response.response_id}.to_json
|
18
20
|
end
|
@@ -32,7 +34,10 @@ module Mirage
|
|
32
34
|
record = MockResponse.find_default(options)
|
33
35
|
end
|
34
36
|
|
35
|
-
|
37
|
+
synchronize do
|
38
|
+
REQUESTS[record.response_id] = request.dup
|
39
|
+
end
|
40
|
+
|
36
41
|
|
37
42
|
send_response(record, body, request, query_string)
|
38
43
|
end
|
@@ -43,24 +48,36 @@ module Mirage
|
|
43
48
|
end
|
44
49
|
|
45
50
|
delete '/templates/:id' do
|
46
|
-
|
47
|
-
|
51
|
+
synchronize do
|
52
|
+
MockResponse.delete(response_id)
|
53
|
+
REQUESTS.delete(response_id)
|
54
|
+
end
|
55
|
+
|
48
56
|
200
|
49
57
|
end
|
50
58
|
|
51
59
|
delete '/requests' do
|
52
|
-
|
60
|
+
synchronize do
|
61
|
+
REQUESTS.clear
|
62
|
+
end
|
63
|
+
|
53
64
|
200
|
54
65
|
end
|
55
66
|
|
56
67
|
delete '/requests/:id' do
|
57
|
-
|
68
|
+
synchronize do
|
69
|
+
REQUESTS.delete(response_id)
|
70
|
+
end
|
71
|
+
|
58
72
|
200
|
59
73
|
end
|
60
74
|
|
61
75
|
delete '/templates' do
|
62
|
-
|
63
|
-
|
76
|
+
synchronize do
|
77
|
+
REQUESTS.clear
|
78
|
+
MockResponse.delete_all
|
79
|
+
end
|
80
|
+
|
64
81
|
200
|
65
82
|
end
|
66
83
|
|
@@ -76,12 +93,12 @@ module Mirage
|
|
76
93
|
tracked_request.body.rewind
|
77
94
|
body = tracked_request.body.read
|
78
95
|
|
79
|
-
parameters = tracked_request.params.dup.select{|key, value| key != body}
|
96
|
+
parameters = tracked_request.params.dup.select { |key, value| key != body }
|
80
97
|
|
81
|
-
{
|
82
|
-
|
83
|
-
|
84
|
-
|
98
|
+
{request_url: request.url,
|
99
|
+
headers: extract_http_headers(tracked_request.env),
|
100
|
+
parameters: parameters,
|
101
|
+
body: body}.to_json
|
85
102
|
|
86
103
|
else
|
87
104
|
404
|
@@ -94,13 +111,15 @@ module Mirage
|
|
94
111
|
|
95
112
|
|
96
113
|
put '/defaults' do
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
114
|
+
synchronize do
|
115
|
+
MockResponse.delete_all
|
116
|
+
if File.directory?(settings.defaults.to_s)
|
117
|
+
Dir["#{settings.defaults}/**/*.rb"].each do |default|
|
118
|
+
begin
|
119
|
+
eval File.read(default)
|
120
|
+
rescue Exception => e
|
121
|
+
raise "Unable to load default responses from: #{default}"
|
122
|
+
end
|
104
123
|
end
|
105
124
|
end
|
106
125
|
end
|
@@ -108,13 +127,19 @@ module Mirage
|
|
108
127
|
end
|
109
128
|
#
|
110
129
|
put '/backup' do
|
111
|
-
|
130
|
+
synchronize do
|
131
|
+
MockResponse.backup
|
132
|
+
end
|
133
|
+
|
112
134
|
200
|
113
135
|
end
|
114
136
|
|
115
137
|
|
116
138
|
put '/' do
|
117
|
-
|
139
|
+
synchronize do
|
140
|
+
MockResponse.revert
|
141
|
+
end
|
142
|
+
|
118
143
|
200
|
119
144
|
end
|
120
145
|
|
@@ -132,6 +157,10 @@ module Mirage
|
|
132
157
|
|
133
158
|
helpers do
|
134
159
|
|
160
|
+
def synchronize &block
|
161
|
+
Mutex.new.synchronize &block
|
162
|
+
end
|
163
|
+
|
135
164
|
def response_id
|
136
165
|
params[:id].to_i
|
137
166
|
end
|
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.
|
4
|
+
version: 3.0.4
|
5
5
|
prerelease:
|
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-
|
12
|
+
date: 2013-11-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
@@ -368,7 +368,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
368
368
|
version: '0'
|
369
369
|
segments:
|
370
370
|
- 0
|
371
|
-
hash:
|
371
|
+
hash: -2506463001240153653
|
372
372
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
373
373
|
none: false
|
374
374
|
requirements:
|