mirage 1.3.3 → 1.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.3
1
+ 1.3.4
data/bin/mirage CHANGED
@@ -7,49 +7,45 @@ include Mirage::Util
7
7
  RUBY_CMD = RUBY_PLATFORM == 'java' ? 'jruby' : 'ruby'
8
8
 
9
9
 
10
- def start_mirage(args, mirage)
10
+ def start_mirage(args)
11
11
  puts "Starting Mirage"
12
12
 
13
13
  if windows?
14
- command = ["cmd", "/C", "start", "\"mirage server\"", RUBY_CMD, "#{File.dirname(__FILE__)}/../lib/start_mirage.rb"]
14
+ command = ["cmd", "/C", "start", "\"mirage server\"", RUBY_CMD, "#{File.dirname(__FILE__)}/../lib/start_mirage.rb"]
15
15
  else
16
- command = [RUBY_CMD, "#{File.dirname(__FILE__)}/../lib/start_mirage.rb"]
16
+ command = [RUBY_CMD, "#{File.dirname(__FILE__)}/../lib/start_mirage.rb"]
17
17
  end
18
18
  ChildProcess.build(*(command.concat(args))).start
19
-
20
- wait_until do
21
- mirage.running?
22
- end
19
+ Mirage::Client.new "http://localhost:#{parse_options(ARGV)[:port]}/mirage"
23
20
  end
24
21
 
25
22
 
26
- def stop_mirage
23
+ def mirage_process_ids
27
24
  if windows?
28
- process_id = `tasklist /V | findstr "mirage\\ server"`.split(' ')[1]
29
- `taskkill /F /T /PID #{process_id}` if process_id
25
+ [`tasklist /V | findstr "mirage\\ server"`.split(' ')[1]].compact
30
26
  else
31
- begin
32
- ["Mirage Server", 'mirage start', 'start_mirage'].each do |process_name|
33
- process_id = `ps aux | grep "#{process_name}" | grep -v grep`.split(' ')[1]
34
- system "kill -9 #{process_id}" if process_id
35
- end
36
- rescue
37
- puts 'Mirage is not running'
38
- end
27
+ ["Mirage Server", 'start_mirage'].collect do |process_name|
28
+ `ps aux | grep "#{process_name}" | grep -v grep`.split(' ')[1]
29
+ end.find_all { |process_id| process_id != $$.to_s }.compact
39
30
  end
40
31
  end
41
32
 
42
- if ARGV.include?('start')
33
+ def stop_mirage
34
+ mirage_process_ids.each { |process_id| windows? ? `taskkill /F /T /PID #{process_id}` : `kill -9 #{process_id}` }
35
+ end
43
36
 
44
- options = parse_options(ARGV)
45
- mirage_client = Mirage::Client.new "http://localhost:#{options[:port]}/mirage"
37
+ if ARGV.include?('start')
46
38
 
47
- if mirage_client.running?
48
- puts "Mirage already running"
39
+ unless mirage_process_ids.empty?
40
+ puts "Mirage is already running"
49
41
  exit 1
50
42
  end
51
43
 
52
- start_mirage(ARGV, mirage_client)
44
+ mirage_client = start_mirage(ARGV)
45
+ wait_until do
46
+ mirage_client.running?
47
+ end
48
+
53
49
  begin
54
50
  mirage_client.prime
55
51
  rescue Mirage::InternalServerException => e
@@ -36,4 +36,10 @@ Feature: Mirage is started from the command line.
36
36
  Scenario: Starting Mirage on a custom port
37
37
  Given Mirage is not running
38
38
  When I run 'mirage start -p 9001'
39
- Then mirage should be running on 'http://localhost:9001/mirage'
39
+ Then mirage should be running on 'http://localhost:9001/mirage'
40
+
41
+ Scenario: Starting Mirage when it is already running
42
+ Given Mirage is running
43
+ When I run 'mirage start -p 9001'
44
+ Then I should see 'Mirage is already running' on the command line
45
+ Then Connection should be refused to 'http://localhost:9001/mirage'
@@ -5,15 +5,16 @@ require 'cucumber'
5
5
  require 'rspec'
6
6
  require 'mechanize'
7
7
 
8
+ include Mirage::Util
8
9
  SCRATCH = './scratch'
9
10
  RUBY_CMD = RUBY_PLATFORM == 'JAVA' ? 'jruby' : 'ruby'
11
+ BLANK_RUBYOPT_CMD = windows? ? 'set RUBYOPT=' : "export RUBYOPT=''"
10
12
  $log_file_marker = 0
11
13
 
12
-
13
14
  module CommandLine
14
15
  def execute command
15
16
  command_line_output_path = "#{SCRATCH}/commandline_output.txt"
16
- system "export RUBYOPT='' && cd #{SCRATCH} && #{command} > #{File.basename(command_line_output_path)}"
17
+ system "#{BLANK_RUBYOPT_CMD} && cd #{SCRATCH} && #{command} > #{File.basename(command_line_output_path)}"
17
18
  File.read(command_line_output_path)
18
19
  end
19
20
  end
@@ -46,11 +47,11 @@ module Regression
46
47
  include CommandLine
47
48
 
48
49
  def stop_mirage
49
- system "export RUBYOPT='' && cd #{SCRATCH} && mirage stop"
50
+ system "#{BLANK_RUBYOPT_CMD} && cd #{SCRATCH} && mirage stop"
50
51
  end
51
52
 
52
53
  def start_mirage
53
- system "export RUBYOPT='' && cd #{SCRATCH} && mirage start"
54
+ system "#{BLANK_RUBYOPT_CMD} && cd #{SCRATCH} && mirage start"
54
55
  end
55
56
 
56
57
  def run command
@@ -91,11 +92,13 @@ Before do
91
92
  end
92
93
 
93
94
  Dir["#{SCRATCH}/*"].each do |file|
94
- FileUtils.rm_rf(file) unless file == "#{SCRATCH}/mirage.log"
95
+ FileUtils.rm_rf(file) unless file == "#{SCRATCH}/mirage.log"
95
96
  end
96
97
 
97
- @mirage_log_file = File.open("#{SCRATCH}/mirage.log")
98
- @mirage_log_file.seek(0,IO::SEEK_END)
98
+ if File.exists? "#{SCRATCH}/mirage.log"
99
+ @mirage_log_file = File.open("#{SCRATCH}/mirage.log")
100
+ @mirage_log_file.seek(0, IO::SEEK_END)
101
+ end
99
102
  end
100
103
 
101
104
 
@@ -91,7 +91,6 @@ module Mirage
91
91
  pattern = request['pattern'] ? /#{request['pattern']}/ : :basic
92
92
  name = args.join('/')
93
93
  is_default = request['default'] == 'true'
94
- the_request = request
95
94
 
96
95
  response = MockResponse.new(name, response_value, pattern, delay.to_f, is_default)
97
96
 
@@ -189,7 +188,7 @@ module Mirage
189
188
  end
190
189
 
191
190
  def delete_response(response_id)
192
- RESPONSES.each do |name, response_set|
191
+ RESPONSES.values.each do |response_set|
193
192
  response_set.each { |key, response| response_set.delete(key) if response.response_id == response_id }
194
193
  end
195
194
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mirage}
8
- s.version = "1.3.3"
8
+ s.version = "1.3.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"]
data/rakefile CHANGED
@@ -35,7 +35,7 @@ end
35
35
  Jeweler::RubygemsDotOrgTasks.new
36
36
 
37
37
 
38
- require 'cucumber'
38
+ require 'cucumber'
39
39
  require 'cucumber/rake/task'
40
40
  Cucumber::Rake::Task.new(:features) do |t|
41
41
  t.cucumber_opts = "mode=regression features --format pretty"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mirage
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.3.3
5
+ version: 1.3.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Leon Davis
@@ -180,7 +180,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
180
180
  requirements:
181
181
  - - ">="
182
182
  - !ruby/object:Gem::Version
183
- hash: 1026754404301644285
183
+ hash: 2550934964107386131
184
184
  segments:
185
185
  - 0
186
186
  version: "0"