Skip to content
Browse files

Pluralize/singularize summary line

Closes #36.
  • Loading branch information...
1 parent bed699b commit 0e850f757580d54df8f669f4790aa661a6f841fa @dchelimsky dchelimsky committed
View
14 lib/rspec/core/formatters/base_text_formatter.rb
@@ -42,8 +42,7 @@ def dump_summary
output.puts "\nFinished in #{format_seconds(duration)} seconds\n"
- summary = "#{example_count} example#{'s' unless example_count == 1}, #{failure_count} failures"
- summary << ", #{pending_count} pending" if pending_count > 0
+ summary = summary_line(example_count, failure_count, pending_count)
if failure_count == 0
if pending_count > 0
@@ -68,6 +67,17 @@ def dump_summary
output.flush
end
+ def summary_line(example_count, failure_count, pending_count)
+ summary = pluralize(example_count, "example")
+ summary << ", " << pluralize(failure_count, "failure")
+ summary << ", #{pending_count} pending" if pending_count > 0
+ summary
+ end
+
+ def pluralize(count, string)
+ "#{count} #{string}#{'s' unless count == 1}"
+ end
+
def format_caller(caller_info)
caller_info.to_s.split(':in `block').first
end
View
23 spec/rspec/core/formatters/base_text_formatter_spec.rb
@@ -3,6 +3,29 @@
module RSpec::Core::Formatters
describe BaseTextFormatter do
+ describe "#summary_line" do
+ let(:output) { StringIO.new }
+ let(:formatter) { RSpec::Core::Formatters::BaseTextFormatter.new(output) }
+
+ context "with 0s" do
+ it "outputs pluralized (excluding pending)" do
+ formatter.summary_line(0,0,0).should eq("0 examples, 0 failures")
+ end
+ end
+
+ context "with 1s" do
+ it "outputs singular (including pending)" do
+ formatter.summary_line(1,1,1).should eq("1 example, 1 failure, 1 pending")
+ end
+ end
+
+ context "with 2s" do
+ it "outputs pluralized (including pending)" do
+ formatter.summary_line(2,2,2).should eq("2 examples, 2 failures, 2 pending")
+ end
+ end
+ end
+
describe "#dump_failures" do
it "preserves formatting" do
output = StringIO.new

0 comments on commit 0e850f7

Please sign in to comment.
Something went wrong with that request. Please try again.