mirage 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -1,3 +1,4 @@
1
+ V2.4.0 - Adding ability to set defaults
1
2
  V2.3.0 - Enhanced commandline/programmatic api
2
3
  V2.2.3 - fix bug where mirage is already running a client calls exit.
3
4
  V2.2.1/2 - Code tidy up
data/README.md CHANGED
@@ -15,4 +15,28 @@ P.s. Mirage runs on Linux,MacOSX and Windows; Rubies 1.8.7, 1.9 and JRuby.
15
15
  Installation
16
16
  ------------
17
17
  gem install mirage
18
-
18
+
19
+ What's New?
20
+ -----------
21
+ ### 2.3.0
22
+ ---------
23
+ #### What do I get?
24
+ ##### 1: Run more than one instance of Mirage per machine.
25
+ ##### 2: Programmatic interface for starting and stopping Mirage
26
+ The client API now includes the ability to start and stop Mirage locally. No more calling out to the command line.
27
+
28
+ **Example Usage:** (See rdoc for full details)
29
+
30
+ mirage_client = Mirage.start :port => 9001 #with out args start mirage on 7001 by default
31
+ Mirage.stop # stops the current running instance as long as only one is running
32
+
33
+ ##### 3: Updated command line interface
34
+ Now powered by the mighty Thor, the stop subcommand has been enhanced.
35
+ **Usage:**
36
+
37
+ mirage stop -> As it always did, stops the current instances of Mirage as long as there is only one running instance.
38
+ mirage stop -p port -> stops Mirage on a given port.
39
+ mirage stop -p port1, port2... -> stop multiple instances of Mirage.
40
+ mirage stop -p all -> stop all instances of mirage.
41
+ #### What do I have to do to upgrade?
42
+ You shouldn't have to do anything to move from the last version of Mirage to this one. Let me know if something stops working!
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.0
1
+ 2.4.0
@@ -0,0 +1,74 @@
1
+ Feature: The client can be configured with default settings to keep your mocking 'DRY'
2
+
3
+ Background:
4
+ Given the following gems are required to run the Mirage client test code:
5
+ """
6
+ require 'rubygems'
7
+ require 'rspec'
8
+ require 'mirage/client'
9
+ """
10
+
11
+ Scenario: configuring the client on instance
12
+ Given I run
13
+ """
14
+ client = Mirage::Client.new do |defaults|
15
+ defaults.method = :post
16
+ defaults.status = 202
17
+ defaults.default = true
18
+ defaults.delay = 2
19
+ defaults.content_type = "text/xml"
20
+ end
21
+
22
+ client.put('greeting','hello')
23
+ """
24
+ When I send POST to 'http://localhost:7001/mirage/responses/greeting/for/someone'
25
+ Then 'hello' should be returned
26
+ And a 202 should be returned
27
+ Then it should take at least '2' seconds
28
+ And the response 'content-type' should be 'text/xml'
29
+
30
+ Scenario: Configuring a client after it has been created
31
+ Given I run
32
+ """
33
+ client = Mirage::Client.new
34
+ client.configure do |defaults|
35
+ defaults.method = :post
36
+ defaults.status = 202
37
+ defaults.default = true
38
+ defaults.delay = 2
39
+ defaults.content_type = "text/xml"
40
+ end
41
+
42
+ client.put('greeting','hello')
43
+ """
44
+ When I send POST to 'http://localhost:7001/mirage/responses/greeting/for/someone'
45
+ Then 'hello' should be returned
46
+ And a 202 should be returned
47
+ Then it should take at least '2' seconds
48
+ And the response 'content-type' should be 'text/xml'
49
+
50
+ Scenario: resetting defaults
51
+ Given I run
52
+ """
53
+ client = Mirage::Client.new
54
+ client.configure do |defaults|
55
+ defaults.method = :post
56
+ defaults.status = 202
57
+ defaults.default = true
58
+ defaults.delay = 2
59
+ defaults.content_type = "text/xml"
60
+ end
61
+
62
+ client.reset
63
+
64
+ client.configure do |defaults|
65
+ defaults.method.should == nil
66
+ defaults.status.should == nil
67
+ defaults.default.should == nil
68
+ defaults.delay.should == nil
69
+ defaults.content_type.should == nil
70
+ end
71
+ """
72
+
73
+
74
+
data/lib/mirage/client.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  $LOAD_PATH.unshift "#{File.dirname(__FILE__)}"
2
2
  require 'client/web'
3
3
  require 'client/error'
4
+ require 'client/cli_bridge'
4
5
  require 'client/runner'
5
6
  require 'client/response'
6
7
  require 'client/client'
@@ -0,0 +1,32 @@
1
+ module Mirage
2
+ module CLIBridge
3
+ def mirage_process_ids *ports
4
+ ports.flatten!
5
+ mirage_instances = {}
6
+ ["Mirage Server", "mirage_server", "mirage server"].each do |process_name|
7
+ processes_with_name(process_name).lines.collect { |line| line.chomp }.each do |process_line|
8
+ pid = process_line.split(' ')[1]
9
+ port = process_line[/port (\d+)/, 1]
10
+ mirage_instances[port] = pid
11
+ end
12
+ end
13
+
14
+ return mirage_instances if ports.first.to_s.downcase == "all"
15
+ Hash[mirage_instances.find_all { |port, pid| ports.include?(port.to_i) }]
16
+ end
17
+
18
+ def kill pid
19
+ ChildProcess.windows? ? `taskkill /F /T /PID #{pid}` : `kill -9 #{pid}`
20
+ end
21
+
22
+ def processes_with_name name
23
+ if ChildProcess.windows?
24
+
25
+ `tasklist /V | findstr "#{name.gsub(" ", '\\ ')}"`
26
+ else
27
+ IO.popen("ps aux | grep '#{name}' | grep -v grep | grep -v #{$$}")
28
+ end
29
+ end
30
+
31
+ end
32
+ end
@@ -1,15 +1,27 @@
1
1
  require 'uri'
2
2
  module Mirage
3
3
  class Client
4
+ Defaults = Struct.new(:method, :status, :delay, :content_type, :default)
4
5
  include Mirage::Web
5
6
  attr_reader :url
6
7
 
8
+
7
9
  # Creates an instance of the Mirage client that can be used to interact with the Mirage Server
8
10
  #
9
11
  # Client.new => a client that is configured to connect to Mirage on http://localhost:7001/mirage (the default settings for Mirage)
10
12
  # Client.new(URL) => a client that is configured to connect to an instance of Mirage running on the specified url.
11
- def initialize url="http://localhost:7001/mirage"
13
+ def initialize url="http://localhost:7001/mirage", &block
12
14
  @url = url
15
+ @defaults = Defaults.new
16
+ configure &block if block_given?
17
+ end
18
+
19
+ def configure &block
20
+ yield @defaults
21
+ end
22
+
23
+ def reset
24
+ @defaults = Defaults.new
13
25
  end
14
26
 
15
27
  def stop
@@ -31,7 +43,7 @@ module Mirage
31
43
  # end
32
44
  def put endpoint, response_value, &block
33
45
  response = Mirage::Response.new response_value
34
-
46
+ @defaults.each_pair{|key, value|response.send("#{key}=", value) if value}
35
47
  yield response if block_given?
36
48
 
37
49
  build_response(http_put("#{@url}/templates/#{endpoint}", response.value, response.headers))
@@ -2,7 +2,7 @@ require 'ostruct'
2
2
  module Mirage
3
3
  class Response
4
4
 
5
- attr_accessor :content_type,:method, :response_code, :pattern, :default, :status, :delay
5
+ attr_accessor :content_type,:method, :pattern, :default, :status, :delay
6
6
  attr_reader :value
7
7
 
8
8
  def initialize response
@@ -50,6 +50,7 @@ module Mirage
50
50
 
51
51
  class Runner < Thor
52
52
  include ::Mirage::Web
53
+ include CLIBridge
53
54
  RUBY_CMD = ChildProcess.jruby? ? 'jruby' : 'ruby'
54
55
 
55
56
  desc "start", "Starts mirage"
@@ -104,7 +105,7 @@ module Mirage
104
105
  end
105
106
 
106
107
  mirage_process_ids(ports).values.each do |process_id|
107
- ChildProcess.windows? ? `taskkill /F /T /PID #{process_id}` : IO.popen("kill -9 #{process_id}")
108
+ kill process_id
108
109
  end
109
110
 
110
111
  wait_until do
@@ -112,31 +113,5 @@ module Mirage
112
113
  end
113
114
  end
114
115
 
115
- private
116
-
117
- def processes_with_name name
118
- if ChildProcess.windows?
119
-
120
- `tasklist /V | findstr "#{name.gsub(" ", '\\ ')}"`
121
- else
122
- IO.popen("ps aux | grep '#{name}' | grep -v grep | grep -v #{$$}")
123
- end
124
- end
125
-
126
- def mirage_process_ids *ports
127
- ports.flatten!
128
- mirage_instances = {}
129
- ["Mirage Server", "mirage_server", "mirage server"].each do |process_name|
130
- processes_with_name(process_name).lines.collect { |line| line.chomp }.each do |process_line|
131
- pid = process_line.split(' ')[1]
132
- port = process_line[/port (\d+)/, 1]
133
- mirage_instances[port] = pid
134
- end
135
- end
136
-
137
- return mirage_instances if ports.first.to_s.downcase == "all"
138
- Hash[mirage_instances.find_all { |port, pid| ports.include?(port.to_i) }]
139
- end
140
-
141
116
  end
142
117
  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 = "2.3.0"
8
+ s.version = "2.4.0"
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-08-26"
12
+ s.date = "2012-09-11"
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/configure.feature",
27
28
  "features/client/preview_responses.feature",
28
29
  "features/client/put.feature",
29
30
  "features/client/requests.feature",
@@ -54,6 +55,7 @@ Gem::Specification.new do |s|
54
55
  "features/support/mirage.rb",
55
56
  "full_build.sh",
56
57
  "lib/mirage/client.rb",
58
+ "lib/mirage/client/cli_bridge.rb",
57
59
  "lib/mirage/client/client.rb",
58
60
  "lib/mirage/client/error.rb",
59
61
  "lib/mirage/client/response.rb",
@@ -66,8 +68,9 @@ Gem::Specification.new do |s|
66
68
  "server/extensions/hash.rb",
67
69
  "server/extensions/object.rb",
68
70
  "server/mock_response.rb",
69
- "spec/running_via_api_spec.rb",
70
- "spec/running_via_api_windows_spec.rb",
71
+ "spec/cli_bridge_spec.rb",
72
+ "spec/runner_spec.rb",
73
+ "spec/spec_helper.rb",
71
74
  "test.rb",
72
75
  "views/index.erb"
73
76
  ]
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+ require 'mirage/client'
3
+
4
+ describe Mirage::CLIBridge do
5
+
6
+ include Mirage::CLIBridge
7
+
8
+ describe 'Windows' do
9
+
10
+ include_context :windows
11
+
12
+ it 'should find the pids of mirage instances for given ports' do
13
+
14
+ tasklist_output = "#{process_string_for_mirage(7001, 18903)}
15
+ #{process_string_for_mirage(7002, 18904)}
16
+ #{process_string_for_mirage(7003, 18905)}"
17
+
18
+ self.should_receive(:`).with(/tasklist.*/).any_number_of_times.and_return(tasklist_output)
19
+ mirage_process_ids([7001, 7002]).should == {"7001" => "18903", "7002" => "18904"}
20
+ end
21
+
22
+ it 'should find the pids of mirage instances for all ports' do
23
+ tasklist_output = "#{process_string_for_mirage(7001, 18903)}
24
+ #{process_string_for_mirage(7002, 18904)}
25
+ #{process_string_for_mirage(7003, 18905)}"
26
+
27
+ self.should_receive(:`).with(/tasklist.*/).any_number_of_times.and_return(tasklist_output)
28
+ mirage_process_ids([:all]).should == {"7001" => "18903", "7002" => "18904", "7003" => "18905"}
29
+ end
30
+
31
+ it 'should kill the given process id' do
32
+ self.should_receive(:`).with(/taskkill \/F \/T \/PID 18903/)
33
+ kill(18903)
34
+ end
35
+ end
36
+
37
+ describe 'Linux/MacOSX' do
38
+
39
+ include_context :linux
40
+
41
+ it 'should find the pids of mirage instances for given ports' do
42
+ ps_aux_output = "#{process_string_for_mirage(7001, 18903)}
43
+ #{process_string_for_mirage(7002, 18904)}
44
+ #{process_string_for_mirage(7003, 18905)}"
45
+
46
+ IO.should_receive(:popen).with(/ps aux.*/).any_number_of_times.and_return(ps_aux_output)
47
+ mirage_process_ids([7001, 7002]).should == {"7001" => "18903", "7002" => "18904"}
48
+ end
49
+
50
+ it 'should find the pids of mirage instances for all ports' do
51
+ ps_aux_output = "#{process_string_for_mirage(7001, 18903)}
52
+ #{process_string_for_mirage(7002, 18904)}
53
+ #{process_string_for_mirage(7003, 18905)}"
54
+
55
+ IO.should_receive(:popen).with(/ps aux.*/).any_number_of_times.and_return(ps_aux_output)
56
+ mirage_process_ids([:all]).should == {"7001" => "18903", "7002" => "18904", "7003" => "18905"}
57
+ end
58
+
59
+ it 'should kill the given process id' do
60
+ self.should_receive(:`).with(/kill -9 18903/)
61
+ kill(18903)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,130 @@
1
+ require 'spec_helper'
2
+ require 'mirage/client'
3
+
4
+ include Mirage
5
+
6
+ describe Mirage do
7
+
8
+ describe 'starting' do
9
+ before(:each) do
10
+ @runner = mock
11
+ Runner.should_receive(:new).and_return(@runner)
12
+ end
13
+
14
+ it 'should start Mirage on port 7001 by default' do
15
+ @runner.should_receive(:invoke).with(:start, [], {:port => 7001})
16
+ Mirage.start
17
+ end
18
+
19
+ it 'should start mirage on the given port' do
20
+ options = {:port => 9001}
21
+ @runner.should_receive(:invoke).with(:start, [], options)
22
+ Mirage.start options
23
+ end
24
+ end
25
+
26
+ describe 'stopping' do
27
+ before(:each) do
28
+ @runner = mock
29
+ Runner.stub(:new).and_return(@runner)
30
+ end
31
+
32
+ it 'should supply single port argument in an array to the runner' do
33
+ port = 7001
34
+ @runner.should_receive(:invoke).with(:stop, [], :port => [port])
35
+ @runner.should_receive(:invoke).with(:stop, [], :port => [:all])
36
+ Mirage.stop(:port => port)
37
+ Mirage.stop(:all)
38
+ end
39
+
40
+ it 'should stop multiple instances of Mirage' do
41
+ ports = 7001, 7002
42
+ @runner.should_receive(:invoke).with(:stop, [], :port => ports)
43
+ Mirage.stop(:port => ports)
44
+ end
45
+
46
+ end
47
+
48
+ describe Mirage::Runner do
49
+ it 'should stop the running instance of Mirage' do
50
+
51
+ runner = Mirage::Runner.new
52
+ runner.should_receive(:mirage_process_ids).with([:all]).any_number_of_times.and_return({"7001" => "18901"})
53
+
54
+ runner.should_receive(:kill).with("18901") do
55
+ runner.rspec_reset
56
+ runner.should_receive(:mirage_process_ids).with([:all]).any_number_of_times.and_return({})
57
+ end
58
+
59
+ runner.stop
60
+ end
61
+
62
+ it 'should not stop any instances when more than one is running' do
63
+ runner = Mirage::Runner.new
64
+ runner.should_receive(:mirage_process_ids).with([:all]).any_number_of_times.and_return({"7001" => "18901", "7002" => "18902", "7003" => "18903"})
65
+ runner.should_not_receive(:kill)
66
+
67
+ lambda { runner.stop }.should raise_error(Mirage::ClientError)
68
+ end
69
+
70
+
71
+ it 'should stop the instance running on the given port' do
72
+ options = {:port => [7001]}
73
+ runner = Mirage::Runner.new
74
+ runner.options = options
75
+
76
+ runner.should_receive(:mirage_process_ids).with([7001]).and_return({"7001" => "18901"})
77
+ runner.should_receive(:kill).with("18901") do
78
+ runner.rspec_reset
79
+ runner.stub(:mirage_process_ids).with([7001]).and_return({})
80
+ end
81
+
82
+ Mirage::Runner.should_receive(:new).and_return(runner)
83
+ runner.invoke(:stop, [], options)
84
+ end
85
+
86
+ it 'should stop the instance running on the given ports' do
87
+ options = {:port => [7001, 7002]}
88
+ runner = Mirage::Runner.new
89
+ runner.options = options
90
+
91
+ runner.should_receive(:mirage_process_ids).with([7001, 7002]).and_return({"7001" => "18901", "7002" => "18902"})
92
+ runner.should_receive(:kill).with("18901")
93
+ runner.should_receive(:kill).with("18902") do
94
+ runner.rspec_reset
95
+ runner.stub(:mirage_process_ids).with([7001, 7002]).and_return({})
96
+ end
97
+
98
+ Mirage::Runner.should_receive(:new).and_return(runner)
99
+ runner.invoke(:stop, [], options)
100
+ end
101
+
102
+ it 'should stop all running instances' do
103
+ options = {:port => [:all]}
104
+ runner = Mirage::Runner.new
105
+ runner.options = options
106
+
107
+ runner.should_receive(:mirage_process_ids).with([:all]).and_return({"7001" => "18901", "7002" => "18902"})
108
+ runner.should_receive(:kill).with("18901")
109
+ runner.should_receive(:kill).with("18902") do
110
+ runner.rspec_reset
111
+ runner.stub(:mirage_process_ids).with([:all]).and_return({})
112
+ end
113
+
114
+ Mirage::Runner.should_receive(:new).and_return(runner)
115
+ runner.invoke(:stop, [], options)
116
+
117
+ end
118
+
119
+ it 'should not error when asked to stop Mirage on a port that it is not running on' do
120
+ options = {:port => [7001]}
121
+ runner = Mirage::Runner.new
122
+ runner.options = options
123
+ runner.should_receive(:mirage_process_ids).with([7001]).any_number_of_times.and_return({})
124
+
125
+ Mirage::Runner.should_receive(:new).and_return(runner)
126
+ lambda { runner.invoke(:stop, [], options) }.should_not raise_error(Mirage::ClientError)
127
+ end
128
+
129
+ end
130
+ end
@@ -0,0 +1,23 @@
1
+ $LOAD_PATH.unshift "../lib"
2
+ require 'rspec'
3
+
4
+ shared_context :windows do
5
+ def process_string_for_mirage(mirage_port, pid)
6
+ %Q{ruby.exe #{pid} Console 1 6,076 K Running WIN-ATPGMMC0218\\\\leon 0:01:58 mirage server port #{mirage_port}}
7
+ end
8
+
9
+ before :each do
10
+ ChildProcess.should_receive(:windows?).any_number_of_times.and_return(true)
11
+ end
12
+ end
13
+
14
+ shared_context :linux do
15
+
16
+ def process_string_for_mirage(mirage_port, pid)
17
+ "team #{pid} 6.2 0.4 84328 20760 pts/1 Sl 22:15 0:00 Mirage Server port #{mirage_port}"
18
+ end
19
+
20
+ before :each do
21
+ ChildProcess.should_receive(:windows?).any_number_of_times.and_return(false)
22
+ end
23
+ 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: 2.3.0
4
+ version: 2.4.0
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-08-26 00:00:00.000000000Z
12
+ date: 2012-09-11 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
- requirement: &17467000 !ruby/object:Gem::Requirement
16
+ requirement: &13798800 !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: *17467000
24
+ version_requirements: *13798800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: eventmachine
27
- requirement: &17465480 !ruby/object:Gem::Requirement
27
+ requirement: &13797620 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - =
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.0.0.rc.4
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *17465480
35
+ version_requirements: *13797620
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: childprocess
38
- requirement: &17441940 !ruby/object:Gem::Requirement
38
+ requirement: &13789700 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *17441940
46
+ version_requirements: *13789700
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: waitforit
49
- requirement: &17440560 !ruby/object:Gem::Requirement
49
+ requirement: &13788460 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *17440560
57
+ version_requirements: *13788460
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: thor
60
- requirement: &17439580 !ruby/object:Gem::Requirement
60
+ requirement: &13787080 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *17439580
68
+ version_requirements: *13787080
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: thin
71
- requirement: &17437920 !ruby/object:Gem::Requirement
71
+ requirement: &13786060 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *17437920
79
+ version_requirements: *13786060
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rake
82
- requirement: &17436460 !ruby/object:Gem::Requirement
82
+ requirement: &13784820 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *17436460
90
+ version_requirements: *13784820
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: cucumber
93
- requirement: &17434960 !ruby/object:Gem::Requirement
93
+ requirement: &13783980 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *17434960
101
+ version_requirements: *13783980
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rspec
104
- requirement: &17428620 !ruby/object:Gem::Requirement
104
+ requirement: &13732180 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *17428620
112
+ version_requirements: *13732180
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: jeweler
115
- requirement: &17427700 !ruby/object:Gem::Requirement
115
+ requirement: &13729860 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *17427700
123
+ version_requirements: *13729860
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: sinatra-contrib
126
- requirement: &17426800 !ruby/object:Gem::Requirement
126
+ requirement: &13727620 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *17426800
134
+ version_requirements: *13727620
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: mechanize
137
- requirement: &17425900 !ruby/object:Gem::Requirement
137
+ requirement: &13725580 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *17425900
145
+ version_requirements: *13725580
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: nokogiri
148
- requirement: &17425340 !ruby/object:Gem::Requirement
148
+ requirement: &13680160 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ! '>='
@@ -153,10 +153,10 @@ dependencies:
153
153
  version: '0'
154
154
  type: :development
155
155
  prerelease: false
156
- version_requirements: *17425340
156
+ version_requirements: *13680160
157
157
  - !ruby/object:Gem::Dependency
158
158
  name: jruby-openssl
159
- requirement: &17424280 !ruby/object:Gem::Requirement
159
+ requirement: &13678600 !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
162
162
  - - ! '>='
@@ -164,7 +164,7 @@ dependencies:
164
164
  version: '0'
165
165
  type: :development
166
166
  prerelease: false
167
- version_requirements: *17424280
167
+ version_requirements: *13678600
168
168
  description: Mirage aids testing of your applications by hosting mock responses so
169
169
  that your applications do not have to talk to real endpoints. Its accessible via
170
170
  HTTP and has a RESTful interface.
@@ -183,6 +183,7 @@ files:
183
183
  - VERSION
184
184
  - bin/mirage
185
185
  - features/client/clear.feature
186
+ - features/client/configure.feature
186
187
  - features/client/preview_responses.feature
187
188
  - features/client/put.feature
188
189
  - features/client/requests.feature
@@ -213,6 +214,7 @@ files:
213
214
  - features/support/mirage.rb
214
215
  - full_build.sh
215
216
  - lib/mirage/client.rb
217
+ - lib/mirage/client/cli_bridge.rb
216
218
  - lib/mirage/client/client.rb
217
219
  - lib/mirage/client/error.rb
218
220
  - lib/mirage/client/response.rb
@@ -225,8 +227,9 @@ files:
225
227
  - server/extensions/hash.rb
226
228
  - server/extensions/object.rb
227
229
  - server/mock_response.rb
228
- - spec/running_via_api_spec.rb
229
- - spec/running_via_api_windows_spec.rb
230
+ - spec/cli_bridge_spec.rb
231
+ - spec/runner_spec.rb
232
+ - spec/spec_helper.rb
230
233
  - test.rb
231
234
  - views/index.erb
232
235
  homepage: https://github.com/lashd/mirage
@@ -246,7 +249,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
246
249
  version: '0'
247
250
  segments:
248
251
  - 0
249
- hash: 3403539479088578528
252
+ hash: 943352209253188731
250
253
  required_rubygems_version: !ruby/object:Gem::Requirement
251
254
  none: false
252
255
  requirements:
@@ -1,147 +0,0 @@
1
- $LOAD_PATH.unshift "../lib"
2
- require 'rspec'
3
- require 'mirage/client'
4
-
5
- def process_string_for_mirage(mirage_port, pid)
6
- "team #{pid} 6.2 0.4 84328 20760 pts/1 Sl 22:15 0:00 Mirage Server port #{mirage_port}"
7
- end
8
-
9
- include Mirage
10
-
11
- unless ChildProcess.windows?
12
- describe Mirage do
13
-
14
- describe 'starting' do
15
- before(:each) do
16
- @runner = mock
17
- Runner.should_receive(:new).and_return(@runner)
18
- end
19
-
20
- it 'should start Mirage on port 7001 by default' do
21
- @runner.should_receive(:invoke).with(:start, [], {:port => 7001})
22
- Mirage.start
23
- end
24
-
25
- it 'should start mirage on the given port' do
26
- options = {:port => 9001}
27
- @runner.should_receive(:invoke).with(:start, [], options)
28
- Mirage.start options
29
- end
30
- end
31
-
32
- describe 'stopping' do
33
- before(:each) do
34
- @runner = mock
35
- Runner.stub(:new).and_return(@runner)
36
- end
37
-
38
- it 'should supply single port argument in an array to the runner' do
39
- port = 7001
40
- @runner.should_receive(:invoke).with(:stop, [], :port => [port])
41
- @runner.should_receive(:invoke).with(:stop, [], :port => [:all])
42
- Mirage.stop(:port => port)
43
- Mirage.stop(:all)
44
- end
45
-
46
- it 'should stop multiple instances of Mirage' do
47
- ports = 7001, 7002
48
- @runner.should_receive(:invoke).with(:stop, [], :port => ports)
49
- Mirage.stop(:port => ports)
50
- end
51
-
52
- end
53
-
54
- describe Mirage::Runner do
55
- it 'should stop the running instance of Mirage' do
56
- IO.should_receive(:popen).with(/ps aux.*/).any_number_of_times.and_return(process_string_for_mirage(7001, 18903))
57
-
58
- IO.should_receive(:popen).with("kill -9 18903") do
59
- IO.rspec_reset
60
- IO.stub(:popen).and_return("")
61
- end
62
- Mirage::Runner.new.stop
63
- end
64
-
65
- it 'should not stop any instances when more than one is running' do
66
- ps_aux_output =<<PS
67
- #{process_string_for_mirage(7001, 18901)}
68
- #{process_string_for_mirage(7002, 18902)}
69
- #{process_string_for_mirage(7003, 18903)}
70
- PS
71
- IO.should_receive(:popen).with(/ps aux.*/).any_number_of_times.and_return(ps_aux_output)
72
- IO.should_not_receive(:popen).with(/kill.*/)
73
-
74
- lambda { Mirage::Runner.new.stop }.should raise_error(Mirage::ClientError)
75
-
76
- end
77
-
78
-
79
- it 'should stop the instance running on the given port' do
80
- ps_aux_output =<<PS
81
- #{process_string_for_mirage(7001, 18901)}
82
- #{process_string_for_mirage(7002, 18902)}
83
- PS
84
- IO.should_receive(:popen).with(/ps aux.*/).any_number_of_times.and_return(ps_aux_output)
85
- IO.should_receive(:popen).with(/kill -9 18901/) do
86
- IO.rspec_reset
87
- IO.stub(:popen).and_return(process_string_for_mirage(7002, 18902))
88
- end
89
-
90
- Mirage::Runner.new.invoke(:stop, [], {:port => [7001]})
91
- end
92
-
93
- it 'should stop the instance running on the given ports' do
94
- ps_aux_output =<<PS
95
- #{process_string_for_mirage(7001, 18901)}
96
- #{process_string_for_mirage(7002, 18902)}
97
- #{process_string_for_mirage(7003, 18903)}
98
- PS
99
- IO.should_receive(:popen).with(/ps aux.*/).any_number_of_times.and_return(ps_aux_output)
100
- IO.should_receive(:popen).with(/kill -9 18901/)
101
- IO.should_receive(:popen).with(/kill -9 18902/) do
102
- IO.rspec_reset
103
- IO.stub(:popen).and_return(process_string_for_mirage("7003", 18903))
104
- end
105
-
106
- Mirage::Runner.new.invoke(:stop, [], {:port => [7001, 7002]})
107
- end
108
-
109
- it 'should stop all running instances' do
110
- ps_aux_output =<<PS
111
- #{process_string_for_mirage(7001, 18901)}
112
- #{process_string_for_mirage(7002, 18902)}
113
- #{process_string_for_mirage(7003, 18903)}
114
- PS
115
- IO.should_receive(:popen).with(/ps aux.*/).any_number_of_times.and_return(ps_aux_output)
116
- IO.should_receive(:popen).with(/kill -9 18901/)
117
- IO.should_receive(:popen).with(/kill -9 18902/)
118
- IO.should_receive(:popen).with(/kill -9 18903/) do
119
- IO.rspec_reset
120
- IO.stub(:popen).and_return("")
121
- end
122
-
123
- Mirage::Runner.new.invoke(:stop, [], {:port => [:all]})
124
-
125
- end
126
-
127
- it 'should not error when asked to stop Mirage on a port that it is not running on' do
128
- ps_aux_output =<<PS
129
- #{process_string_for_mirage(7001, 18901)}
130
- PS
131
- IO.should_receive(:popen).with(/ps aux.*/).any_number_of_times.and_return(ps_aux_output)
132
- IO.should_not_receive(:popen).with(/kill -9 18901/)
133
- lambda { Mirage::Runner.new.invoke(:stop, [], {:port => [7002]}) }.should_not raise_error(Mirage::ClientError)
134
- end
135
-
136
- # it 'should not start mirage on the same port' do
137
- # ps_aux_output =<<PS
138
- ##{process_string_for_mirage(7001, 18901)}
139
- #PS
140
- # IO.should_receive(:popen).with(/ps aux.*/).any_number_of_times.and_return(ps_aux_output)
141
- # lambda{Mirage::Runner.new.invoke(:start, [], {:port => 7001})}.should raise_error(Mirage::ClientError)
142
- # end
143
-
144
-
145
- end
146
- end
147
- end
@@ -1,187 +0,0 @@
1
- $LOAD_PATH.unshift "../lib"
2
- require 'rspec'
3
- require 'mirage/client'
4
-
5
- if ChildProcess.windows?
6
-
7
-
8
- def process_string_for_mirage(mirage_port, pid)
9
- %Q{ruby.exe #{pid} Console 1 6,076 K Running WIN-ATPGMMC0218\\\\leon 0:01:58 mirage server port #{mirage_port}}
10
- end
11
-
12
- include Mirage
13
-
14
- describe Mirage do
15
-
16
- describe 'starting' do
17
- before(:each) do
18
- @runner = mock
19
- Runner.should_receive(:new).and_return(@runner)
20
- end
21
-
22
- it 'should start Mirage on port 7001 by default' do
23
- @runner.should_receive(:invoke).with(:start, [], {:port => 7001})
24
- Mirage.start
25
- end
26
-
27
- it 'should start mirage on the given port' do
28
- options = {:port => 9001}
29
- @runner.should_receive(:invoke).with(:start, [], options)
30
- Mirage.start options
31
- end
32
- end
33
-
34
- describe 'stopping' do
35
- before(:each) do
36
- @runner = mock
37
- Runner.stub(:new).and_return(@runner)
38
- end
39
-
40
- it 'should supply single port argument in an array to the runner' do
41
- port = 7001
42
- @runner.should_receive(:invoke).with(:stop, [], :port => [port])
43
- @runner.should_receive(:invoke).with(:stop, [], :port => [:all])
44
- Mirage.stop(:port => port)
45
- Mirage.stop(:port => :all)
46
- end
47
-
48
- it 'should stop multiple instances of Mirage' do
49
- ports = 7001, 7002
50
- @runner.should_receive(:invoke).with(:stop, [], :port => ports)
51
- Mirage.stop(:port => ports)
52
- end
53
-
54
- end
55
-
56
- describe Mirage::Runner do
57
- it 'should stop the running instance of Mirage' do
58
-
59
- runner = Mirage::Runner.new
60
-
61
- runner.should_receive(:`).with(/tasklist.*/).any_number_of_times.and_return(process_string_for_mirage(7001, 18903))
62
- runner.should_receive(:`).with(/taskkill \/F \/T \/PID 18903/) do
63
- runner.rspec_reset
64
- runner.stub(:`).and_return("")
65
- end
66
-
67
- Mirage::Runner.should_receive(:new).with([], {}, anything).and_return(runner)
68
- runner.invoke(:stop, [], nil)
69
- end
70
-
71
- it 'should not stop any instances when more than one is running' do
72
- ps_aux_output =<<PS
73
- #{process_string_for_mirage(7001, 18901)}
74
- #{process_string_for_mirage(7002, 18902)}
75
- #{process_string_for_mirage(7003, 18903)}
76
- PS
77
-
78
- runner = Mirage::Runner.new
79
-
80
- runner.should_receive(:`).with(/tasklist.*/).any_number_of_times.and_return(ps_aux_output)
81
- runner.should_not_receive(:`).with(/taskkill.*/)
82
-
83
- Mirage::Runner.should_receive(:new).with([], {}, anything).and_return(runner)
84
-
85
- lambda { runner.invoke(:stop, [], nil) }.should raise_error(Mirage::ClientError)
86
-
87
- end
88
-
89
-
90
- it 'should stop the instance running on the given port' do
91
-
92
- task_list_output =<<TASKLIST
93
- #{process_string_for_mirage(7001, 18901)}
94
- #{process_string_for_mirage(7002, 18902)}
95
- TASKLIST
96
-
97
- options = {:port => [7001]}
98
- runner = Mirage::Runner.new
99
- runner.options = options
100
-
101
- runner.should_receive(:`).with(/tasklist.*/).at_least(1).and_return(task_list_output)
102
- runner.should_receive(:`).with(/taskkill \/F \/T \/PID 18901/) do
103
- runner.rspec_reset
104
- runner.stub(:`).and_return(process_string_for_mirage(7002, 18902))
105
- end
106
-
107
- Mirage::Runner.should_receive(:new).with([], options, anything).and_return(runner)
108
-
109
- runner.invoke(:stop, [], options)
110
- end
111
-
112
- it 'should stop the instance running on the given ports' do
113
- ps_aux_output =<<PS
114
- #{process_string_for_mirage(7001, 18901)}
115
- #{process_string_for_mirage(7002, 18902)}
116
- #{process_string_for_mirage(7003, 18903)}
117
- PS
118
-
119
- options = {:port => [7001,7002]}
120
- runner = Mirage::Runner.new
121
- runner.options = options
122
-
123
- runner.should_receive(:`).with(/tasklist.*/).any_number_of_times.and_return(ps_aux_output)
124
- runner.should_receive(:`).with(/taskkill \/F \/T \/PID 18901/)
125
- runner.should_receive(:`).with(/taskkill \/F \/T \/PID 18902/) do
126
- runner.rspec_reset
127
- runner.stub(:`).and_return(process_string_for_mirage("7003", 18903))
128
- end
129
-
130
- Mirage::Runner.should_receive(:new).with([], options, anything).and_return(runner)
131
- runner.invoke(:stop, [], options)
132
- end
133
-
134
- it 'should stop all running instances' do
135
- ps_aux_output =<<PS
136
- #{process_string_for_mirage(7001, 18901)}
137
- #{process_string_for_mirage(7002, 18902)}
138
- #{process_string_for_mirage(7003, 18903)}
139
- PS
140
-
141
- options = {:port => [:all]}
142
- runner = Mirage::Runner.new
143
- runner.options = options
144
-
145
-
146
- runner.should_receive(:`).with(/tasklist.*/).any_number_of_times.and_return(ps_aux_output)
147
-
148
- runner.should_receive(:`).with(/taskkill \/F \/T \/PID 18901/)
149
- runner.should_receive(:`).with(/taskkill \/F \/T \/PID 18902/)
150
- runner.should_receive(:`).with(/taskkill \/F \/T \/PID 18903/) do
151
- runner.rspec_reset
152
- runner.stub(:`).and_return("")
153
- end
154
-
155
- Mirage::Runner.should_receive(:new).with([], options, anything).and_return(runner)
156
- runner.invoke(:stop, [], options)
157
-
158
- end
159
-
160
- it 'should not error when asked to stop Mirage on a port that it is not running on' do
161
- ps_aux_output =<<PS
162
- #{process_string_for_mirage(7001, 18901)}
163
- PS
164
-
165
- options = {:port => [7002]}
166
- runner = Mirage::Runner.new
167
-
168
- runner.should_receive(:`).with(/tasklist.*/).any_number_of_times.and_return(ps_aux_output)
169
- runner.should_not_receive(:`).with(/taskkill \/F \/T \/PID 18901/)
170
-
171
- Mirage::Runner.should_receive(:new).with([], options, anything).and_return(runner)
172
-
173
- lambda { runner.invoke(:stop, [], options) }.should_not raise_error(Mirage::ClientError)
174
- end
175
-
176
- # it 'should not start mirage on the same port' do
177
- # ps_aux_output =<<PS
178
- ##{process_string_for_mirage(7001, 18901)}
179
- #PS
180
- # IO.should_receive(:popen).with(/ps aux.*/).any_number_of_times.and_return(ps_aux_output)
181
- # lambda{Mirage::Runner.new.invoke(:start, [], {:port => 7001})}.should raise_error(Mirage::ClientError)
182
- # end
183
-
184
-
185
- end
186
- end
187
- end