test/busted_test.rb in busted-0.1.0 vs test/busted_test.rb in busted-0.2.0

- old
+ new

@@ -6,10 +6,17 @@ Busted.run profiler: :pizza end assert_equal "profiler `pizza' does not exist", error.message end + def test_invalid_profiler_action_exception + error = assert_raises ArgumentError do + Busted.start profiler: :sandwich, action: :pizza + end + assert_equal "profiler requires start or finish action", error.message + end + def test_cache_invalidations_requires_block assert_raises LocalJumpError do Busted.run end end @@ -52,10 +59,18 @@ def test_constant_cache_invalidations_with_addition assert_equal 0, Busted.constant_cache_invalidations { 1 + 1 } end + def test_start_finish_with_addition + Busted.start + 1 + 1 + report = Busted.finish + assert_equal 0, report[:invalidations][:method] + assert_equal 0, report[:invalidations][:constant] + end + def test_cache_invalidations_with_new_constant report = Busted.run { self.class.const_set :"CHEESE", "cheese" } assert_equal 0, report[:invalidations][:method] assert_equal 1, report[:invalidations][:constant] end @@ -72,10 +87,18 @@ self.class.const_set :"VEGETABLE", "vegetable" end assert_equal 1, invalidations end + def test_start_finish_with_new_constant + Busted.start + self.class.const_set :"PEPPERONI", "pepperoni" + report = Busted.finish + assert_equal 0, report[:invalidations][:method] + assert_equal 1, report[:invalidations][:constant] + end + def test_cache_invalidations_with_new_method report = Busted.run { Object.class_exec { def cheese; end } } assert_equal 1, report[:invalidations][:method] assert_equal 0, report[:invalidations][:constant] end @@ -92,10 +115,18 @@ Object.class_exec { def vegetable; end } end assert_equal 0, invalidations end + def test_start_finish_with_new_method + Busted.start + Object.class_exec { def pepperoni; end } + report = Busted.finish + assert_equal 1, report[:invalidations][:method] + assert_equal 0, report[:invalidations][:constant] + end + def test_cache_invalidations_with_new_class report = Busted.run { Object.class_eval "class ThreeCheese; end" } assert_equal 0, report[:invalidations][:method] assert_equal 1, report[:invalidations][:constant] end @@ -112,10 +143,18 @@ Object.class_eval "class Veggie; end" end assert_equal 1, invalidations end + def test_start_finish_with_new_class + Busted.start + Object.class_eval "class Pepperoni; end" + report = Busted.finish + assert_equal 0, report[:invalidations][:method] + assert_equal 1, report[:invalidations][:constant] + end + def test_cache_predicate_requires_block assert_raises LocalJumpError do Busted.cache? end end @@ -198,10 +237,21 @@ report = Busted.run(trace: true) { Object.class_exec { def cookie; end } } assert_equal 1, report[:invalidations][:method] assert_equal 0, report[:invalidations][:constant] assert_equal "global", report[:traces][:method][0][:class] assert_match /test\/busted_test.rb\z/, report[:traces][:method][0][:sourcefile] - assert_equal "198", report[:traces][:method][0][:lineno] + assert_equal "237", report[:traces][:method][0][:lineno] + end + + def test_start_finish_and_traces_with_new_method + Busted.start trace: true + Object.class_exec { def candy; end } + report = Busted.finish + assert_equal 1, report[:invalidations][:method] + assert_equal 0, report[:invalidations][:constant] + assert_equal "global", report[:traces][:method][0][:class] + assert_match /test\/busted_test.rb\z/, report[:traces][:method][0][:sourcefile] + assert_equal "247", report[:traces][:method][0][:lineno] end end def test_trace_without_root_privileges Busted::Tracer.stub :exists?, true do