spec/fault_injection_spec.rb in faultinjection-0.0.1 vs spec/fault_injection_spec.rb in faultinjection-0.0.2

- old
+ new

@@ -1,21 +1,20 @@ require File.dirname(__FILE__) + '/spec_helper.rb' require 'fault_injection.rb' -include FaultInjection $LOAD_PATH << File.dirname(__FILE__) describe "Argument Checking" do it "raises if a line number is less than 0" do Proc.new{ - inject_fault({:file => 'target_00.rb',:line => -5}) + FaultInjection.inject({:file => 'target_00.rb',:line => -5}).should be_true }.should raise_error(ArgumentError) end it "raises if a err_class is not a subclass of Exception" do Proc.new { - inject_fault({:file => 'target_00.rb',:line => 1}, 3) + FaultInjection.inject({:file => 'target_00.rb',:line => 1}, 3).should be_true }.should raise_error(ArgumentError) end end describe "'File & line' fault-injection." do @@ -25,11 +24,11 @@ clear end it "works on Hash format for file & line specification" do Proc.new{ target_func_00 }.should_not raise_error - inject_fault({:file => 'target_00.rb', :line => 9}) + FaultInjection.inject({:file => 'target_00.rb', :line => 9}).should be_true begin target_func_00 violate "target_func_00 must raise RuntimeError" rescue @@ -42,11 +41,13 @@ end it "works on 'file:line' format injection command." do Proc.new{ target_func_00 }.should_not raise_error - inject_fault "target_00.rb:9", SecurityError, "This is a error" + FaultInjection.inject("target_00.rb:9", + SecurityError, + "This is a error").should be_true Proc.new{ target_func_00 }.should raise_error(SecurityError,"This is a error") end @@ -60,27 +61,28 @@ end it "should check arguments in Array format command." do Proc.new{ Bar.new.bar }.should_not raise_error - Proc.new{ inject_fault([]) }.should raise_error(ArgumentError) - Proc.new{ inject_fault([:Array]) }.should raise_error(ArgumentError) + Proc.new{ FaultInjection.inject([]) }.should raise_error(ArgumentError) + Proc.new{ FaultInjection.inject([:Array]) }.should raise_error(ArgumentError) end it "should inject faults properly with Array format command" do Proc.new{ Bar.new.bar }.should_not raise_error # raise on method calling chane, "Bar#bar --> Foo#foo" - inject_fault [:Bar,:bar,:Foo,:foo],RangeError + FaultInjection.inject([:Bar,:bar,:Foo,:foo],RangeError).should be_true Proc.new{ Bar.new.bar }.should raise_error(RangeError) end end describe "Specifying Exception class" do require 'target_01.rb' it "can inject fault with specified Exception class" do - inject_fault({:file => 'target_01.rb', :line => 3},ArgumentError) + include FaultInjection + inject({:file => 'target_01.rb', :line => 3},ArgumentError).should be_true Proc.new{ target_func_01 }.should raise_error(ArgumentError) clear end