Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Format failures through an exception without a message.

When a spec fails because of a fail or raise without a message the output
should not try to include the message.
  • Loading branch information...
commit 19fdd9c676e2f004ba4c2b1c20516e71edcfb83f 1 parent c2a784d
@Manfred Manfred authored
View
21 examples/007_forced_fail_spec.rb
@@ -0,0 +1,21 @@
+# encoding: utf-8
+
+require 'preamble'
+
+describe "The test framework" do
+ it "fails" do
+ fail
+ end
+end
+
+# We need to specs to run now, not at exit because we want to inspect
+# the outcomes.
+
+Peck.run
+
+require 'assert'
+
+event = Peck.all_events[0]
+
+assert(event.exception.class == RuntimeError,
+ "Expected failure event to be a RuntimeError")
View
9 lib/peck/notifiers/default.rb
@@ -28,7 +28,14 @@ def finished_specification(spec)
def write_exeception(number, event)
puts " #{number}) #{event.spec.label}\n\n"
backtrace = clean_backtrace(event.exception.backtrace)
- puts " #{event.exception.message}\n\n\t#{backtrace.join("\n\t")}\n\n"
+
+ parts = []
+ unless event.exception.message.nil? || event.exception.message == ''
+ parts << " #{event.exception.message}"
+ end
+ parts << "\t#{backtrace.join("\n\t")}"
+ parts << nil
+ puts parts.join("\n\n")
end
def write_event(number, event)
View
39 spec/default_notifier_spec.rb
@@ -8,24 +8,47 @@ class FakeSpec < Struct.new(:label)
describe Peck::Notifiers::Default do
before do
+ @notifier = Peck::Notifiers::Default.new
+ end
+
+ it "formats test failures into a readable format" do
+ exception = nil
begin
raise ArgumentError, "Is a good example of what might happen"
rescue => e
- @e = e
+ exception = e
end
- @notifier = Peck::Notifiers::Default.new
- @spec = FakeSpec.new("Event should go on")
- @event = Peck::Event.new(@e, @spec)
- end
- it "formats test failures into a readable format" do
+ spec = FakeSpec.new("Event should go on")
+ event = Peck::Event.new(exception, spec)
+
capture_stdout do
- @notifier.write_event(2, @event)
+ @notifier.write_event(2, event)
end.should == " 2) Event should go on
Is a good example of what might happen
-\tspec/default_notifier_spec.rb:12
+\tspec/default_notifier_spec.rb:17
+
+"
+ end
+
+ it "formats test failures without a message" do
+ exception = nil
+ begin
+ fail
+ rescue => e
+ exception = e
+ end
+
+ spec = FakeSpec.new("Event should go on")
+ event = Peck::Event.new(exception, spec)
+
+ capture_stdout do
+ @notifier.write_event(2, event)
+ end.should == " 2) Event should go on
+
+\tspec/default_notifier_spec.rb:39
"
end
Please sign in to comment.
Something went wrong with that request. Please try again.