Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

doc formatter strips whitespace from group and example descriptions

  • Loading branch information...
commit 7db7f4bc0e26af76292c2709284e2f13f61d09ff 1 parent a08eabc
David Chelimsky dchelimsky authored
12 lib/rspec/core/formatters/documentation_formatter.rb
View
@@ -3,9 +3,7 @@
module RSpec
module Core
module Formatters
-
class DocumentationFormatter < BaseTextFormatter
-
def initialize(output)
super(output)
@group_level = 0
@@ -15,7 +13,7 @@ def example_group_started(example_group)
super(example_group)
output.puts if @group_level == 0
- output.puts "#{current_indentation}#{example_group.description}"
+ output.puts "#{current_indentation}#{example_group.description.strip}"
@group_level += 1
end
@@ -40,7 +38,7 @@ def example_failed(example)
end
def failure_output(example, exception)
- red("#{current_indentation}#{example.description} (FAILED - #{next_failure_index})")
+ red("#{current_indentation}#{example.description.strip} (FAILED - #{next_failure_index})")
end
def next_failure_index
@@ -49,11 +47,11 @@ def next_failure_index
end
def passed_output(example)
- green("#{current_indentation}#{example.description}")
+ green("#{current_indentation}#{example.description.strip}")
end
def pending_output(example, message)
- yellow("#{current_indentation}#{example.description} (PENDING: #{message})")
+ yellow("#{current_indentation}#{example.description.strip} (PENDING: #{message})")
end
def current_indentation
@@ -63,9 +61,7 @@ def current_indentation
def example_group_chain
example_group.ancestors.reverse
end
-
end
-
end
end
end
24 spec/rspec/core/formatters/documentation_formatter_spec.rb
View
@@ -28,7 +28,6 @@ module RSpec::Core::Formatters
end
it "represents nested group using hierarchy tree" do
-
output = StringIO.new
RSpec.configuration.stub(:color_enabled?) { false }
@@ -62,5 +61,28 @@ module RSpec::Core::Formatters
nested example 2.2
")
end
+
+ it "strips whitespace for each row" do
+ output = StringIO.new
+ RSpec.configuration.stub(:color_enabled?) { false }
+
+ formatter = RSpec::Core::Formatters::DocumentationFormatter.new(output)
+
+ group = RSpec::Core::ExampleGroup.describe(" root ")
+ context1 = group.describe(" nested ")
+ context1.example(" example 1 ") {}
+ context1.example(" example 2 ", :pending => true){}
+ context1.example(" example 3 ") { fail }
+
+ group.run(RSpec::Core::Reporter.new(formatter))
+
+ output.string.should eql("
+root
+ nested
+ example 1
+ example 2 (PENDING: No reason given)
+ example 3 (FAILED - 1)
+")
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.