Implement condition DSL negated test prefix (no_*)
* Allow no_* to be used for every tests in condition DSL: condition { no_has_env :shell, '/bin/sh' }; * Modify Test constructor to accept negated: named argument, implement #negated? and #pass?; * Rename #success? to #verify in all test classes.
This commit is contained in:
@@ -14,7 +14,7 @@ module Producer
|
||||
|
||||
def met?
|
||||
return !!@return_value if @tests.empty?
|
||||
@tests.each { |t| return false unless t.success? }
|
||||
@tests.each { |t| return false unless t.pass? }
|
||||
true
|
||||
end
|
||||
|
||||
|
@@ -13,6 +13,9 @@ module Producer
|
||||
define_method(keyword) do |*args|
|
||||
@tests << klass.new(@env, *args)
|
||||
end
|
||||
define_method("no_#{keyword}") do |*args|
|
||||
@tests << klass.new(@env, *args, negated: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@@ -3,9 +3,18 @@ module Producer
|
||||
class Test
|
||||
attr_reader :env, :arguments
|
||||
|
||||
def initialize(env, *arguments)
|
||||
def initialize(env, *arguments, negated: false)
|
||||
@env = env
|
||||
@arguments = arguments
|
||||
@negated = negated
|
||||
end
|
||||
|
||||
def negated?
|
||||
@negated
|
||||
end
|
||||
|
||||
def pass?
|
||||
verify ^ negated?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -2,7 +2,7 @@ module Producer
|
||||
module Core
|
||||
module Tests
|
||||
class HasEnv < Test
|
||||
def success?
|
||||
def verify
|
||||
env.remote.environment.has_key? arguments.first.to_s.upcase
|
||||
end
|
||||
end
|
||||
|
@@ -2,7 +2,7 @@ module Producer
|
||||
module Core
|
||||
module Tests
|
||||
class HasFile < Test
|
||||
def success?
|
||||
def verify
|
||||
env.remote.fs.has_file? arguments.first
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user