Skip to content

Commit

Permalink
log relative paths for runtime log
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Nov 8, 2011
1 parent 22f36fb commit bb3f97e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
3 changes: 1 addition & 2 deletions lib/parallel_specs/spec_failures_logger.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'parallel_specs'
require File.join(File.dirname(__FILE__), 'spec_logger_base')
require 'parallel_specs/spec_logger_base'

class ParallelSpecs::SpecFailuresLogger < ParallelSpecs::SpecLoggerBase
def initialize(options, output=nil)
Expand Down
9 changes: 5 additions & 4 deletions lib/parallel_specs/spec_runtime_logger.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'parallel_specs'
require File.join(File.dirname(__FILE__), 'spec_logger_base')
require 'parallel_specs/spec_logger_base'

class ParallelSpecs::SpecRuntimeLogger < ParallelSpecs::SpecLoggerBase
def initialize(options, output=nil)
Expand All @@ -20,9 +19,11 @@ def start_dump(*args)
return unless ENV['TEST_ENV_NUMBER'] #only record when running in parallel
# TODO: Figure out why sometimes time can be less than 0
lock_output do
@output.puts @example_times.map { |file, time| "#{file}:#{time > 0 ? time : 0}" }
@example_times.each do |file, time|
relative_path = file.sub(/^#{Regexp.escape Dir.pwd}\//,'')
@output.puts "#{relative_path}:#{time > 0 ? time : 0}"
end
end
@output.flush
end

end
3 changes: 1 addition & 2 deletions lib/parallel_specs/spec_summary_logger.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'parallel_specs'
require File.join(File.dirname(__FILE__), 'spec_logger_base')
require 'parallel_specs/spec_logger_base'

class ParallelSpecs::SpecSummaryLogger < ParallelSpecs::SpecLoggerBase
def initialize(options, output=nil)
Expand Down
24 changes: 24 additions & 0 deletions spec/parallel_specs/spec_runtime_logger_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'spec_helper'

describe ParallelSpecs::SpecRuntimeLogger do
before do
# pretend we run in parallel or the logger will log nothing
ENV['TEST_ENV_NUMBER'] = ''
end

after do
ENV.delete 'TEST_ENV_NUMBER'
end

it "logs runtime with relative paths" do
Tempfile.open('xxx') do |f|
logger = ParallelSpecs::SpecRuntimeLogger.new(f)
logger.example_started
logger.example_passed(mock(:location => "#{Dir.pwd}/spec/foo.rb:123"))
logger.start_dump

f.close
File.read(f.path).should =~ %r{^spec/foo.rb:0.\d+$}m
end
end
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

FAKE_RAILS_ROOT = '/tmp/pspecs/fixtures'

require 'tempfile'
require 'parallel_specs'
require 'parallel_specs/spec_runtime_logger'
require 'parallel_cucumber'

def mocked_process
Expand Down

0 comments on commit bb3f97e

Please sign in to comment.