Permalink
Browse files

Notify output handlers when an expectation failed.

  • Loading branch information...
1 parent 9e3264f commit 60ad0dae19bd8ebac4d3974f5c3441ed40188f8d @jellybob jellybob committed Jul 24, 2011
Showing with 26 additions and 5 deletions.
  1. +6 −1 lib/critical/metric_base.rb
  2. +2 −2 lib/critical/output_handler/base.rb
  3. +18 −2 spec/unit/metric_base_spec.rb
@@ -360,7 +360,12 @@ def track(what)
def expect(status_on_failure=nil, &block)
status_on_failure ||= :critical
begin
- update_status(status_on_failure) unless instance_eval(&block)
+ if instance_eval(&block)
+ report.expectation_succeeded
+ else
+ update_status(status_on_failure)
+ report.expectation_failed
+ end
rescue Exception => e
update_status(status_on_failure)
end
@@ -43,10 +43,10 @@ def collection_failed(error, message=nil, trace=nil)
def processing_failed(error, message=nil, trace=nil)
end
- def expectation_failed(error, message=nil, trace=nil)
+ def expectation_failed(error=nil, message=nil, trace=nil)
end
- def expectation_succeeded(error, message=nil, trace=nil)
+ def expectation_succeeded(error=nil, message=nil, trace=nil)
end
def collection_completed(*args)
@@ -250,7 +250,7 @@ def index
@metric_spec.processing_block = Proc.new { 'here I come' }
@metric.processing_block.call.should == 'here I come'
end
-
+
it "passes itself into the handler block if a block with arity 1 is given" do
@metric_class.collects { :some_data }
@metric_spec.processing_block = Proc.new { |m| m.snitch= :yoshitoshi}
@@ -391,14 +391,30 @@ def @metric.string_to_echo
@metric.result
end
+ describe "reporting on expectations" do
+
+ it "notifies the output handler when an expectation fails" do
+ @output_handler.should_receive(:expectation_failed)
+ @metric_spec.processing_block = Proc.new { expect {false} }
+ @metric.collect(@output_handler, @trending_handler)
+ end
+
+ it "notifies the output handler when an expectation succeeds" do
+ @output_handler.should_receive(:expectation_succeeded)
+ @metric_spec.processing_block = Proc.new { expect {true} }
+ @metric.collect(@output_handler, @trending_handler)
+ end
+
+ end
+
describe "classifying the state of the monitored property" do
it "reports expectation failures as critical" do
@metric_spec.processing_block = Proc.new { expect {false} }
@metric.collect(@output_handler, @trending_handler)
@metric.metric_status.should == :critical
end
-
+
it "reports expectation failures as warning when given :warning as the argument" do
@metric_spec.processing_block = Proc.new { expect(:warning) {false} }
@metric.collect(@output_handler, @trending_handler)

0 comments on commit 60ad0da

Please sign in to comment.