Sha256: ab454bbe86a36c42c98d82da55b43b25d3ed76f285c113a033ec3c4d8f2b6cd7

Contents?: true

Size: 933 Bytes

Versions: 5362

Compression:

Stored size: 933 Bytes

Contents

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

5,362 entries across 5,272 versions & 126 rubygems

Version Path
cybrid_api_bank_ruby-0.113.108 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/hunk_generator.rb
cybrid_api_organization_ruby-0.113.108 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/hunk_generator.rb
cybrid_api_id_ruby-0.113.108 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/hunk_generator.rb
cybrid_api_bank_ruby-0.113.106 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/hunk_generator.rb
cybrid_api_id_ruby-0.113.106 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/hunk_generator.rb
ory-client-1.5.2 vendor/bundle/ruby/2.5.0/gems/rspec-support-3.12.1/lib/rspec/support/hunk_generator.rb
cybrid_api_organization_ruby-0.113.105 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/hunk_generator.rb
cybrid_api_bank_ruby-0.113.105 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/hunk_generator.rb
cybrid_api_id_ruby-0.113.105 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/hunk_generator.rb
cybrid_api_bank_ruby-0.113.104 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/hunk_generator.rb
cybrid_api_id_ruby-0.113.104 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/hunk_generator.rb
cybrid_api_organization_ruby-0.113.104 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/hunk_generator.rb
cybrid_api_id_ruby-0.113.103 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/hunk_generator.rb
cybrid_api_bank_ruby-0.113.103 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/hunk_generator.rb
cybrid_api_organization_ruby-0.113.103 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/hunk_generator.rb
cybrid_api_bank_ruby-0.113.101 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/hunk_generator.rb
cybrid_api_id_ruby-0.113.101 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/hunk_generator.rb
cybrid_api_organization_ruby-0.113.101 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/hunk_generator.rb
cybrid_api_bank_ruby-0.113.100 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/hunk_generator.rb
cybrid_api_id_ruby-0.113.100 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.12.1/lib/rspec/support/hunk_generator.rb