Sha256: 3c9933a244e6efa178866de439c87d8c0ce737be7bb82ce799f5d9b9e3788344

Contents?: true

Size: 1.62 KB

Versions: 15

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

module RSpecTracer
  module Example
    module_function

    def from(example)
      data = {
        example_group: example.example_group.name,
        description: example.description,
        full_description: example.full_description,
        shared_group: example.metadata[:shared_group_inclusion_backtrace]
          .map(&:formatted_inclusion_location)
      }.merge(example_location(example))

      data.merge(example_id: Digest::MD5.hexdigest(data.to_json))
    end

    def example_location(example)
      metadata = example.metadata

      location = {
        file_name: location_file_name(metadata[:file_path]),
        line_number: metadata[:line_number]
      }

      if metadata[:file_path] == metadata[:rerun_file_path]
        return location.merge(
          rerun_file_name: location[:file_name],
          rerun_line_number: location[:line_number]
        )
      end

      location.merge(example_rerun_location(example.example_group.parent_groups))
    end

    def example_rerun_location(example_groups)
      example_groups.each do |example_group|
        metadata = example_group.metadata

        next unless metadata[:file_path] == metadata[:rerun_file_path]

        return {
          rerun_file_name: location_file_name(metadata[:file_path]),
          rerun_line_number: metadata[:line_number]
        }
      end
    end

    def location_file_name(rspec_file_name)
      file_path = RSpecTracer::SourceFile.file_path(rspec_file_name)

      RSpecTracer::SourceFile.file_name(file_path)
    end

    private_class_method :example_location, :example_rerun_location, :location_file_name
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rspec-tracer-1.0.0 lib/rspec_tracer/example.rb
rspec-tracer-0.9.3 lib/rspec_tracer/example.rb
rspec-tracer-0.9.2 lib/rspec_tracer/example.rb
rspec-tracer-0.9.1 lib/rspec_tracer/example.rb
rspec-tracer-0.9.0 lib/rspec_tracer/example.rb
rspec-tracer-0.8.0 lib/rspec_tracer/example.rb
rspec-tracer-0.7.0 lib/rspec_tracer/example.rb
rspec-tracer-0.6.2 lib/rspec_tracer/example.rb
rspec-tracer-0.6.1 lib/rspec_tracer/example.rb
rspec-tracer-0.6.0 lib/rspec_tracer/example.rb
rspec-tracer-0.5.0 lib/rspec_tracer/example.rb
rspec-tracer-0.4.0 lib/rspec_tracer/example.rb
rspec-tracer-0.3.0 lib/rspec_tracer/example.rb
rspec-tracer-0.2.0 lib/rspec_tracer/example.rb
rspec-tracer-0.1.0 lib/rspec_tracer/example.rb