Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
rvm:
- '1.9.3'
- '2.0.0'
- '2.0.0'
- '2.1.5'
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ source 'https://rubygems.org'

gem 'sinatra'
gem 'childprocess'
gem "waitforit"
gem "thor"
gem "ptools"
gem "httparty"
Expand Down
4 changes: 1 addition & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ GEM
remote: https://rubygems.org/
specs:
addressable (2.3.5)
backports (3.3.5)
backports (3.6.8)
bouncy-castle-java (1.5.0147)
builder (3.2.2)
childprocess (0.3.9)
Expand Down Expand Up @@ -106,7 +106,6 @@ GEM
tilt (~> 1.3)
thor (0.18.1)
tilt (1.4.1)
waitforit (0.0.1)
win32-api (1.5.0-x86-mingw32)
win32-file (0.6.8)
win32-api (>= 1.2.1)
Expand Down Expand Up @@ -141,4 +140,3 @@ DEPENDENCIES
sinatra
sinatra-contrib
thor
waitforit
8 changes: 6 additions & 2 deletions features/support/command_line.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
require 'tempfile'
require 'wait_methods'

module CommandLine
include Mirage::WaitMethods

def run command
output = Tempfile.new("child")
Dir.chdir SCRATCH do
Expand All @@ -8,7 +12,7 @@ def run command
process.io.stdout = output
process.io.stderr = output
process.start
wait_until(:timeout_after => 30.seconds) { process.exited? }
wait_until(:timeout_after => 30) { process.exited? }
end
File.read(output.path)
end
Expand All @@ -30,4 +34,4 @@ def write_to_file file_path, content
end

World CommandLine
include CommandLine
include CommandLine
3 changes: 2 additions & 1 deletion lib/mirage/client.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}"
require 'wait_methods'
require 'client/template'
require 'client/error'
require 'client/cli_bridge'
Expand All @@ -7,4 +8,4 @@
require 'client/templates'
require 'client/requests'
require 'client/request'
require 'client/client'
require 'client/client'
10 changes: 6 additions & 4 deletions lib/mirage/client/runner.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'thor'
require 'waitforit'
require 'childprocess'
require 'uri'
require 'httparty'

module Mirage
class << self

Expand Down Expand Up @@ -30,7 +30,7 @@ def stop options={:port => []}
end

Runner.new.invoke(:stop, [], options)
rescue ClientError => e
rescue ClientError
raise ClientError.new("Mirage is running multiple ports, please specify the port(s) see api/tests for details")
end

Expand All @@ -52,6 +52,8 @@ def running? options_or_url = {:port => 7001}

class Runner < Thor
include CLIBridge
include Mirage::WaitMethods

RUBY_CMD = ChildProcess.jruby? ? 'jruby' : 'ruby'

desc "start", "Starts mirage"
Expand Down Expand Up @@ -79,7 +81,7 @@ def start
command = command.concat(options.to_a).flatten.collect { |arg| arg.to_s }
ChildProcess.build(*command).start

wait_until(:timeout_after => 30.seconds) { Mirage.running?(options) }
wait_until(:timeout_after => 30) { Mirage.running?(options) }

begin
Mirage::Client.new(options).prime
Expand All @@ -100,4 +102,4 @@ def stop
end

end
end
end
19 changes: 19 additions & 0 deletions lib/mirage/wait_methods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Mirage
# module WaitMethods - contains methods for waiting
module WaitMethods
# Wait until a the supplied block returns true
# @example
# wait_until do
# (rand % 2) == 0
# end
def wait_until(opts = {})
opts = {timeout_after: 5, retry_every: 0.1}.merge(opts)
start_time = Time.now
until Time.now > start_time + opts[:timeout_after]
return true if yield == true
sleep opts[:retry_every]
end
fail TimeoutException, 'Action took to long'
end
end
end
3 changes: 0 additions & 3 deletions mirage.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ Gem::Specification.new do |s|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<sinatra>, [">= 0"])
s.add_runtime_dependency(%q<childprocess>, [">= 0"])
s.add_runtime_dependency(%q<waitforit>, [">= 0"])
s.add_runtime_dependency(%q<thor>, [">= 0"])
s.add_runtime_dependency(%q<ptools>, [">= 0"])
s.add_runtime_dependency(%q<httparty>, [">= 0"])
Expand All @@ -146,7 +145,6 @@ Gem::Specification.new do |s|
else
s.add_dependency(%q<sinatra>, [">= 0"])
s.add_dependency(%q<childprocess>, [">= 0"])
s.add_dependency(%q<waitforit>, [">= 0"])
s.add_dependency(%q<thor>, [">= 0"])
s.add_dependency(%q<ptools>, [">= 0"])
s.add_dependency(%q<httparty>, [">= 0"])
Expand All @@ -160,7 +158,6 @@ Gem::Specification.new do |s|
else
s.add_dependency(%q<sinatra>, [">= 0"])
s.add_dependency(%q<childprocess>, [">= 0"])
s.add_dependency(%q<waitforit>, [">= 0"])
s.add_dependency(%q<thor>, [">= 0"])
s.add_dependency(%q<ptools>, [">= 0"])
s.add_dependency(%q<httparty>, [">= 0"])
Expand Down