vmc-ng/spec/helpers.rb in vmc-0.4.0.beta.32 vs vmc-ng/spec/helpers.rb in vmc-0.4.0.beta.33
- old
+ new
@@ -1,10 +1,17 @@
+require "simplecov"
+
+SimpleCov.start do
+ root File.expand_path("../../", __FILE__)
+ add_filter "spec/"
+end
+
require "cfoundry"
require "vmc"
-require "./eventlog"
-require "./patches"
+require File.expand_path("../eventlog", __FILE__)
+require File.expand_path("../patches", __FILE__)
TARGET = ENV["VMC_TEST_TARGET"] || "http://localhost:8181"
USER = ENV["VMC_TEST_USER"] || "sre@vmware.com"
PASSWORD = ENV["VMC_TEST_PASSWORD"] || "test"
@@ -42,12 +49,14 @@
# cache runtimes for app generation
def runtimes
@@runtimes ||= client.runtimes(0)
end
- def with_random_app
- with_random_apps(1)
+ def with_random_app(space = client.current_space)
+ with_random_apps(space, 1) do |apps|
+ yield apps.first
+ end
end
# create 2-5 random apps, call the block, and then delete them
def with_random_apps(space = client.current_space, num = rand(3) + 2)
apps = []
@@ -80,11 +89,11 @@
yield space
ensure
space.delete!
end
- def running(command, inputs = {})
+ def running(command, inputs = {}, given = {})
VMC::CLI.new.exit_status 0
before_in = $stdin
before_out = $stdout
before_err = $stderr
@@ -100,11 +109,11 @@
main = Thread.current
thd = Thread.new do
begin
- VMC::CLI.new.invoke(command, inputs)
+ VMC::CLI.new.invoke(command, inputs, given)
rescue SystemExit => e
unless e.status == 0
raise <<EOF
execution failed with status #{e.status}!
@@ -263,30 +272,36 @@
Complete.new
end
class FailWith
- def initialize(exception)
+ def initialize(exception, predicate = nil)
@expected = exception
+ @predicate = predicate
end
def matches?(log)
@actual = log.wait_for_event(EventLog::Raised).exception
- @actual.is_a?(@expected)
+
+ return false unless @actual.is_a?(@expected)
+
+ @predicate.call(@actual) if @predicate
+
+ true
end
def failure_message
- "expected #@expected to be raised, but got #{@actual.class}: '#@actual"
+ "expected #@expected to be raised, but got #{@actual.class}: '#@actual'"
end
def negative_failure_message
"expected #@expected to NOT be raised, but it was"
end
end
- def fail_with(exception)
- FailWith.new(exception)
+ def fail_with(exception, &blk)
+ FailWith.new(exception, blk)
end
class ProgressExpectation
def matches?(log)
@@ -354,11 +369,11 @@
def has_input(name, value = nil)
$vmc_event.should have_input(name, value)
end
- def raises(exception)
- $vmc_event.should fail_with(exception)
+ def raises(exception, &blk)
+ $vmc_event.should fail_with(exception, &blk)
end
def finish
$vmc_event.should complete
end