mirage 2.1.2 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ gem 'childprocess'
5
5
  gem "waitforit"
6
6
 
7
7
  group :development do
8
+ gem "thin"
8
9
  gem 'rake'
9
10
  gem 'cucumber'
10
11
  gem 'rspec'
@@ -12,6 +12,7 @@ GEM
12
12
  gherkin (~> 2.7.1)
13
13
  json (>= 1.4.6)
14
14
  term-ansicolor (>= 1.0.6)
15
+ daemons (1.1.8)
15
16
  diff-lcs (1.1.3)
16
17
  domain_name (0.5.1)
17
18
  unf (~> 0.0.3)
@@ -70,6 +71,10 @@ GEM
70
71
  sinatra (~> 1.3.0)
71
72
  tilt (~> 1.3)
72
73
  term-ansicolor (1.0.7)
74
+ thin (1.4.1)
75
+ daemons (>= 1.0.9)
76
+ eventmachine (>= 0.12.6)
77
+ rack (>= 1.0.0)
73
78
  tilt (1.3.3)
74
79
  unf (0.0.4)
75
80
  unf_ext
@@ -93,4 +98,5 @@ DEPENDENCIES
93
98
  rspec
94
99
  sinatra
95
100
  sinatra-contrib
101
+ thin
96
102
  waitforit
data/HISTORY CHANGED
@@ -1,3 +1,5 @@
1
+ V2.2.1/2 - Code tidy up
2
+ V2.2.0 - Api for starting and stopping Mirage locally
1
3
  V2.1.2 - rename status_code to status
2
4
  V2.1.1 - Set response code and tidy ups
3
5
  V2.0.16 - minor typo fix for window command window title in windows
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.2
1
+ 2.2.2
data/bin/mirage CHANGED
@@ -1,68 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'rubygems'
3
- require 'childprocess'
4
- ROOT_DIR = File.dirname(__FILE__)
5
- $LOAD_PATH.unshift("#{ROOT_DIR}/../lib")
6
- $LOAD_PATH.unshift("#{ROOT_DIR}/../server")
7
3
 
4
+ $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib")
8
5
  require 'mirage/client'
9
- require 'waitforit'
10
- require 'util'
11
6
 
12
7
 
13
- include Mirage::Util
14
- RUBY_CMD = RUBY_PLATFORM == 'java' ? 'jruby' : 'ruby'
15
-
16
- def start_mirage(args)
17
- puts "Starting Mirage"
18
-
19
- if windows?
20
- command = ["cmd", "/C", "start", "mirage server", RUBY_CMD, "#{File.dirname(__FILE__)}/../mirage_server.rb"]
21
- else
22
- command = [RUBY_CMD, "#{File.dirname(__FILE__)}/../mirage_server.rb"]
23
- end
24
- ChildProcess.build(*(command.concat(args))).start
25
- Mirage::Client.new "http://localhost:#{parse_options(ARGV)[:port]}/mirage"
26
- end
27
-
28
-
29
- def mirage_process_ids
30
- if windows?
31
- [`tasklist /V | findstr "mirage\\ server"`.split(' ')[1]].compact
32
- else
33
- ["Mirage Server", 'mirage_server'].collect do |process_name|
34
- `ps aux | grep "#{process_name}" | grep -v grep`.split(' ')[1]
35
- end.find_all { |process_id| process_id != $$.to_s }.compact
36
- end
37
- end
38
-
39
- def stop_mirage
40
- mirage_process_ids.each { |process_id| windows? ? `taskkill /F /T /PID #{process_id}` : `kill -9 #{process_id}` }
41
- wait_until{ mirage_process_ids.size == 0 }
42
- end
43
8
 
44
9
  if ARGV.include?('start')
45
-
46
- unless mirage_process_ids.empty?
47
- puts "Mirage is already running"
48
- exit 1
49
- end
50
-
51
- mirage_client = start_mirage(ARGV)
52
- wait_until :timeout_after => 30.seconds do
53
- mirage_client.running?
54
- end
55
-
56
- begin
57
- mirage_client.prime
58
- rescue Mirage::InternalServerException => e
59
- puts "WARN: #{e.message}"
60
- end
61
-
10
+ Mirage.start ARGV
62
11
  elsif ARGV.include?('stop')
63
- puts "Stopping Mirage"
64
- stop_mirage
12
+ Mirage.stop
65
13
  else
66
- parse_options ['--help']
14
+ Mirage::CLI.parse_options ['--help']
67
15
  exit 1
68
16
  end
@@ -0,0 +1,48 @@
1
+ @command_line
2
+ Feature: The Mirage client provides a programmatic interface equivalent to the command line interface. This gives an
3
+ easy method for bringing a local instance of Mirage in situ inside a test suite.
4
+
5
+ The client can only be used to stop Mirage if it is was used to start the running instance.
6
+
7
+ Background:
8
+ Given the following gems are required to run the Mirage client test code:
9
+ """
10
+ require 'rubygems'
11
+ require 'rspec'
12
+ require 'mirage/client'
13
+ """
14
+
15
+
16
+ Scenario: Starting mirage with defaults
17
+ Given Mirage is not running
18
+ When I run
19
+ """
20
+ Mirage.start
21
+ """
22
+ Then mirage should be running on 'http://localhost:7001/mirage'
23
+
24
+
25
+ Scenario: Stopping Mirage
26
+ Given Mirage is not running
27
+ When I run
28
+ """
29
+ Mirage.start
30
+ Mirage.stop
31
+ """
32
+ Then Connection should be refused to 'http://localhost:7001/mirage'
33
+
34
+
35
+ Scenario: Starting Mirage on a custom port
36
+ Given Mirage is not running
37
+ And the file './custom_responses_location/default_greetings.rb' contains:
38
+ """
39
+ prime do |mirage|
40
+ mirage.put('greeting', 'hello')
41
+ end
42
+ """
43
+ When I run
44
+ """
45
+ Mirage.start :port => 9001, :defaults => './custom_responses_location'
46
+ """
47
+ And I send GET to 'http://localhost:9001/mirage/responses/greeting'
48
+ Then 'hello' should be returned
@@ -114,12 +114,16 @@ Feature: the Mirage client provides methods for setting responses and loading de
114
114
  """
115
115
 
116
116
  Scenario: Setting a file as a response
117
- Given I run
117
+ Given the file 'test_file.txt' contains:
118
+ """
119
+ test content
120
+ """
121
+ And I run
118
122
  """
119
- Mirage::Client.new.put('download', File.open('README.md'))
123
+ Mirage::Client.new.put('download', File.open('test_file.txt'))
120
124
  """
121
125
  When I send GET to 'http://localhost:7001/mirage/responses/download'
122
- Then the response should be the same as the content of 'README.md'
126
+ Then the response should be the same as the content of 'test_file.txt'
123
127
 
124
128
  Scenario: Setting a response status code
125
129
  Given I run
@@ -13,11 +13,15 @@ Feature: If you want to see the content of a particular response without trigger
13
13
 
14
14
 
15
15
  Scenario: Peeking a file based response
16
- Given I send PUT to 'http://localhost:7001/mirage/templates/some/location/download' with file: README.md and headers:
16
+ Given the file 'test_file.txt' contains:
17
+ """
18
+ test content
19
+ """
20
+ And I send PUT to 'http://localhost:7001/mirage/templates/some/location/download' with file: test_file.txt and headers:
17
21
  | X-mirage-file | true |
18
22
 
19
23
  When I send GET to 'http://localhost:7001/mirage/templates/1'
20
- Then the response should be the same as the content of 'README.md'
24
+ Then the response should be the same as the content of 'test_file.txt'
21
25
 
22
26
 
23
27
  Scenario: Peeking a response that does not exist
@@ -36,7 +36,7 @@ Given /^Mirage (is|is not) running$/ do |running|
36
36
  if running == 'is'
37
37
  start_mirage unless $mirage.running?
38
38
  else
39
- stop_mirage if $mirage.running?
39
+ stop_mirage if $mirage.running?
40
40
  end
41
41
  end
42
42
 
@@ -54,9 +54,10 @@ Given /^the file '(.*)' contains:$/ do |file_path, content|
54
54
  FileUtils.rm_rf(file_path) if File.exists?(file_path)
55
55
  FileUtils.mkdir_p(File.dirname(file_path))
56
56
 
57
- file = File.new("#{file_path}", 'w')
58
- file.write(content)
59
- file.close
57
+ File.open("#{file_path}", 'w') do |file|
58
+ file.write(content)
59
+ end
60
+
60
61
  end
61
62
 
62
63
  Then /^the usage information should be displayed$/ do
@@ -64,11 +65,13 @@ Then /^the usage information should be displayed$/ do
64
65
  end
65
66
  Given /^usage information:$/ do |table|
66
67
  @usage = table.raw.flatten.collect { |line| normalise(line) }
67
- end
68
+ end
68
69
 
69
70
  Then /^I run$/ do |text|
70
71
  text.gsub!("\"", "\\\\\"")
71
- raise "run failed" unless system "#{RUBY_CMD} -e \"#{@code_snippet}\n#{text}\""
72
+ Dir.chdir SCRATCH do
73
+ raise "run failed" unless system "#{RUBY_CMD} -e \"#{@code_snippet}\n#{text}\""
74
+ end
72
75
  end
73
76
 
74
77
  Given /^the following gems are required to run the Mirage client test code:$/ do |text|
@@ -87,7 +90,7 @@ When /^I send (POST|PUT) to '(http:\/\/localhost:7001\/mirage\/(.*?))' with requ
87
90
  end
88
91
  end
89
92
 
90
- When /^I send (GET|PUT|POST|OPTIONS|HEAD|DELETE) to '(http:\/\/localhost:7001\/mirage([^']*))'$/ do |method, url, endpoint|
93
+ When /^I send (GET|PUT|POST|OPTIONS|HEAD|DELETE) to '(http:\/\/localhost:\d{4}\/mirage([^']*))'$/ do |method, url, endpoint|
91
94
  start_time = Time.now
92
95
  @response = case method
93
96
  when 'GET' then
@@ -174,7 +177,10 @@ Given /^I send PUT to '(http:\/\/localhost:7001\/mirage\/(.*?))' with file: ([^'
174
177
  parameter, value = row[0], row[1]
175
178
  headers[parameter]=value
176
179
  end
177
- http_put(url, File.new(path), headers)
180
+
181
+ Dir.chdir SCRATCH do
182
+ http_put(url, File.new(path), headers)
183
+ end
178
184
  end
179
185
 
180
186
  When /^the response '([^']*)' should be '([^']*)'$/ do |header, value|
@@ -182,5 +188,7 @@ When /^the response '([^']*)' should be '([^']*)'$/ do |header, value|
182
188
  end
183
189
 
184
190
  Then /^the response should be the same as the content of '([^']*)'$/ do |path|
185
- @response.body.should == File.read(path)
191
+ Dir.chdir SCRATCH do
192
+ @response.body.should == File.read(path)
193
+ end
186
194
  end
@@ -2,7 +2,6 @@ $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../../lib")
2
2
  $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../../server")
3
3
  require 'rubygems'
4
4
  require 'mirage/client'
5
- require 'util'
6
5
  require 'cucumber'
7
6
  require 'rspec'
8
7
  require 'mechanize'
@@ -10,7 +9,14 @@ require 'childprocess'
10
9
 
11
10
  ENV['RUBYOPT'] =''
12
11
 
13
- include Mirage::Util
12
+ module OsSupport
13
+ def windows?
14
+ ENV['OS'] == 'Windows_NT'
15
+ end
16
+ end
17
+ World OsSupport
18
+ include OsSupport
19
+
14
20
  SCRATCH = './scratch'
15
21
  RUBY_CMD = RUBY_PLATFORM == 'JAVA' ? 'jruby' : 'ruby'
16
22
 
@@ -23,6 +29,8 @@ else
23
29
  MIRAGE_CMD = "#{RUBY_CMD} ../bin/mirage"
24
30
  end
25
31
 
32
+
33
+
26
34
  module CommandLine
27
35
  COMAND_LINE_OUTPUT_PATH = "#{File.dirname(__FILE__)}/../../#{SCRATCH}/commandline_output.txt"
28
36
  module Windows
@@ -66,8 +74,6 @@ end
66
74
 
67
75
  module Mirage
68
76
  module Runner
69
- include Mirage::Util
70
-
71
77
  def stop_mirage
72
78
  system "cd #{SCRATCH} && #{MIRAGE_CMD} stop"
73
79
  end
@@ -92,8 +98,6 @@ end
92
98
 
93
99
  module IntelliJ
94
100
  include CommandLine
95
- include Mirage::Util
96
-
97
101
  def run command
98
102
  execute "#{RUBY_CMD} #{command}"
99
103
  end
@@ -0,0 +1,69 @@
1
+ module Mirage
2
+ class CLI
3
+ RUBY_CMD = RUBY_PLATFORM == 'java' ? 'jruby' : 'ruby'
4
+ class << self
5
+
6
+
7
+ def parse_options args
8
+ options = {:port => 7001, :defaults => 'responses', :root_directory => '.'}
9
+
10
+ opt_parser = OptionParser.new do |opts|
11
+ opts.banner = "Usage: mirage start|stop [options]"
12
+ opts.on("-p", "--port PORT", "the port to start Mirage on") do |port|
13
+ options[:port] = port.to_i
14
+ end
15
+
16
+ opts.on("-d", "--defaults DIR", "location to load default responses from") do |directory|
17
+ options[:defaults] = directory
18
+ end
19
+
20
+ opts.on('--debug', 'run in debug mode') do
21
+ options[:debug] = true
22
+ end
23
+ end
24
+ opt_parser.parse args
25
+
26
+ options
27
+ rescue
28
+ puts opt_parser
29
+ exit 1
30
+ end
31
+
32
+ def run args
33
+ unless mirage_process_ids.empty?
34
+ puts "Mirage is already running"
35
+ exit 1
36
+ end
37
+
38
+ mirage_server_file = "#{File.dirname(__FILE__)}/../../mirage_server.rb"
39
+ if windows?
40
+ command = ["cmd", "/C", "start", "mirage server", RUBY_CMD, mirage_server_file]
41
+ else
42
+ command = [RUBY_CMD, mirage_server_file]
43
+ end
44
+
45
+ ChildProcess.build(*(command.concat(args))).start
46
+ end
47
+
48
+ def stop
49
+ mirage_process_ids.each { |process_id| windows? ? `taskkill /F /T /PID #{process_id}` : `kill -9 #{process_id}` }
50
+ wait_until { mirage_process_ids.size == 0 }
51
+ end
52
+
53
+ private
54
+ def mirage_process_ids
55
+ if windows?
56
+ [`tasklist /V | findstr "mirage\\ server"`.split(' ')[1]].compact
57
+ else
58
+ ["Mirage Server", 'mirage_server'].collect do |process_name|
59
+ `ps aux | grep "#{process_name}" | grep -v grep`.split(' ')[1]
60
+ end.find_all { |process_id| process_id != $$.to_s }.compact
61
+ end
62
+ end
63
+
64
+ def windows?
65
+ ENV['OS'] == 'Windows_NT'
66
+ end
67
+ end
68
+ end
69
+ end
@@ -1,10 +1,47 @@
1
1
  $LOAD_PATH.unshift "#{File.dirname(__FILE__)}"
2
2
  require 'uri'
3
+ require 'waitforit'
4
+ require 'childprocess'
3
5
  require 'client/web'
6
+ require 'cli'
4
7
  require 'ostruct'
8
+ require 'optparse'
5
9
 
6
10
  module Mirage
7
11
 
12
+ class << self
13
+
14
+ def start args={}
15
+ puts "Starting Mirage"
16
+ args = convert_to_command_line_argument_array(args) if args.is_a? Hash
17
+
18
+ Mirage::CLI.run args
19
+ mirage_client = Mirage::Client.new "http://localhost:#{Mirage::CLI.parse_options(args)[:port]}/mirage"
20
+ wait_until(:timeout_after => 30.seconds) { mirage_client.running? }
21
+
22
+ begin
23
+ mirage_client.prime
24
+ rescue Mirage::InternalServerException => e
25
+ puts "WARN: #{e.message}"
26
+ end
27
+ mirage_client
28
+ end
29
+
30
+ def stop
31
+ puts "Stopping Mirage"
32
+ Mirage::CLI.stop
33
+ end
34
+
35
+ private
36
+ def convert_to_command_line_argument_array(args)
37
+ command_line_arguments = {}
38
+ args.each do |key, value|
39
+ command_line_arguments["--#{key}"] = "#{value}"
40
+ end
41
+ command_line_arguments.to_a.flatten
42
+ end
43
+ end
44
+
8
45
  class MirageError < ::Exception
9
46
  attr_reader :code
10
47
 
@@ -13,11 +50,12 @@ module Mirage
13
50
  @code = message, code
14
51
  end
15
52
  end
16
-
53
+
17
54
  class Response < OpenStruct
18
55
 
19
56
  attr_accessor :content_type
20
57
  attr_reader :value
58
+
21
59
  def initialize response
22
60
  @content_type = 'text/plain'
23
61
  @value = response
@@ -27,7 +65,7 @@ module Mirage
27
65
  def headers
28
66
  headers = {}
29
67
 
30
- @table.each{|header, value| headers["X-mirage-#{header.to_s.gsub('_', '-')}"] = value}
68
+ @table.each { |header, value| headers["X-mirage-#{header.to_s.gsub('_', '-')}"] = value }
31
69
  headers['Content-Type']=@content_type
32
70
  headers['X-mirage-file'] = 'true' if @response.kind_of?(IO)
33
71
 
@@ -69,10 +107,10 @@ module Mirage
69
107
  # end
70
108
  def put endpoint, response_value, &block
71
109
  response = Response.new response_value
72
-
110
+
73
111
  yield response if block_given?
74
112
 
75
- build_response(http_put("#{@url}/templates/#{endpoint}",response.value, response.headers))
113
+ build_response(http_put("#{@url}/templates/#{endpoint}", response.value, response.headers))
76
114
  end
77
115
 
78
116
  # Use to look at what a response contains without actually triggering it.
@@ -85,7 +123,7 @@ module Mirage
85
123
  when Mirage::Web::FileResponse then
86
124
  return response.response.body
87
125
  end
88
-
126
+
89
127
  end
90
128
 
91
129
  # Clear Content from Mirage
@@ -98,7 +136,7 @@ module Mirage
98
136
  # Client.new.clear(:requests) # Clear all tracked request information
99
137
  # Client.new.clear(:request => response_id) # Clear the tracked request for a given response id
100
138
  def clear thing=nil
101
-
139
+
102
140
  case thing
103
141
  when :requests
104
142
  http_delete("#{@url}/requests")
@@ -107,10 +145,11 @@ module Mirage
107
145
  when Hash then
108
146
  puts "deleteing request #{thing[:request]}"
109
147
  http_delete("#{@url}/requests/#{thing[:request]}") if thing[:request]
110
- else NilClass
148
+ else
149
+ NilClass
111
150
  http_delete("#{@url}/templates")
112
151
  end
113
-
152
+
114
153
  end
115
154
 
116
155
 
@@ -125,14 +164,14 @@ module Mirage
125
164
 
126
165
  # Save the state of the Mirage server so that it can be reverted back to that exact state at a later time.
127
166
  def save
128
- http_put("#{@url}/backup",'').code == 200
167
+ http_put("#{@url}/backup", '').code == 200
129
168
  end
130
169
 
131
170
 
132
171
  # Revert the state of Mirage back to the state that was last saved
133
172
  # If there is no snapshot to rollback to, nothing happens
134
173
  def revert
135
- http_put("#{@url}",'').code == 200
174
+ http_put("#{@url}", '').code == 200
136
175
  end
137
176
 
138
177
 
@@ -148,7 +187,7 @@ module Mirage
148
187
  # Clear down the Mirage Server and load any defaults that are in Mirages default responses directory.
149
188
  def prime
150
189
  puts "#{@url}/defaults"
151
- build_response(http_put("#{@url}/defaults",''))
190
+ build_response(http_put("#{@url}/defaults", ''))
152
191
  end
153
192
 
154
193
  private
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "mirage"
8
- s.version = "2.1.2"
8
+ s.version = "2.2.2"
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 = "2012-04-29"
12
+ s.date = "2012-07-10"
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 = [
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
24
24
  "VERSION",
25
25
  "bin/mirage",
26
26
  "features/client/clear.feature",
27
+ "features/client/command_line_interface.feature",
27
28
  "features/client/mirage_client.feature",
28
29
  "features/client/put.feature",
29
30
  "features/client/request.feature",
@@ -46,15 +47,16 @@ Gem::Specification.new do |s|
46
47
  "features/step_definitions/my_steps.rb",
47
48
  "features/support/env.rb",
48
49
  "full_build.sh",
50
+ "lib/mirage/cli.rb",
49
51
  "lib/mirage/client.rb",
50
52
  "lib/mirage/client/web.rb",
51
53
  "mirage.gemspec",
52
54
  "mirage_server.rb",
53
55
  "rakefile",
56
+ "responses/default_responses.rb",
54
57
  "server/extensions/hash.rb",
55
58
  "server/extensions/object.rb",
56
59
  "server/mock_response.rb",
57
- "server/util.rb",
58
60
  "test.rb",
59
61
  "views/index.erb"
60
62
  ]
@@ -72,6 +74,7 @@ Gem::Specification.new do |s|
72
74
  s.add_runtime_dependency(%q<sinatra>, [">= 0"])
73
75
  s.add_runtime_dependency(%q<childprocess>, [">= 0"])
74
76
  s.add_runtime_dependency(%q<waitforit>, [">= 0"])
77
+ s.add_development_dependency(%q<thin>, [">= 0"])
75
78
  s.add_development_dependency(%q<rake>, [">= 0"])
76
79
  s.add_development_dependency(%q<cucumber>, [">= 0"])
77
80
  s.add_development_dependency(%q<rspec>, [">= 0"])
@@ -84,6 +87,7 @@ Gem::Specification.new do |s|
84
87
  s.add_dependency(%q<sinatra>, [">= 0"])
85
88
  s.add_dependency(%q<childprocess>, [">= 0"])
86
89
  s.add_dependency(%q<waitforit>, [">= 0"])
90
+ s.add_dependency(%q<thin>, [">= 0"])
87
91
  s.add_dependency(%q<rake>, [">= 0"])
88
92
  s.add_dependency(%q<cucumber>, [">= 0"])
89
93
  s.add_dependency(%q<rspec>, [">= 0"])
@@ -97,6 +101,7 @@ Gem::Specification.new do |s|
97
101
  s.add_dependency(%q<sinatra>, [">= 0"])
98
102
  s.add_dependency(%q<childprocess>, [">= 0"])
99
103
  s.add_dependency(%q<waitforit>, [">= 0"])
104
+ s.add_dependency(%q<thin>, [">= 0"])
100
105
  s.add_dependency(%q<rake>, [">= 0"])
101
106
  s.add_dependency(%q<cucumber>, [">= 0"])
102
107
  s.add_dependency(%q<rspec>, [">= 0"])
@@ -9,19 +9,16 @@ require 'sinatra/base'
9
9
  require 'extensions/object'
10
10
  require 'extensions/hash'
11
11
  require 'mock_response'
12
- require 'util'
13
12
 
14
13
  require 'mirage/client'
15
14
 
16
- include Mirage::Util
17
-
18
15
  module Mirage
19
16
 
20
17
  class Server < Sinatra::Base
21
18
 
22
19
  configure do
23
- options = parse_options(ARGV)
24
- set :defaults_directory, options[:defaults_directory]
20
+ options = Mirage::CLI.parse_options(ARGV)
21
+ set :defaults, options[:defaults]
25
22
  set :port, options[:port]
26
23
  set :show_exceptions, false
27
24
  set :logging, true
@@ -113,7 +110,7 @@ module Mirage
113
110
  put '/mirage/defaults' do
114
111
  MockResponse.delete_all
115
112
 
116
- Dir["#{settings.defaults_directory}/**/*.rb"].each do |default|
113
+ Dir["#{settings.defaults}/**/*.rb"].each do |default|
117
114
  begin
118
115
  eval File.read(default)
119
116
  rescue Exception => e
File without changes
data/test.rb CHANGED
@@ -1 +1,6 @@
1
- a change another
1
+ require 'rubygems'
2
+ require './lib/mirage/client'
3
+
4
+ client = Mirage.start :port => 9001
5
+
6
+ client.stop
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.1.2
4
+ version: 2.2.2
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: 2012-04-29 00:00:00.000000000Z
12
+ date: 2012-07-10 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
- requirement: &16709080 !ruby/object:Gem::Requirement
16
+ requirement: &22006800 !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: *16709080
24
+ version_requirements: *22006800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: childprocess
27
- requirement: &16708560 !ruby/object:Gem::Requirement
27
+ requirement: &22006260 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *16708560
35
+ version_requirements: *22006260
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: waitforit
38
- requirement: &16708060 !ruby/object:Gem::Requirement
38
+ requirement: &22005560 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,21 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *16708060
46
+ version_requirements: *22005560
47
+ - !ruby/object:Gem::Dependency
48
+ name: thin
49
+ requirement: &22004900 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *22004900
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: rake
49
- requirement: &16673860 !ruby/object:Gem::Requirement
60
+ requirement: &22004220 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,10 +65,10 @@ dependencies:
54
65
  version: '0'
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *16673860
68
+ version_requirements: *22004220
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: cucumber
60
- requirement: &16673060 !ruby/object:Gem::Requirement
71
+ requirement: &22003340 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - ! '>='
@@ -65,10 +76,10 @@ dependencies:
65
76
  version: '0'
66
77
  type: :development
67
78
  prerelease: false
68
- version_requirements: *16673060
79
+ version_requirements: *22003340
69
80
  - !ruby/object:Gem::Dependency
70
81
  name: rspec
71
- requirement: &16672340 !ruby/object:Gem::Requirement
82
+ requirement: &22002640 !ruby/object:Gem::Requirement
72
83
  none: false
73
84
  requirements:
74
85
  - - ! '>='
@@ -76,10 +87,10 @@ dependencies:
76
87
  version: '0'
77
88
  type: :development
78
89
  prerelease: false
79
- version_requirements: *16672340
90
+ version_requirements: *22002640
80
91
  - !ruby/object:Gem::Dependency
81
92
  name: jeweler
82
- requirement: &16671580 !ruby/object:Gem::Requirement
93
+ requirement: &22001680 !ruby/object:Gem::Requirement
83
94
  none: false
84
95
  requirements:
85
96
  - - ! '>='
@@ -87,10 +98,10 @@ dependencies:
87
98
  version: '0'
88
99
  type: :development
89
100
  prerelease: false
90
- version_requirements: *16671580
101
+ version_requirements: *22001680
91
102
  - !ruby/object:Gem::Dependency
92
103
  name: sinatra-contrib
93
- requirement: &16670800 !ruby/object:Gem::Requirement
104
+ requirement: &22000860 !ruby/object:Gem::Requirement
94
105
  none: false
95
106
  requirements:
96
107
  - - ! '>='
@@ -98,10 +109,10 @@ dependencies:
98
109
  version: '0'
99
110
  type: :development
100
111
  prerelease: false
101
- version_requirements: *16670800
112
+ version_requirements: *22000860
102
113
  - !ruby/object:Gem::Dependency
103
114
  name: mechanize
104
- requirement: &16670040 !ruby/object:Gem::Requirement
115
+ requirement: &21998380 !ruby/object:Gem::Requirement
105
116
  none: false
106
117
  requirements:
107
118
  - - ! '>='
@@ -109,10 +120,10 @@ dependencies:
109
120
  version: '0'
110
121
  type: :development
111
122
  prerelease: false
112
- version_requirements: *16670040
123
+ version_requirements: *21998380
113
124
  - !ruby/object:Gem::Dependency
114
125
  name: nokogiri
115
- requirement: &16669340 !ruby/object:Gem::Requirement
126
+ requirement: &21997720 !ruby/object:Gem::Requirement
116
127
  none: false
117
128
  requirements:
118
129
  - - ! '>='
@@ -120,10 +131,10 @@ dependencies:
120
131
  version: '0'
121
132
  type: :development
122
133
  prerelease: false
123
- version_requirements: *16669340
134
+ version_requirements: *21997720
124
135
  - !ruby/object:Gem::Dependency
125
136
  name: jruby-openssl
126
- requirement: &16668600 !ruby/object:Gem::Requirement
137
+ requirement: &21997140 !ruby/object:Gem::Requirement
127
138
  none: false
128
139
  requirements:
129
140
  - - ! '>='
@@ -131,7 +142,7 @@ dependencies:
131
142
  version: '0'
132
143
  type: :development
133
144
  prerelease: false
134
- version_requirements: *16668600
145
+ version_requirements: *21997140
135
146
  description: Mirage aids testing of your applications by hosting mock responses so
136
147
  that your applications do not have to talk to real endpoints. Its accessible via
137
148
  HTTP and has a RESTful interface.
@@ -150,6 +161,7 @@ files:
150
161
  - VERSION
151
162
  - bin/mirage
152
163
  - features/client/clear.feature
164
+ - features/client/command_line_interface.feature
153
165
  - features/client/mirage_client.feature
154
166
  - features/client/put.feature
155
167
  - features/client/request.feature
@@ -172,15 +184,16 @@ files:
172
184
  - features/step_definitions/my_steps.rb
173
185
  - features/support/env.rb
174
186
  - full_build.sh
187
+ - lib/mirage/cli.rb
175
188
  - lib/mirage/client.rb
176
189
  - lib/mirage/client/web.rb
177
190
  - mirage.gemspec
178
191
  - mirage_server.rb
179
192
  - rakefile
193
+ - responses/default_responses.rb
180
194
  - server/extensions/hash.rb
181
195
  - server/extensions/object.rb
182
196
  - server/mock_response.rb
183
- - server/util.rb
184
197
  - test.rb
185
198
  - views/index.erb
186
199
  homepage: https://github.com/lashd/mirage
@@ -200,7 +213,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
200
213
  version: '0'
201
214
  segments:
202
215
  - 0
203
- hash: -2084322877409170050
216
+ hash: -518118911155639654
204
217
  required_rubygems_version: !ruby/object:Gem::Requirement
205
218
  none: false
206
219
  requirements:
@@ -1,38 +0,0 @@
1
- require 'optparse'
2
- module Mirage
3
- module Util
4
-
5
- def parse_options args
6
- options = {:port => 7001, :defaults_directory => 'responses', :root_directory => '.'}
7
-
8
- opt_parser = OptionParser.new do |opts|
9
- opts.banner = "Usage: mirage start|stop [options]"
10
- opts.on("-p", "--port PORT", "the port to start Mirage on") do |port|
11
- options[:port] = port.to_i
12
- end
13
-
14
- opts.on("-d", "--defaults DIR", "location to load default responses from") do |directory|
15
- options[:defaults_directory] = directory
16
- end
17
-
18
- opts.on('--debug', 'run in debug mode') do
19
- options[:debug] = true
20
- end
21
- end
22
-
23
- begin
24
- opt_parser.parse args
25
- rescue
26
- puts opt_parser
27
- exit 1
28
- end
29
-
30
- options
31
- end
32
-
33
- def windows?
34
- ENV['OS'] == 'Windows_NT'
35
- end
36
- end
37
-
38
- end