Skip to content

Commit

Permalink
small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Nov 25, 2010
1 parent 46f0d49 commit 190f8c8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/rspec/core/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def self.delegate_to_metadata(*keys)
end
end

delegate_to_metadata :description, :full_description, :execution_result, :file_path, :pending
delegate_to_metadata :description, :full_description, :execution_result, :file_path, :pending, :location

def initialize(example_group_class, desc, options, example_block=nil)
@example_group_class, @options, @example_block = example_group_class, options, example_block
Expand Down
73 changes: 43 additions & 30 deletions lib/rspec/core/formatters/base_text_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,9 @@ def dump_failures
output.puts
output.puts "Failures:"
failed_examples.each_with_index do |example, index|
output.puts if index > 0
exception = example.execution_result[:exception_encountered]
short_padding = ' '
padding = ' '
if exception.is_a?(RSpec::Core::PendingExampleFixedError)
output.puts "#{short_padding}#{index.next}) #{example.full_description} FIXED"
output.puts "#{padding}Expected pending '#{example.metadata[:execution_result][:pending_message]}' to fail. No Error was raised."
else
output.puts "#{short_padding}#{index.next}) #{example.full_description}"
output.puts "#{padding}#{red("Failure/Error:")} #{red(read_failed_line(exception, example).strip)}"
exception.message.split("\n").each do |line|
output.puts "#{padding}#{red(line)}"
end

example.example_group.ancestors.push(example.example_group).each do |group|
if group.metadata[:shared_group_name]
output.puts "#{padding}Shared Example Group: \"#{group.metadata[:shared_group_name]}\" called from " +
"#{backtrace_line(group.metadata[:example_group][:location])}"
break
end
end
end

format_backtrace(exception.backtrace, example).each do |backtrace_info|
output.puts grey("#{padding}# #{backtrace_info}")
end
output.puts
dump_pending_example_fixed(example, index) || dump_failure(example, index)
dump_backtrace(example)
end
end

Expand Down Expand Up @@ -69,7 +46,7 @@ def dump_profile
output.puts "\nTop #{sorted_examples.size} slowest examples:\n"
sorted_examples.each do |example|
output.puts " #{example.full_description}"
output.puts grey(" #{red(format_seconds(example.execution_result[:run_time]))} #{red("seconds")} #{format_caller(example.metadata[:location])}")
output.puts grey(" #{red(format_seconds(example.execution_result[:run_time]))} #{red("seconds")} #{format_caller(example.location)}")
end
end

Expand All @@ -86,8 +63,8 @@ def dump_pending
output.puts "Pending:"
pending_examples.each do |pending_example|
output.puts yellow(" #{pending_example.full_description}")
output.puts grey(" # #{pending_example.metadata[:execution_result][:pending_message]}")
output.puts grey(" # #{format_caller(pending_example.metadata[:location])}")
output.puts grey(" # #{pending_example.execution_result[:pending_message]}")
output.puts grey(" # #{format_caller(pending_example.location)}")
end
end
end
Expand Down Expand Up @@ -134,6 +111,14 @@ def grey(text)
color(text, "\e[90m")
end

def short_padding
' '
end

def long_padding
' '
end

private

def pluralize(count, string)
Expand All @@ -144,8 +129,36 @@ def format_caller(caller_info)
backtrace_line(caller_info.to_s.split(':in `block').first)
end

end
def dump_backtrace(example)
format_backtrace(example.execution_result[:exception_encountered].backtrace, example).each do |backtrace_info|
output.puts grey("#{long_padding}# #{backtrace_info}")
end
end

def dump_pending_example_fixed(example, index)
if RSpec::Core::PendingExampleFixedError === example.execution_result[:exception_encountered]
output.puts "#{short_padding}#{index.next}) #{example.full_description} FIXED"
output.puts blue("#{long_padding}Expected pending '#{example.metadata[:execution_result][:pending_message]}' to fail. No Error was raised.")
true
end
end

def dump_failure(example, index)
exception = example.execution_result[:exception_encountered]
output.puts "#{short_padding}#{index.next}) #{example.full_description}"
output.puts "#{long_padding}#{red("Failure/Error:")} #{red(read_failed_line(exception, example).strip)}"
exception.message.split("\n").each { |line| output.puts "#{long_padding}#{red(line)}" }

example.example_group.ancestors.push(example.example_group).each do |group|
if group.metadata[:shared_group_name]
output.puts "#{long_padding}Shared Example Group: \"#{group.metadata[:shared_group_name]}\" called from " +
"#{backtrace_line(group.metadata[:example_group][:location])}"
break
end
end
end

end
end
end
end

0 comments on commit 190f8c8

Please sign in to comment.