@@ -555,6 +555,70 @@ def expect_gc(opts)
555
555
end
556
556
end
557
557
558
+ describe "reporting example_finished" do
559
+ let ( :reporter ) { RSpec ::Core ::Reporter . new ( RSpec ::Core ::Configuration . new ) }
560
+
561
+ def capture_reported_execution_result_for_example ( &block )
562
+ reporter = RSpec ::Core ::Reporter . new ( RSpec ::Core ::Configuration . new )
563
+
564
+ reported_execution_result = nil
565
+
566
+ listener = double ( "Listener" )
567
+ allow ( listener ) . to receive ( :example_finished ) do |notification |
568
+ reported_execution_result = notification . example . execution_result . dup
569
+ end
570
+
571
+ reporter . register_listener ( listener , :example_finished )
572
+
573
+ RSpec . describe do
574
+ it ( &block )
575
+ end . run ( reporter )
576
+
577
+ reported_execution_result
578
+ end
579
+
580
+ it "fills in the execution result details before reporting a passed example as finished" do
581
+ execution_result = capture_reported_execution_result_for_example do
582
+ expect ( 1 ) . to eq 1
583
+ end
584
+
585
+ expect ( execution_result ) . to have_attributes (
586
+ :status => :passed ,
587
+ :exception => nil ,
588
+ :finished_at => a_value_within ( 1 ) . of ( Time . now ) ,
589
+ :run_time => a_value >= 0
590
+ )
591
+ end
592
+
593
+ it "fills in the execution result details before reporting a failed example as finished" do
594
+ execution_result = capture_reported_execution_result_for_example do
595
+ expect ( 1 ) . to eq 2
596
+ end
597
+
598
+ expect ( execution_result ) . to have_attributes (
599
+ :status => :failed ,
600
+ :exception => RSpec ::Expectations ::ExpectationNotMetError ,
601
+ :finished_at => a_value_within ( 1 ) . of ( Time . now ) ,
602
+ :run_time => a_value >= 0
603
+ )
604
+ end
605
+
606
+ it "fills in the execution result details before reporting a pending example as finished" do
607
+ execution_result = capture_reported_execution_result_for_example do
608
+ pending "because"
609
+ expect ( 1 ) . to eq 2
610
+ end
611
+
612
+ expect ( execution_result ) . to have_attributes (
613
+ :status => :pending ,
614
+ :pending_message => "because" ,
615
+ :pending_exception => RSpec ::Expectations ::ExpectationNotMetError ,
616
+ :finished_at => a_value_within ( 1 ) . of ( Time . now ) ,
617
+ :run_time => a_value >= 0
618
+ )
619
+ end
620
+ end
621
+
558
622
describe "#pending" do
559
623
def expect_pending_result ( example )
560
624
expect ( example ) . to be_pending
0 commit comments