Skip to content

Commit bf8a1e6

Browse files
committed
feat: create shortcut to_PREDICATE for the very common single-predicate expectation
E.g. expect_execution { ... } .to_achieve { ... } Works with any expectation
1 parent 29693b3 commit bf8a1e6

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/roby/test/expect_execution.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ def respond_to_missing?(m, include_private)
5656
SETUP_METHODS.include?(m)
5757
end
5858

59-
def method_missing(m, *args, &block)
60-
expectations.public_send(m, *args, &block)
59+
def method_missing(m, *args, **kw, &block)
60+
if (to_method = m.to_s.match(/^to_/))
61+
return to { send(to_method.post_match, *args, **kw, &block) }
62+
end
63+
64+
expectations.public_send(m, *args, **kw, &block)
6165
self
6266
end
6367

test/test/test_execution_expectations.rb

+12
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ module Test
5454
ret1.should_receive(:filter_result).with(10).and_return(15).once
5555
assert_equal([15, 42], expect_execution.to { [ret1, 42] })
5656
end
57+
58+
it "handles any #to_PREDICATE call for " \
59+
"simpler single-expectation syntax" do
60+
result = expect_execution.to_achieve { 20 }
61+
assert_equal 20, result
62+
end
63+
64+
it "forwards arguments of to_PREDICATE to the predicate" do
65+
plan.add(task = Roby::Task.new)
66+
expect_execution { task.quarantined! }
67+
.to_quarantine(task)
68+
end
5769
end
5870

5971
describe "#verify" do

0 commit comments

Comments
 (0)