Skip to content

Commit

Permalink
doc formatter strips whitespace from group and example descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Jan 30, 2012
1 parent a08eabc commit 7db7f4b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
12 changes: 4 additions & 8 deletions lib/rspec/core/formatters/documentation_formatter.rb
Expand Up @@ -3,9 +3,7 @@
module RSpec
module Core
module Formatters

class DocumentationFormatter < BaseTextFormatter

def initialize(output)
super(output)
@group_level = 0
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -63,9 +61,7 @@ def current_indentation
def example_group_chain
example_group.ancestors.reverse
end

end

end
end
end
24 changes: 23 additions & 1 deletion spec/rspec/core/formatters/documentation_formatter_spec.rb
Expand Up @@ -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 }

Expand Down Expand Up @@ -60,6 +59,29 @@ module RSpec::Core::Formatters
context 2
nested example 2.1
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
Expand Down

0 comments on commit 7db7f4b

Please sign in to comment.