Sha256: 466c7c12cb2355cb2fab0b5f5d27d562025e0b0de61200a6015ab69c3c98b9d4

Contents?: true

Size: 1.13 KB

Versions: 30

Compression:

Stored size: 1.13 KB

Contents

class ParallelCucumber
  class RuntimeLogger

    def initialize(step_mother, path_or_io, options=nil)
      @io = prepare_io(path_or_io)
      @example_times = Hash.new(0)
    end

    def before_feature(_)
      @start_at = Time.now.to_f
    end

    def after_feature(feature)
      @example_times[feature.file] += Time.now.to_f - @start_at
    end

    def after_features(*args)
      lock_output do
        @io.puts @example_times.map { |file, time| "#{file}:#{time}" }
      end
    end

    private

    def prepare_io(path_or_io)
      if path_or_io.respond_to?(:write)
        path_or_io
      else # its a path
        File.open(path_or_io, 'w').close # clean out the file
        file = File.open(path_or_io, 'a')

        at_exit do
          unless file.closed?
            file.flush
            file.close
          end
        end

        file
      end
    end

    # do not let multiple processes get in each others way
    def lock_output
      if File === @io
        begin
          @io.flock File::LOCK_EX
          yield
        ensure
          @io.flock File::LOCK_UN
        end
      else
        yield
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 3 rubygems

Version Path
parallel_tests-0.6.20 lib/parallel_cucumber/runtime_logger.rb
parallel_tests-instructure-0.6.19 lib/parallel_cucumber/runtime_logger.rb
parallel_tests-0.6.19 lib/parallel_cucumber/runtime_logger.rb
parallel_tests-0.6.18 lib/parallel_cucumber/runtime_logger.rb
parallel_tests-instructure-0.6.18 lib/parallel_cucumber/runtime_logger.rb
parallel_tests-0.6.17 lib/parallel_cucumber/runtime_logger.rb
parallel_tests-instructure-0.6.17 lib/parallel_cucumber/runtime_logger.rb
parallel_tests-instructure-0.6.16 lib/parallel_cucumber/runtime_logger.rb
parallel_tests-0.6.16 lib/parallel_cucumber/runtime_logger.rb
parallel_tests-0.6.15 lib/parallel_cucumber/runtime_logger.rb
parallel_tests-0.6.14 lib/parallel_cucumber/runtime_logger.rb
parallel_tests-0.6.13 lib/parallel_cucumber/runtime_logger.rb
parallel_tests-0.6.12 lib/parallel_cucumber/runtime_logger.rb
parallel_tests-0.6.11 lib/parallel_cucumber/runtime_logger.rb
parallel_tests-0.6.10 lib/parallel_cucumber/runtime_logger.rb
parallel_tests-0.6.9 lib/parallel_cucumber/runtime_logger.rb
parallel_tests-0.6.8 lib/parallel_cucumber/runtime_logger.rb
parallel_tests-0.6.7 lib/parallel_cucumber/runtime_logger.rb
parallel_tests-0.6.6 lib/parallel_cucumber/runtime_logger.rb
parallel_tests-0.6.5 lib/parallel_cucumber/runtime_logger.rb