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 RSpec
module Core module Core
module Formatters module Formatters

class DocumentationFormatter < BaseTextFormatter class DocumentationFormatter < BaseTextFormatter

def initialize(output) def initialize(output)
super(output) super(output)
@group_level = 0 @group_level = 0
Expand All @@ -15,7 +13,7 @@ def example_group_started(example_group)
super(example_group) super(example_group)


output.puts if @group_level == 0 output.puts if @group_level == 0
output.puts "#{current_indentation}#{example_group.description}" output.puts "#{current_indentation}#{example_group.description.strip}"


@group_level += 1 @group_level += 1
end end
Expand All @@ -40,7 +38,7 @@ def example_failed(example)
end end


def failure_output(example, exception) 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 end


def next_failure_index def next_failure_index
Expand All @@ -49,11 +47,11 @@ def next_failure_index
end end


def passed_output(example) def passed_output(example)
green("#{current_indentation}#{example.description}") green("#{current_indentation}#{example.description.strip}")
end end


def pending_output(example, message) def pending_output(example, message)
yellow("#{current_indentation}#{example.description} (PENDING: #{message})") yellow("#{current_indentation}#{example.description.strip} (PENDING: #{message})")
end end


def current_indentation def current_indentation
Expand All @@ -63,9 +61,7 @@ def current_indentation
def example_group_chain def example_group_chain
example_group.ancestors.reverse example_group.ancestors.reverse
end end

end end

end 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 end


it "represents nested group using hierarchy tree" do it "represents nested group using hierarchy tree" do

output = StringIO.new output = StringIO.new
RSpec.configuration.stub(:color_enabled?) { false } RSpec.configuration.stub(:color_enabled?) { false }


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

0 comments on commit 7db7f4b

Please sign in to comment.