Thibault Jouan 35621e1f5f 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.
2013-12-19 20:22:44 +00:00

40 lines
914 B
Ruby

module Producer
module Core
class Condition
class DSL
class << self
def evaluate(env, &block)
dsl = new(env, &block)
return_value = dsl.evaluate
Condition.new(dsl.tests, return_value)
end
def define_test(keyword, klass)
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
define_test :has_env, Tests::HasEnv
define_test :has_file, Tests::HasFile
attr_accessor :tests
def initialize(env, &block)
@env = env
@block = block
@tests = []
end
def evaluate
instance_eval &@block
end
end
end
end
end