Sha256: ca613ccc87ff81f537ccf3986dedb0999a49e611d6bef3f2ea8a10f1bafae276

Contents?: true

Size: 964 Bytes

Versions: 2056

Compression:

Stored size: 964 Bytes

Contents

# frozen_string_literal: true

require 'diff/lcs'
require 'diff/lcs/hunk'

module RSpec
  module Support
    # @private
    class HunkGenerator
      def initialize(actual, expected)
        @actual = actual
        @expected = expected
      end

      def hunks
        @file_length_difference = 0
        @hunks ||= diffs.map do |piece|
          build_hunk(piece)
        end
      end

    private

      def diffs
        Diff::LCS.diff(expected_lines, actual_lines)
      end

      def expected_lines
        @expected.split("\n").map! { |e| e.chomp }
      end

      def actual_lines
        @actual.split("\n").map! { |e| e.chomp }
      end

      def build_hunk(piece)
        Diff::LCS::Hunk.new(
          expected_lines, actual_lines, piece, context_lines, @file_length_difference
        ).tap do |h|
          @file_length_difference = h.file_length_difference
        end
      end

      def context_lines
        3
      end
    end
  end
end

Version data entries

2,056 entries across 2,055 versions & 17 rubygems

Version Path
cybrid_api_id_ruby-0.123.179 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/hunk_generator.rb
cybrid_api_organization_ruby-0.123.179 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/hunk_generator.rb
cybrid_api_organization_ruby-0.123.177 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/hunk_generator.rb
cybrid_api_id_ruby-0.123.177 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/hunk_generator.rb
cybrid_api_organization_ruby-0.123.176 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/hunk_generator.rb
cybrid_api_id_ruby-0.123.176 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/hunk_generator.rb
cybrid_api_organization_ruby-0.123.175 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/hunk_generator.rb
cybrid_api_id_ruby-0.123.175 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/hunk_generator.rb
cybrid_api_id_ruby-0.123.174 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/hunk_generator.rb
cybrid_api_organization_ruby-0.123.174 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/hunk_generator.rb
cybrid_api_id_ruby-0.123.173 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/hunk_generator.rb
cybrid_api_organization_ruby-0.123.173 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/hunk_generator.rb
ory-client-1.16.3 vendor/bundle/ruby/3.1.0/gems/rspec-support-3.13.2/lib/rspec/support/hunk_generator.rb
cybrid_api_organization_ruby-0.123.172 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/hunk_generator.rb
cybrid_api_id_ruby-0.123.172 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/hunk_generator.rb
cybrid_api_id_ruby-0.123.171 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/hunk_generator.rb
cybrid_api_organization_ruby-0.123.171 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/hunk_generator.rb
cybrid_api_id_ruby-0.123.170 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/hunk_generator.rb
cybrid_api_organization_ruby-0.123.170 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/hunk_generator.rb
cybrid_api_organization_ruby-0.123.163 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/hunk_generator.rb