summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-02-14 23:01:42 +0200
committerPaul Buetow <paul@buetow.org>2025-02-14 23:01:42 +0200
commit1e3a8819e845c4025cda3e2574ce294e9180907a (patch)
treecbb65a890c901cd15c76ef20bd742844820f0729
parent2d9685779d260debbc95ab89ba4c2a5b3387190e (diff)
test only_when
-rw-r--r--lib/dsl.rb4
-rw-r--r--lib/dslkeywords/only_when.rb2
-rw-r--r--test/lib/dslkeywords/only_when_test.rb20
3 files changed, 23 insertions, 3 deletions
diff --git a/lib/dsl.rb b/lib/dsl.rb
index 3a53762..3d0ca30 100644
--- a/lib/dsl.rb
+++ b/lib/dsl.rb
@@ -8,7 +8,7 @@ Dir["#{Dir.pwd}/lib/dslkeywords/*.rb"].each { |m| require m }
module RCM
# Here all starts
class DSL
- attr_reader :id
+ attr_reader :id, :conds_met
def self.reset!
@@rcm_counter = -1
@@ -43,6 +43,6 @@ def configure(reset: false, &block)
RCM::DSL.new(reset) do |rcm|
rcm.info('Configuring...')
rcm.instance_eval(&block)
- rcm.evaluate!
+ rcm.evaluate! if rcm.conds_met
end
end
diff --git a/lib/dslkeywords/only_when.rb b/lib/dslkeywords/only_when.rb
index 82dbc1f..485fd42 100644
--- a/lib/dslkeywords/only_when.rb
+++ b/lib/dslkeywords/only_when.rb
@@ -5,7 +5,7 @@ module RCM
def initialize = @conds = {}
def is(arg) = arg
- def method_missing(method_name, *args, &block) = @conds[method_name] = args.first
+ def method_missing(method_name, *args) = @conds[method_name] = args.first
def respond_to_missing? = true
def met?
diff --git a/test/lib/dslkeywords/only_when_test.rb b/test/lib/dslkeywords/only_when_test.rb
new file mode 100644
index 0000000..9eaf5ac
--- /dev/null
+++ b/test/lib/dslkeywords/only_when_test.rb
@@ -0,0 +1,20 @@
+require 'minitest/autorun'
+require 'socket'
+
+require_relative '../../../lib/dsl'
+
+class RCMOnlyWhenTest < Minitest::Test
+ def test_hostname
+ rcm = configure(reset: true) do
+ only_when { hostname Socket.gethostname }
+ end
+ assert rcm.conds_met
+ end
+
+ def test_hostname_negative
+ rcm = configure(reset: true) do
+ only_when { hostname "#{Socket.gethostname}.invalid" }
+ end
+ refute rcm.conds_met
+ end
+end