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 CHANGED
@@ -11,9 +11,9 @@ gem 'hashie'
11
11
 
12
12
  group :test do
13
13
  gem 'cucumber'
14
- gem 'rspec'
14
+ gem 'rspec', require: 'rspec/core/rake_task'
15
15
  gem 'rack-test'
16
- gem 'simplecov'
16
+ gem 'simplecov', require: false
17
17
  end
18
18
 
19
19
  group :development do
data/Rakefile CHANGED
@@ -1,81 +1,10 @@
1
- $LOAD_PATH.unshift('lib')
2
- require 'rubygems'
3
- require 'bundler'
1
+ require 'bundler/setup'
4
2
 
5
- begin
6
- Bundler.setup(:default, :development)
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
- task :stop do
78
- `RACK_ENV='development' && ruby ./bin/mirage stop`
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.4
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 gems are required to run the Mirage client test code:
6
+ Given the following require statements are needed:
7
7
  """
8
8
  require 'rubygems'
9
9
  require 'rspec/expectations'
@@ -18,7 +18,7 @@ Feature: Template Models
18
18
 
19
19
 
20
20
  Background:
21
- Given the following gems are required to run the Mirage client test code:
21
+ Given the following require statements are needed:
22
22
  """
23
23
  require 'rubygems'
24
24
  require 'mirage/client'
@@ -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 gems are required to run the Mirage client test code:
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 gems are required to run the Mirage client test code:
6
+ Given the following require statements are needed:
7
7
  """
8
8
  require 'rubygems'
9
9
  require 'rspec/expectations'
@@ -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 gems are required to run the Mirage client test code:
10
+ Given the following require statements are needed:
11
11
  """
12
12
  require 'rubygems'
13
13
  require 'rspec/expectations'
@@ -5,7 +5,7 @@ Feature: How to check if Mirage is running
5
5
 
6
6
 
7
7
  Background:
8
- Given the following gems are required to run the Mirage client test code:
8
+ Given the following require statements are needed:
9
9
  """
10
10
  require 'rubygems'
11
11
  require 'rspec/expectations'
@@ -4,7 +4,7 @@ Feature: Creating snapshots
4
4
 
5
5
 
6
6
  Background:
7
- Given the following gems are required to run the Mirage client test code:
7
+ Given the following require statements are needed:
8
8
  """
9
9
  require 'rubygems'
10
10
  require 'rspec/expectations'
@@ -16,7 +16,7 @@ Feature: Stopping Mirage
16
16
  """
17
17
  Mirage.stop
18
18
  """
19
- Then Connection should be refused to 'http://localhost:7001'
19
+ Then mirage should not be running on 'http://localhost:7001'
20
20
 
21
21
 
22
22
  Scenario: Stopping Mirage on custom port
@@ -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
- file_path = "#{SCRATCH}/#{file_path}" unless file_path =~ /^\//
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
- then
96
- http_post(url, entity)
34
+ post(url, body: entity)
97
35
  when 'PUT'
98
- then
99
- http_put(url, entity)
36
+ put(url, body: entity)
100
37
  end
101
38
  end
102
39
 
103
- When /^(GET|PUT|POST|OPTIONS|HEAD|DELETE) is sent to '([^']*)'$/ do |method, endpoint|
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
- http_get(url)
45
+ get(url)
109
46
  when 'PUT' then
110
- http_put(url, '')
47
+ put(url, body: '')
111
48
  when 'POST' then
112
- http_post(url, '')
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
- http_delete(url)
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
- http_post(url, parameters)
74
+ post(url, query: parameters, headers: {'Content-length' => '0'})
186
75
  when 'GET' then
187
- http_get(url, parameters)
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
- @response = http_put("http://localhost:7001#{endpoint}", @response_template.to_hash.to_json, :headers => {"Content-Type" => "application/json"})
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
- $mirage.templates.put(endpoint, value)
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
@@ -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 'rubygems'
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'
@@ -1,8 +1,7 @@
1
1
  Before do
2
2
  FileUtils.mkdir_p(SCRATCH)
3
3
 
4
- $mirage = start_mirage_in_scratch_dir
5
- $mirage.templates.delete_all
4
+ mirage.templates.delete_all
6
5
 
7
6
  Dir["#{SCRATCH}/*"].each do |file|
8
7
  FileUtils.rm_rf(file) unless file == "#{SCRATCH}/mirage.log"
@@ -4,5 +4,9 @@ module Mirage
4
4
  Mirage.start
5
5
  end
6
6
  end
7
+
8
+ def mirage
9
+ @mirage ||= Mirage.running? ? Mirage::Client.new : start_mirage_in_scratch_dir
10
+ end
7
11
  end
8
- include Mirage
12
+ World Mirage
@@ -1,69 +1,20 @@
1
- require 'net/http'
2
- require 'uri'
1
+ require 'httparty'
3
2
  module Mirage
4
3
  module Web
5
- class FileResponse
6
- attr_reader :response
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
- def http_get url, params={}, headers={}
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
- def http_post url, params={}, headers={}
50
- uri = URI.parse(url)
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
- def http_delete url, params={}, headers={}
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 body '{"username":"Joe Blogs"}'
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) unless arg
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.4"
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 = "2013-11-18"
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
- builder_method :name
9
- builder_method :age
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
- person = model_class.new
14
- person.name(name).age(age)
15
- person.name.should == name
16
- person.age.should == age
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
- name, age = 'Joe', 25
26
-
27
- person = model_class.new
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
@@ -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(Mirage::ClientError)
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 = mock(code: 404)
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
- MockResponse = Mirage::MockResponse
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,7 @@
1
+ task :start do
2
+ `RACK_ENV='development' && ruby ./bin/mirage start`
3
+ end
4
+
5
+ task :stop do
6
+ `RACK_ENV='development' && ruby ./bin/mirage stop`
7
+ 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
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: 2013-11-18 00:00:00.000000000 Z
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: -2506463001240153653
375
+ hash: -158737056239506774
372
376
  required_rubygems_version: !ruby/object:Gem::Requirement
373
377
  none: false
374
378
  requirements: