test/unit/view_handler_tests.rb in deas-0.4.1 vs test/unit/view_handler_tests.rb in deas-0.5.0

- old
+ new

@@ -12,78 +12,118 @@ setup do @handler = test_runner(TestViewHandler).handler end subject{ @handler } - should have_instance_methods :init, :init!, :run, :run! - should have_class_methods :before, :before_callbacks - should have_class_methods :after, :after_callbacks - should have_class_methods :before_init, :before_init_callbacks - should have_class_methods :after_init, :after_init_callbacks - should have_class_methods :before_run, :before_run_callbacks - should have_class_methods :after_run, :after_run_callbacks - should have_class_methods :layout, :layouts + should have_imeths :init, :init!, :run, :run! + should have_cmeths :layout, :layouts + should have_cmeths :before, :prepend_before, :before_callbacks + should have_cmeths :after, :prepend_after, :after_callbacks + should have_cmeths :before_init, :prepend_before_init, :before_init_callbacks + should have_cmeths :after_init, :prepend_after_init, :after_init_callbacks + should have_cmeths :before_run, :prepend_before_run, :before_run_callbacks + should have_cmeths :after_run, :prepend_after_run, :after_run_callbacks should "raise a NotImplementedError if run! is not overwritten" do assert_raises(NotImplementedError){ subject.run! } end - should "store procs in #before_callbacks with #before" do - before_proc = proc{ } - TestViewHandler.before(&before_proc) + should "be able to render templates" do + return_value = test_runner(RenderViewHandler).run + assert_equal "my_template", return_value[0] + assert_equal({ :some => :option }, return_value[1]) + end - assert_includes before_proc, TestViewHandler.before_callbacks + should "allow specifying the layouts using #layout or #layouts" do + handler_class = Class.new{ include Deas::ViewHandler } + + handler_class.layout 'layouts/app' + assert_equal [ 'layouts/app' ], handler_class.layouts + + handler_class.layouts 'layouts/web', 'layouts/search' + assert_equal [ 'layouts/web', 'layouts/search' ], handler_class.layouts end - should "store procs in #after_callbacks with #after" do - after_proc = proc{ } - TestViewHandler.after(&after_proc) + end - assert_includes after_proc, TestViewHandler.after_callbacks + class CallbackTests < BaseTests + desc "callbacks" + setup do + @proc1 = proc{ '1' } + @proc2 = proc{ '2' } + @handler = Class.new{ include Deas::ViewHandler } end - should "store procs in #before_init_callbacks with #before_init" do - before_init_proc = proc{ } - TestViewHandler.before_init(&before_init_proc) + should "append procs in #before_callbacks with #before" do + @handler.before(&@proc1); @handler.before(&@proc2) + assert_equal @proc1, @handler.before_callbacks.first + assert_equal @proc2, @handler.before_callbacks.last + end - assert_includes before_init_proc, TestViewHandler.before_init_callbacks + should "prepend procs in #before_callbacks with #before" do + @handler.prepend_before(&@proc1); @handler.prepend_before(&@proc2) + assert_equal @proc2, @handler.before_callbacks.first + assert_equal @proc1, @handler.before_callbacks.last end - should "store procs in #after_init_callbacks with #after_init" do - after_init_proc = proc{ } - TestViewHandler.after_init(&after_init_proc) + should "append procs in #after_callbacks with #after" do + @handler.after(&@proc1); @handler.after(&@proc2) + assert_equal @proc1, @handler.after_callbacks.first + assert_equal @proc2, @handler.after_callbacks.last + end - assert_includes after_init_proc, TestViewHandler.after_init_callbacks + should "prepend procs in #after_callbacks with #before" do + @handler.prepend_after(&@proc1); @handler.prepend_after(&@proc2) + assert_equal @proc2, @handler.after_callbacks.first + assert_equal @proc1, @handler.after_callbacks.last end - should "store procs in #before_run_callbacks with #before_run" do - before_run_proc = proc{ } - TestViewHandler.before_run(&before_run_proc) + should "append procs in #before_init_callbacks with #before_init" do + @handler.before_init(&@proc1); @handler.before_init(&@proc2) + assert_equal @proc1, @handler.before_init_callbacks.first + assert_equal @proc2, @handler.before_init_callbacks.last + end - assert_includes before_run_proc, TestViewHandler.before_run_callbacks + should "prepend procs in #before_init_callbacks with #before" do + @handler.prepend_before_init(&@proc1); @handler.prepend_before_init(&@proc2) + assert_equal @proc2, @handler.before_init_callbacks.first + assert_equal @proc1, @handler.before_init_callbacks.last end - should "store procs in #after_run_callbacks with #after_run" do - after_run_proc = proc{ } - TestViewHandler.after_run(&after_run_proc) + should "append procs in #after_init_callbacks with #after_init" do + @handler.after_init(&@proc1); @handler.after_init(&@proc2) + assert_equal @proc1, @handler.after_init_callbacks.first + assert_equal @proc2, @handler.after_init_callbacks.last + end - assert_includes after_run_proc, TestViewHandler.after_run_callbacks + should "prepend procs in #after_init_callbacks with #before" do + @handler.prepend_after_init(&@proc1); @handler.prepend_after_init(&@proc2) + assert_equal @proc2, @handler.after_init_callbacks.first + assert_equal @proc1, @handler.after_init_callbacks.last end - should "allow specifying the layouts using #layout or #layouts" do - handler_class = Class.new{ include Deas::ViewHandler } + should "append procs in #before_run_callbacks with #before_run" do + @handler.before_run(&@proc1); @handler.before_run(&@proc2) + assert_equal @proc1, @handler.before_run_callbacks.first + assert_equal @proc2, @handler.before_run_callbacks.last + end - handler_class.layout 'layouts/app' - assert_equal [ 'layouts/app' ], handler_class.layouts + should "prepend procs in #before_run_callbacks with #before" do + @handler.prepend_before_run(&@proc1); @handler.prepend_before_run(&@proc2) + assert_equal @proc2, @handler.before_run_callbacks.first + assert_equal @proc1, @handler.before_run_callbacks.last + end - handler_class.layouts 'layouts/web', 'layouts/search' - assert_equal [ 'layouts/web', 'layouts/search' ], handler_class.layouts + should "append procs in #after_run_callbacks with #after_run" do + @handler.after_run(&@proc1); @handler.after_run(&@proc2) + assert_equal @proc1, @handler.after_run_callbacks.first + assert_equal @proc2, @handler.after_run_callbacks.last end - should "be able to render templates" do - return_value = test_runner(RenderViewHandler).run - assert_equal "my_template", return_value[0] - assert_equal({ :some => :option }, return_value[1]) + should "prepend procs in #after_run_callbacks with #before" do + @handler.prepend_after_run(&@proc1); @handler.prepend_after_run(&@proc2) + assert_equal @proc2, @handler.after_run_callbacks.first + assert_equal @proc1, @handler.after_run_callbacks.last end end class WithMethodFlagsTests < BaseTests