Permalink
Browse files

Adding tests for subclassing Staged.

  • Loading branch information...
1 parent 1b793cb commit 216960a05645045600fc330cf3704dd9104ca023 @JEG2 committed Apr 19, 2009
Showing with 49 additions and 2 deletions.
  1. +49 −2 test/test_staged.rb
View
@@ -35,12 +35,59 @@ def test_finished_sets_finished_with_or_without_code
assert_stage_flagged_with_and_without_code(:finish)
end
+ ######################
+ ### Adding a Stage ###
+ ######################
+
+ def test_forwarding_to_load_or_run_adds_a_stage
+ test_staged = subclass do
+ def test(&code)
+ load_or_run(:test, &code)
+ end
+
+ private
+
+ def run_test_code
+ @test_code[]
+ end
+ end
+ flag = :ran_test_code
+ staged(test_staged) do |s|
+ s.test { flag }
+ end
+ assert_equal(flag, @staged.test)
+ end
+
+ def test_a_stage_can_support_arguments_when_run
+ test_args_staged = subclass do
+ def test_with_args(*args, &code)
+ load_or_run(:test_with_args, *args, &code)
+ end
+
+ private
+
+ def run_test_with_args_code(*args)
+ @test_with_args_code[*args]
+ end
+ end
+ staged(test_args_staged) do |s|
+ s.test_with_args { |*args| args }
+ end
+ assert_equal([ ], @staged.test_with_args)
+ assert_equal([1], @staged.test_with_args(1))
+ assert_equal([1, 2], @staged.test_with_args(1, 2))
+ end
+
#######
private
#######
- def staged(&init)
- @staged = Mungr::Staged.new(&init)
+ def staged(staged_class = Mungr::Staged, &init)
+ @staged = staged_class.new(&init)
+ end
+
+ def subclass(&class_def)
+ Class.new(Mungr::Staged, &class_def)
end
def assert_stage_sets_or_runs_code(stage)

0 comments on commit 216960a

Please sign in to comment.