mirage 3.0.4 → 3.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -2
- data/Rakefile +5 -76
- data/VERSION +1 -1
- data/features/client/configure.feature +1 -1
- data/features/client/model.feature +1 -1
- data/features/client/preview_responses.feature +1 -1
- data/features/client/prime.feature +1 -1
- data/features/client/put.feature +1 -1
- data/features/client/running.feature +1 -1
- data/features/client/save_and_revert.feature +1 -1
- data/features/client/stop.feature +1 -1
- data/features/step_definitions/my_steps.rb +17 -200
- data/features/step_definitions/observation_steps.rb +102 -0
- data/features/support/command_line.rb +11 -0
- data/features/support/env.rb +2 -6
- data/features/support/hooks.rb +1 -2
- data/features/support/mirage.rb +5 -1
- data/features/support/web.rb +11 -60
- data/features/templates/required_content.feature +4 -1
- data/lib/mirage/client/helpers/method_builder.rb +1 -1
- data/mirage.gemspec +6 -2
- data/spec/client/helpers/method_builder_spec.rb +26 -18
- data/spec/client/runner_spec.rb +1 -1
- data/spec/client/template_spec.rb +1 -1
- data/spec/server/binary_data_checker_spec.rb +0 -1
- data/spec/server/mock_response_spec.rb +1 -3
- data/tasks/application.rake +7 -0
- data/tasks/packaging.rake +28 -0
- data/tasks/tests.rake +25 -0
- metadata +7 -3
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,81 +1,10 @@
|
|
1
|
-
|
2
|
-
require 'rubygems'
|
3
|
-
require 'bundler'
|
1
|
+
require 'bundler/setup'
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
rescue Bundler::BundlerError => e
|
8
|
-
$stderr.puts e.message
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
11
|
-
end
|
12
|
-
|
13
|
-
require 'rake'
|
14
|
-
require 'rspec/core/rake_task'
|
15
|
-
|
16
|
-
task :specs
|
17
|
-
|
18
|
-
%w(client server).each do |type|
|
19
|
-
public_task_name = "#{type}_specs"
|
20
|
-
private_task_name = "_#{public_task_name}"
|
21
|
-
|
22
|
-
RSpec::Core::RakeTask.new(private_task_name) do |task|
|
23
|
-
task.pattern = "spec/#{type}/**/*_spec.rb"
|
24
|
-
end
|
25
|
-
|
26
|
-
desc "specs for: #{type}"
|
27
|
-
task public_task_name do
|
28
|
-
ENV['coverage'] = type
|
29
|
-
Rake::Task[private_task_name].invoke
|
30
|
-
end
|
31
|
-
|
32
|
-
Rake::Task["specs"].prerequisites << public_task_name
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
require 'jeweler'
|
37
|
-
Jeweler::Tasks.new do |gem|
|
38
|
-
gem.name = "mirage"
|
39
|
-
gem.homepage = "https://github.com/lashd/mirage"
|
40
|
-
gem.license = "MIT"
|
41
|
-
gem.summary = "Mirage is a easy mock server for testing your applications"
|
42
|
-
gem.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.'
|
43
|
-
gem.authors = ["Leon Davis"]
|
44
|
-
gem.executables = ['mirage']
|
45
|
-
gem.post_install_message = %{
|
46
|
-
===============================================================================
|
47
|
-
Mirage v3:
|
48
|
-
|
49
|
-
Mirage has just gone up a major version from 2 to 3. If you're project uses
|
50
|
-
a previous version take a look at https://github.com/lashd/mirage to see
|
51
|
-
what's changed
|
52
|
-
===============================================================================
|
53
|
-
}
|
54
|
-
end
|
55
|
-
Jeweler::RubygemsDotOrgTasks.new
|
56
|
-
|
57
|
-
|
58
|
-
require 'cucumber'
|
59
|
-
require 'cucumber/rake/task'
|
60
|
-
Cucumber::Rake::Task.new(:features) do |t|
|
61
|
-
t.cucumber_opts = "mode=regression features --format pretty"
|
62
|
-
end
|
63
|
-
|
64
|
-
task :clean do |task|
|
65
|
-
if system "gem list -i mirage"
|
66
|
-
puts "cleaning"
|
67
|
-
system "gem uninstall -x mirage"
|
68
|
-
end
|
69
|
-
Dir['*.gem'].each { |gem| FileUtils.rm_f(gem) }
|
70
|
-
task.reenable
|
71
|
-
end
|
72
|
-
|
73
|
-
task :start do
|
74
|
-
`RACK_ENV='development' && ruby ./bin/mirage start`
|
75
|
-
end
|
3
|
+
Bundler.setup(:default, :development)
|
4
|
+
Bundler.require(:test, :development)
|
76
5
|
|
77
|
-
|
78
|
-
|
6
|
+
Dir["#{File.dirname(__FILE__)}/tasks/**/*.rake"].each do |tasks|
|
7
|
+
import tasks
|
79
8
|
end
|
80
9
|
|
81
10
|
task :default => [:specs, :install, :features, :clean]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0.
|
1
|
+
3.0.5
|
@@ -3,7 +3,7 @@ Feature: Configuring Templates
|
|
3
3
|
If you find yourself setting the same basic http settings for templates, the client can be configured to preset these.
|
4
4
|
|
5
5
|
Background:
|
6
|
-
Given the following
|
6
|
+
Given the following require statements are needed:
|
7
7
|
"""
|
8
8
|
require 'rubygems'
|
9
9
|
require 'rspec/expectations'
|
@@ -3,7 +3,7 @@ Feature: Inspecting Templates
|
|
3
3
|
The client can be used to retrieve a template stored on Mirage.
|
4
4
|
|
5
5
|
Background:
|
6
|
-
Given the following
|
6
|
+
Given the following require statements are needed:
|
7
7
|
"""
|
8
8
|
require 'rubygems'
|
9
9
|
require 'rspec/expectations'
|
@@ -3,7 +3,7 @@ Feature: Priming Mirage
|
|
3
3
|
The client can be used to prime Mirage with Templates found in the templates directory that was configured when Mirage was started.
|
4
4
|
|
5
5
|
Background:
|
6
|
-
Given the following
|
6
|
+
Given the following require statements are needed:
|
7
7
|
"""
|
8
8
|
require 'rubygems'
|
9
9
|
require 'rspec/expectations'
|
data/features/client/put.feature
CHANGED
@@ -7,7 +7,7 @@ Feature: Adding Templates
|
|
7
7
|
Body, Header, and Parameter requirements can be specified as either a String or Regexp
|
8
8
|
|
9
9
|
Background:
|
10
|
-
Given the following
|
10
|
+
Given the following require statements are needed:
|
11
11
|
"""
|
12
12
|
require 'rubygems'
|
13
13
|
require 'rspec/expectations'
|
@@ -1,32 +1,3 @@
|
|
1
|
-
require 'base64'
|
2
|
-
require 'hashie'
|
3
|
-
Then /^'([^']*)' should be returned$/ do |expected_response|
|
4
|
-
response_text = @response.body
|
5
|
-
if response_text != expected_response
|
6
|
-
expected_response.split('&').each { |param_value_pair| response_text.should =~ /#{param_value_pair}/ }
|
7
|
-
expected_response.length.should == response_text.length
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
Then /^a (\d+) should be returned$/ do |error_code|
|
12
|
-
@response.code.to_i.should == error_code.to_i
|
13
|
-
end
|
14
|
-
|
15
|
-
Then /^it should take at least '(.*)' seconds$/ do |time|
|
16
|
-
(@response_time).should >= time.to_f
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
Then /^mirage (should|should not) be running on '(.*)'$/ do |should, url|
|
21
|
-
running = false
|
22
|
-
begin
|
23
|
-
running = http_get(url).code.to_i.should == 200
|
24
|
-
rescue
|
25
|
-
end
|
26
|
-
|
27
|
-
should == "should" ? running.should == true : running.should == false
|
28
|
-
end
|
29
|
-
|
30
1
|
Given /^I run '(.*)'$/ do |command|
|
31
2
|
if ENV['mode'] == 'regression' && ChildProcess.windows?
|
32
3
|
command.gsub!(/^mirage/, MIRAGE_CMD)
|
@@ -37,36 +8,8 @@ Given /^I run '(.*)'$/ do |command|
|
|
37
8
|
@commandline_output = normalise(run("#{path}#{command}"))
|
38
9
|
end
|
39
10
|
|
40
|
-
Given /^Mirage (is|is not) running$/ do |running|
|
41
|
-
if running == 'is'
|
42
|
-
start_mirage_in_scratch_dir unless Mirage.running?
|
43
|
-
else
|
44
|
-
Mirage.stop :all
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
Then /^Connection should be refused to '(.*)'$/ do |url|
|
49
|
-
begin
|
50
|
-
http_get(url)
|
51
|
-
fail "Mirage is still running"
|
52
|
-
rescue Errno::ECONNREFUSED
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
11
|
Given /^the file '(.*)' contains:$/ do |file_path, content|
|
57
|
-
|
58
|
-
|
59
|
-
FileUtils.rm_rf(file_path) if File.exists?(file_path)
|
60
|
-
FileUtils.mkdir_p(File.dirname(file_path))
|
61
|
-
|
62
|
-
File.open("#{file_path}", 'w') do |file|
|
63
|
-
file.write(content)
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
Then /^the usage information should be displayed$/ do
|
69
|
-
@usage.each_line { |line| @commandline_output.should include(line) }
|
12
|
+
write_to_file file_path, content
|
70
13
|
end
|
71
14
|
|
72
15
|
Given /^usage information:$/ do |usage|
|
@@ -84,87 +27,32 @@ Given /^the following require statements are needed:$/ do |text|
|
|
84
27
|
@code_snippet = text.gsub("\"", "\\\\\"")
|
85
28
|
end
|
86
29
|
|
87
|
-
Given /^the following gems are required to run the Mirage client test code:$/ do |text|
|
88
|
-
@code_snippet = text.gsub("\"", "\\\\\"")
|
89
|
-
end
|
90
|
-
|
91
30
|
When /^I send (POST|PUT) to '(.*)' with request entity$/ do |method, endpoint, entity|
|
92
31
|
url = "http://localhost:7001#{endpoint}"
|
93
32
|
@response = case method
|
94
33
|
when 'POST'
|
95
|
-
|
96
|
-
http_post(url, entity)
|
34
|
+
post(url, body: entity)
|
97
35
|
when 'PUT'
|
98
|
-
|
99
|
-
http_put(url, entity)
|
36
|
+
put(url, body: entity)
|
100
37
|
end
|
101
38
|
end
|
102
39
|
|
103
|
-
When /^(GET|PUT|POST|
|
40
|
+
When /^(GET|PUT|POST|DELETE) is sent to '([^']*)'$/ do |method, endpoint|
|
104
41
|
start_time = Time.now
|
105
42
|
url = "http://localhost:7001#{endpoint}"
|
106
43
|
@response = case method
|
107
44
|
when 'GET' then
|
108
|
-
|
45
|
+
get(url)
|
109
46
|
when 'PUT' then
|
110
|
-
|
47
|
+
put(url, body: '')
|
111
48
|
when 'POST' then
|
112
|
-
|
113
|
-
when 'HEAD' then
|
114
|
-
http_head(url)
|
115
|
-
when 'OPTIONS' then
|
116
|
-
http_options(url)
|
49
|
+
post(url, body: '')
|
117
50
|
when 'DELETE' then
|
118
|
-
|
119
|
-
end
|
120
|
-
@response_time = Time.now - start_time
|
121
|
-
end
|
122
|
-
|
123
|
-
|
124
|
-
When /^I send (PUT|POST) to '(.*)' with body '(.*)'$/ do |method, endpoint, body|
|
125
|
-
url = "http://localhost:7001#{endpoint}"
|
126
|
-
start_time = Time.now
|
127
|
-
@response = case method
|
128
|
-
when 'PUT'
|
129
|
-
http_put(url, body)
|
130
|
-
when 'POST'
|
131
|
-
http_post(url, body)
|
51
|
+
delete(url)
|
132
52
|
end
|
133
|
-
|
134
53
|
@response_time = Time.now - start_time
|
135
54
|
end
|
136
55
|
|
137
|
-
When /^I send PUT to '(.*)' with body '([^']*)' and headers:$/ do |endpoint, body, table|
|
138
|
-
url = "http://localhost:7001#{endpoint}"
|
139
|
-
headers = {}
|
140
|
-
table.raw.each do |row|
|
141
|
-
parameter, value = row[0], row[1]
|
142
|
-
headers[parameter]=value
|
143
|
-
end
|
144
|
-
@response = http_put(url, body, :headers => headers)
|
145
|
-
end
|
146
|
-
|
147
|
-
Then /^I should see '(.*?)' on the command line$/ do |content|
|
148
|
-
@commandline_output.should include(content)
|
149
|
-
end
|
150
|
-
|
151
|
-
Then /^'(.*)' should exist$/ do |path|
|
152
|
-
File.exists?("#{SCRATCH}/#{path}").should == true
|
153
|
-
end
|
154
|
-
|
155
|
-
Then /^mirage.log should contain '(.*)'$/ do |content|
|
156
|
-
log_file_content = @mirage_log_file.readlines.to_s
|
157
|
-
fail("#{content} not found in mirage.log: #{log_file_content}") unless log_file_content.index(content)
|
158
|
-
end
|
159
|
-
|
160
|
-
Given /^I goto '(.*)'$/ do |url|
|
161
|
-
@page = Mechanize.new.get url
|
162
|
-
end
|
163
|
-
|
164
|
-
Then /^I should see '(.*)'$/ do |text|
|
165
|
-
@page.body.index(text).should_not == nil
|
166
|
-
end
|
167
|
-
|
168
56
|
When /^I click '(.*)'$/ do |thing|
|
169
57
|
@page = @page.links.find { |link| link.attributes['id'] == thing }.click
|
170
58
|
end
|
@@ -179,103 +67,32 @@ When /^I send (GET|POST) to '(.*)' with parameters:$/ do |http_method, endpoint,
|
|
179
67
|
value = File.exists?(value) ? File.open(value, 'rb') : value
|
180
68
|
parameters[parameter]=value
|
181
69
|
end
|
70
|
+
puts parameters
|
182
71
|
|
183
72
|
@response = case http_method
|
184
73
|
when 'POST' then
|
185
|
-
|
74
|
+
post(url, query: parameters, headers: {'Content-length' => '0'})
|
186
75
|
when 'GET' then
|
187
|
-
|
76
|
+
get(url, query: parameters)
|
188
77
|
end
|
189
78
|
end
|
190
79
|
|
191
|
-
Then /^the following should be returned:$/ do |text|
|
192
|
-
text.gsub("\n","").gsub(" ", "").should == @response.body
|
193
|
-
end
|
194
|
-
|
195
|
-
Given /^I send PUT to '(http:\/\/localhost:7001\/mirage\/(.*?))' with file: ([^']*) and headers:$/ do |url, endpoint, path, table|
|
196
|
-
headers = {}
|
197
|
-
table.raw.each do |row|
|
198
|
-
parameter, value = row[0], row[1]
|
199
|
-
headers[parameter]=value
|
200
|
-
end
|
201
|
-
|
202
|
-
Dir.chdir SCRATCH do
|
203
|
-
http_put(url, File.new(path), :headers => headers)
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
Given /^I send PUT to '(.*?)' with body '([^']*)' and parameters:$/ do |endpoint, body, table|
|
208
|
-
url = "http://localhost:7001#{endpoint}"
|
209
|
-
headers = {}
|
210
|
-
table.raw.each do |row|
|
211
|
-
parameter, value = row[0], row[1]
|
212
|
-
headers[parameter]=value
|
213
|
-
end
|
214
|
-
|
215
|
-
Dir.chdir SCRATCH do
|
216
|
-
http_put(url, File.new("/home/team/Projects/mirage/pkg/mirage-2.1.2.gem"), :parameters => headers)
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
|
221
|
-
When /^the response '([^']*)' should be '([^']*)'$/ do |header, value|
|
222
|
-
@response.response[header].should include(value)
|
223
|
-
end
|
224
|
-
|
225
|
-
Then /^the response should be the same as the content of '([^']*)'$/ do |path|
|
226
|
-
Dir.chdir SCRATCH do
|
227
|
-
@response.body.should == File.read(path)
|
228
|
-
end
|
229
|
-
end
|
230
80
|
Given /^the following template template:$/ do |text|
|
231
81
|
@response_template = Hashie::Mash.new(JSON.parse(text))
|
232
82
|
end
|
83
|
+
|
233
84
|
When /^'(.*)' is base64 encoded$/ do |template_component|
|
234
85
|
@response_template.send(:eval, "#{template_component}=Base64.encode64(#{template_component})")
|
235
86
|
end
|
236
|
-
When /^the template is sent using PUT to '(.*?)'$/ do |endpoint|
|
237
87
|
|
238
|
-
|
88
|
+
When /^the template is sent using PUT to '(.*?)'$/ do |endpoint|
|
89
|
+
@response = put("http://localhost:7001#{endpoint}", body: @response_template.to_hash.to_json, :headers => {"Content-Type" => "application/json"})
|
239
90
|
end
|
91
|
+
|
240
92
|
Given /^a template for '(.*)' has been set with a value of '(.*)'$/ do |endpoint, value|
|
241
|
-
|
242
|
-
end
|
243
|
-
Then /^request data should have been retrieved$/ do
|
244
|
-
puts @response.body
|
245
|
-
request_data = JSON.parse(@response.body)
|
246
|
-
request_data.include?('parameters').should == true
|
247
|
-
request_data.include?('headers').should == true
|
248
|
-
request_data.include?('body').should == true
|
249
|
-
request_data.include?('request_url').should == true
|
93
|
+
mirage.templates.put(endpoint, value)
|
250
94
|
end
|
95
|
+
|
251
96
|
Given(/^the following Template JSON:$/) do |text|
|
252
97
|
@response_template = Hashie::Mash.new(JSON.parse(text))
|
253
|
-
end
|
254
|
-
Then(/^the template (request|response) specification should have the following set:$/) do |spec, table|
|
255
|
-
template_json = JSON.parse(http_get("http://localhost:7001/templates/#{JSON.parse(@response.body)['id']}").body)
|
256
|
-
request_specification = template_json[spec]
|
257
|
-
request_specification.size.should==table.hashes.size
|
258
|
-
table.hashes.each do |hash|
|
259
|
-
default = request_specification[hash['Setting'].downcase.gsub(' ', '_')]
|
260
|
-
case required_default = hash['Default']
|
261
|
-
when 'none'
|
262
|
-
case default
|
263
|
-
when Array
|
264
|
-
default.should == []
|
265
|
-
when Hash
|
266
|
-
default.should == {}
|
267
|
-
else
|
268
|
-
default.should == ""
|
269
|
-
|
270
|
-
end
|
271
|
-
else
|
272
|
-
default.to_s.downcase.should == required_default.downcase
|
273
|
-
end
|
274
|
-
end
|
275
|
-
end
|
276
|
-
Then(/^the following json should be returned:$/) do |text|
|
277
|
-
JSON.parse(text).should == JSON.parse(@response.body)
|
278
|
-
end
|
279
|
-
When(/^the content-type should be '(.*)'$/) do |content_type|
|
280
|
-
@response.content_type.should == content_type
|
281
98
|
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
Then /^'([^']*)' should be returned$/ do |expected_response|
|
2
|
+
response_text = @response.body
|
3
|
+
if response_text != expected_response
|
4
|
+
expected_response.split('&').each { |param_value_pair| response_text.should =~ /#{param_value_pair}/ }
|
5
|
+
expected_response.length.should == response_text.length
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
Then /^a (\d+) should be returned$/ do |error_code|
|
10
|
+
@response.code.to_i.should == error_code.to_i
|
11
|
+
end
|
12
|
+
|
13
|
+
Then /^it should take at least '(.*)' seconds$/ do |time|
|
14
|
+
(@response_time).should >= time.to_f
|
15
|
+
end
|
16
|
+
|
17
|
+
Then /^mirage (should|should not) be running on '(.*)'$/ do |should, url|
|
18
|
+
running = begin
|
19
|
+
get(url).code.to_i.should == 200
|
20
|
+
rescue
|
21
|
+
false
|
22
|
+
end
|
23
|
+
|
24
|
+
should == "should" ? running.should == true : running.should == false
|
25
|
+
end
|
26
|
+
|
27
|
+
Given /^Mirage (is|is not) running$/ do |running|
|
28
|
+
if running == 'is'
|
29
|
+
start_mirage_in_scratch_dir unless Mirage.running?
|
30
|
+
else
|
31
|
+
Mirage.stop :all
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
Then /^the usage information should be displayed$/ do
|
36
|
+
@usage.each_line { |line| @commandline_output.should include(line) }
|
37
|
+
end
|
38
|
+
|
39
|
+
Then /^I should see '(.*?)' on the command line$/ do |content|
|
40
|
+
@commandline_output.should include(content)
|
41
|
+
end
|
42
|
+
|
43
|
+
Then /^'(.*)' should exist$/ do |path|
|
44
|
+
File.exists?("#{SCRATCH}/#{path}").should == true
|
45
|
+
end
|
46
|
+
|
47
|
+
Then /^mirage.log should contain '(.*)'$/ do |content|
|
48
|
+
log_file_content = @mirage_log_file.readlines.to_s
|
49
|
+
fail("#{content} not found in mirage.log: #{log_file_content}") unless log_file_content.index(content)
|
50
|
+
end
|
51
|
+
|
52
|
+
Given /^I goto '(.*)'$/ do |url|
|
53
|
+
@page = Mechanize.new.get url
|
54
|
+
end
|
55
|
+
|
56
|
+
Then /^I should see '(.*)'$/ do |text|
|
57
|
+
@page.body.index(text).should_not == nil
|
58
|
+
end
|
59
|
+
|
60
|
+
When /^the response '([^']*)' should be '([^']*)'$/ do |header, value|
|
61
|
+
@response.response[header].should include(value)
|
62
|
+
end
|
63
|
+
|
64
|
+
Then /^request data should have been retrieved$/ do
|
65
|
+
puts @response.body
|
66
|
+
request_data = JSON.parse(@response.body)
|
67
|
+
request_data.include?('parameters').should == true
|
68
|
+
request_data.include?('headers').should == true
|
69
|
+
request_data.include?('body').should == true
|
70
|
+
request_data.include?('request_url').should == true
|
71
|
+
end
|
72
|
+
|
73
|
+
Then(/^the template (request|response) specification should have the following set:$/) do |spec, table|
|
74
|
+
template_json = JSON.parse(get("http://localhost:7001/templates/#{JSON.parse(@response.body)['id']}").body)
|
75
|
+
request_specification = template_json[spec]
|
76
|
+
request_specification.size.should==table.hashes.size
|
77
|
+
table.hashes.each do |hash|
|
78
|
+
default = request_specification[hash['Setting'].downcase.gsub(' ', '_')]
|
79
|
+
case required_default = hash['Default']
|
80
|
+
when 'none'
|
81
|
+
case default
|
82
|
+
when Array
|
83
|
+
default.should == []
|
84
|
+
when Hash
|
85
|
+
default.should == {}
|
86
|
+
else
|
87
|
+
default.should == ""
|
88
|
+
|
89
|
+
end
|
90
|
+
else
|
91
|
+
default.to_s.downcase.should == required_default.downcase
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
Then(/^the following json should be returned:$/) do |text|
|
97
|
+
JSON.parse(text).should == JSON.parse(@response.body)
|
98
|
+
end
|
99
|
+
|
100
|
+
When(/^the content-type should be '(.*)'$/) do |content_type|
|
101
|
+
@response.content_type.should == content_type
|
102
|
+
end
|
@@ -16,6 +16,17 @@ module CommandLine
|
|
16
16
|
def normalise text
|
17
17
|
text.gsub(/[\n]/, ' ').gsub(/\s+/, ' ').strip
|
18
18
|
end
|
19
|
+
|
20
|
+
def write_to_file file_path, content
|
21
|
+
file_path = "#{SCRATCH}/#{file_path}" unless file_path =~ /^\//
|
22
|
+
|
23
|
+
FileUtils.rm_rf(file_path) if File.exists?(file_path)
|
24
|
+
FileUtils.mkdir_p(File.dirname(file_path))
|
25
|
+
|
26
|
+
File.open("#{file_path}", 'w') do |file|
|
27
|
+
file.write(content)
|
28
|
+
end
|
29
|
+
end
|
19
30
|
end
|
20
31
|
|
21
32
|
World CommandLine
|
data/features/support/env.rb
CHANGED
@@ -1,14 +1,10 @@
|
|
1
1
|
ROOT_DIR = File.expand_path("#{File.dirname(__FILE__)}/../..")
|
2
2
|
SOURCE_PATH = "#{ROOT_DIR}/lib"
|
3
|
-
|
3
|
+
Bundler.require
|
4
4
|
|
5
5
|
$LOAD_PATH.unshift(SOURCE_PATH)
|
6
|
-
require '
|
6
|
+
require 'base64'
|
7
7
|
require 'mirage/client'
|
8
|
-
require 'cucumber'
|
9
|
-
require 'rspec'
|
10
|
-
require 'mechanize'
|
11
|
-
require 'childprocess'
|
12
8
|
|
13
9
|
SCRATCH = "#{ROOT_DIR}/scratch"
|
14
10
|
RUBY_CMD = ChildProcess.jruby? ? 'jruby' : 'ruby'
|
data/features/support/hooks.rb
CHANGED
data/features/support/mirage.rb
CHANGED
data/features/support/web.rb
CHANGED
@@ -1,69 +1,20 @@
|
|
1
|
-
require '
|
2
|
-
require 'uri'
|
1
|
+
require 'httparty'
|
3
2
|
module Mirage
|
4
3
|
module Web
|
5
|
-
|
6
|
-
|
7
|
-
def initialize response
|
8
|
-
@response = response
|
9
|
-
end
|
10
|
-
|
11
|
-
def save_as path
|
12
|
-
@response.save_as(path)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def http_put url, entity, options={}
|
17
|
-
if options[:parameters]
|
18
|
-
url << "?#{options[:parameters].to_a.collect{|pair|pair.join("=")}.join("&")}"
|
19
|
-
end
|
20
|
-
uri = URI.parse(url)
|
21
|
-
request = Net::HTTP::Put.new(uri.request_uri)
|
22
|
-
|
23
|
-
if entity.is_a? File
|
24
|
-
request.body_stream=entity
|
25
|
-
request.content_length=entity.lstat.size
|
26
|
-
else
|
27
|
-
request.body=entity
|
28
|
-
end
|
29
|
-
|
30
|
-
if options[:headers]
|
31
|
-
options[:headers].each { |field, value| request.add_field(field, value) }
|
32
|
-
end
|
33
|
-
|
34
|
-
#if options[:parameters]
|
35
|
-
# request.set_form_data options[:parameters]
|
36
|
-
#end
|
37
|
-
|
38
|
-
Net::HTTP.new(uri.host, uri.port).request(request)
|
4
|
+
def get *args
|
5
|
+
HTTParty.get(*args)
|
39
6
|
end
|
40
|
-
|
41
|
-
|
42
|
-
uri = URI.parse(url)
|
43
|
-
request = Net::HTTP::Get.new(uri.request_uri)
|
44
|
-
request.set_form_data params
|
45
|
-
headers.each { |field, value| request.add_field(field, value) }
|
46
|
-
Net::HTTP.new(uri.host, uri.port).request(request)
|
7
|
+
def put *args
|
8
|
+
HTTParty.put(*args)
|
47
9
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
request = Net::HTTP::Post.new(uri.request_uri)
|
52
|
-
|
53
|
-
params.is_a?(Hash) ? request.set_form_data(params) : request.body = params
|
54
|
-
|
55
|
-
headers.each { |field, value| request.add_field(field, value) }
|
56
|
-
Net::HTTP.new(uri.host, uri.port).request(request)
|
10
|
+
def post *args
|
11
|
+
puts "running this one"
|
12
|
+
HTTParty.post(*args)
|
57
13
|
end
|
58
|
-
|
59
|
-
|
60
|
-
uri = URI.parse(url)
|
61
|
-
request = Net::HTTP::Delete.new(uri.request_uri)
|
62
|
-
params.is_a?(Hash) ? request.set_form_data(params) : request.body = params
|
63
|
-
headers.each { |field, value| request.add_field(field, value) }
|
64
|
-
Net::HTTP.new(uri.host, uri.port).request(request)
|
14
|
+
def delete *args
|
15
|
+
HTTParty.delete(*args)
|
65
16
|
end
|
66
|
-
|
67
17
|
end
|
68
18
|
end
|
19
|
+
|
69
20
|
World(Mirage::Web)
|
@@ -102,7 +102,10 @@ Feature: Placing requirements on requests
|
|
102
102
|
And 'response.body' is base64 encoded
|
103
103
|
And the template is sent using PUT to '/templates/greeting'
|
104
104
|
|
105
|
-
When I send POST to '/responses/greeting' with
|
105
|
+
When I send POST to '/responses/greeting' with request entity
|
106
|
+
"""
|
107
|
+
{"username":"Joe Blogs"}
|
108
|
+
"""
|
106
109
|
Then 'Hello Joe' should be returned
|
107
110
|
|
108
111
|
|
@@ -6,7 +6,7 @@ module Mirage
|
|
6
6
|
method_names.each do |method_name|
|
7
7
|
method_name = method_name.to_sym
|
8
8
|
define_method method_name do |arg=nil|
|
9
|
-
return instance_variable_get("@#{method_name}".to_sym)
|
9
|
+
return instance_variable_get("@#{method_name}".to_sym) if arg.nil?
|
10
10
|
instance_variable_set("@#{method_name}".to_sym, arg)
|
11
11
|
self
|
12
12
|
end
|
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.5"
|
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 = "
|
12
|
+
s.date = "2014-01-19"
|
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
|
"features/requests/get.feature",
|
52
52
|
"features/save_and_revert.feature",
|
53
53
|
"features/step_definitions/my_steps.rb",
|
54
|
+
"features/step_definitions/observation_steps.rb",
|
54
55
|
"features/support/command_line.rb",
|
55
56
|
"features/support/env.rb",
|
56
57
|
"features/support/hooks.rb",
|
@@ -107,6 +108,9 @@ Gem::Specification.new do |s|
|
|
107
108
|
"spec/server/mock_response_spec.rb",
|
108
109
|
"spec/server/server_spec.rb",
|
109
110
|
"spec/spec_helper.rb",
|
111
|
+
"tasks/application.rake",
|
112
|
+
"tasks/packaging.rake",
|
113
|
+
"tasks/tests.rake",
|
110
114
|
"views/index.haml",
|
111
115
|
"views/response.haml"
|
112
116
|
]
|
@@ -1,32 +1,40 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Helpers::MethodBuilder do
|
4
|
-
it 'should give a builder_method builder method' do
|
5
|
-
model_class = Class.new do
|
6
|
-
extend Helpers::MethodBuilder
|
7
4
|
|
8
|
-
|
9
|
-
|
5
|
+
describe 'a builder method' do
|
6
|
+
let :model do
|
7
|
+
model_class = Class.new do
|
8
|
+
extend Helpers::MethodBuilder
|
9
|
+
|
10
|
+
builder_method :name
|
11
|
+
end
|
12
|
+
model_class.new
|
10
13
|
end
|
11
|
-
name, age = 'Joe', 25
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
it 'should set a value' do
|
16
|
+
model.name(:joe)
|
17
|
+
model.name.should == :joe
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should chain' do
|
21
|
+
model.name(:joe).should == model
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should work with booleans' do
|
25
|
+
model.name(false)
|
26
|
+
model.name.should == false
|
27
|
+
end
|
17
28
|
end
|
18
29
|
|
30
|
+
|
19
31
|
it 'should let you define more than one builder method at a time' do
|
20
32
|
model_class = Class.new do
|
21
33
|
extend Helpers::MethodBuilder
|
22
|
-
|
23
|
-
builder_methods :name, :age
|
34
|
+
builder_methods :foo, :bar
|
24
35
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
person.name(name).age(age)
|
29
|
-
person.name.should == name
|
30
|
-
person.age.should == age
|
36
|
+
model = model_class.new
|
37
|
+
model.respond_to?(:foo).should be_true
|
38
|
+
model.respond_to?(:bar).should be_true
|
31
39
|
end
|
32
40
|
end
|
data/spec/client/runner_spec.rb
CHANGED
@@ -131,7 +131,7 @@ describe Mirage do
|
|
131
131
|
runner.stub(:mirage_process_ids).with([7001]).and_return({})
|
132
132
|
|
133
133
|
Mirage::Runner.should_receive(:new).and_return(runner)
|
134
|
-
expect { runner.invoke(:stop, [], options) }.not_to raise_error
|
134
|
+
expect { runner.invoke(:stop, [], options) }.not_to raise_error
|
135
135
|
end
|
136
136
|
|
137
137
|
end
|
@@ -67,7 +67,7 @@ describe Mirage::Template do
|
|
67
67
|
|
68
68
|
it 'should raise an error if the template is not found' do
|
69
69
|
template_url = 'url'
|
70
|
-
response =
|
70
|
+
response = double(code: 404)
|
71
71
|
Template.should_receive(:backedup_get).with(template_url, :format => :json).and_return response
|
72
72
|
expect{Template.get(template_url)}.to raise_error Mirage::TemplateNotFound
|
73
73
|
end
|
@@ -3,7 +3,6 @@ require 'binary_data_checker'
|
|
3
3
|
|
4
4
|
|
5
5
|
describe Mirage::BinaryDataChecker do
|
6
|
-
BinaryDataChecker = Mirage::BinaryDataChecker
|
7
6
|
include_context :resources
|
8
7
|
it 'should find binary data' do
|
9
8
|
BinaryDataChecker.contains_binary_data?(File.read("#{resources_dir}/binary.file")).should == true
|
@@ -4,9 +4,7 @@ require 'extensions/hash'
|
|
4
4
|
require 'mock_response'
|
5
5
|
|
6
6
|
describe Mirage::MockResponse do
|
7
|
-
|
8
|
-
ServerResponseNotFound = Mirage::ServerResponseNotFound
|
9
|
-
BinaryDataChecker = Mirage::BinaryDataChecker
|
7
|
+
|
10
8
|
before :each do
|
11
9
|
MockResponse.delete_all
|
12
10
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
task :clean do |task|
|
2
|
+
if system "gem list -i mirage"
|
3
|
+
puts "cleaning"
|
4
|
+
system "gem uninstall -x mirage"
|
5
|
+
end
|
6
|
+
Dir['*.gem'].each { |gem| FileUtils.rm_f(gem) }
|
7
|
+
task.reenable
|
8
|
+
end
|
9
|
+
|
10
|
+
Jeweler::Tasks.new do |gem|
|
11
|
+
gem.name = "mirage"
|
12
|
+
gem.homepage = "https://github.com/lashd/mirage"
|
13
|
+
gem.license = "MIT"
|
14
|
+
gem.summary = "Mirage is a easy mock server for testing your applications"
|
15
|
+
gem.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
|
+
gem.authors = ["Leon Davis"]
|
17
|
+
gem.executables = ['mirage']
|
18
|
+
gem.post_install_message = %{
|
19
|
+
===============================================================================
|
20
|
+
Mirage v3:
|
21
|
+
|
22
|
+
Mirage has just gone up a major version from 2 to 3. If you're project uses
|
23
|
+
a previous version take a look at https://github.com/lashd/mirage to see
|
24
|
+
what's changed
|
25
|
+
===============================================================================
|
26
|
+
}
|
27
|
+
end
|
28
|
+
Jeweler::RubygemsDotOrgTasks.new
|
data/tasks/tests.rake
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
task :specs
|
2
|
+
|
3
|
+
%w(client server).each do |type|
|
4
|
+
public_task_name = "#{type}_specs"
|
5
|
+
private_task_name = "_#{public_task_name}"
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new(private_task_name) do |task|
|
8
|
+
task.pattern = "spec/#{type}/**/*_spec.rb"
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "specs for: #{type}"
|
12
|
+
task public_task_name do
|
13
|
+
ENV['coverage'] = type
|
14
|
+
Rake::Task[private_task_name].invoke
|
15
|
+
end
|
16
|
+
|
17
|
+
Rake::Task["specs"].prerequisites << public_task_name
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
require 'cucumber'
|
22
|
+
require 'cucumber/rake/task'
|
23
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
24
|
+
t.cucumber_opts = "mode=regression features --format pretty"
|
25
|
+
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.5
|
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:
|
12
|
+
date: 2014-01-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
@@ -280,6 +280,7 @@ files:
|
|
280
280
|
- features/requests/get.feature
|
281
281
|
- features/save_and_revert.feature
|
282
282
|
- features/step_definitions/my_steps.rb
|
283
|
+
- features/step_definitions/observation_steps.rb
|
283
284
|
- features/support/command_line.rb
|
284
285
|
- features/support/env.rb
|
285
286
|
- features/support/hooks.rb
|
@@ -336,6 +337,9 @@ files:
|
|
336
337
|
- spec/server/mock_response_spec.rb
|
337
338
|
- spec/server/server_spec.rb
|
338
339
|
- spec/spec_helper.rb
|
340
|
+
- tasks/application.rake
|
341
|
+
- tasks/packaging.rake
|
342
|
+
- tasks/tests.rake
|
339
343
|
- views/index.haml
|
340
344
|
- views/response.haml
|
341
345
|
homepage: https://github.com/lashd/mirage
|
@@ -368,7 +372,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
368
372
|
version: '0'
|
369
373
|
segments:
|
370
374
|
- 0
|
371
|
-
hash: -
|
375
|
+
hash: -158737056239506774
|
372
376
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
373
377
|
none: false
|
374
378
|
requirements:
|