Sha256: 45426df6df1e2b5e26ce35e92a037e0ef0fd28f37c73e92a5f18a4cc15ecae31

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

module Similatron
  class ComparisonEngine
    def initialize(executable_path: nil, diffs_path:)
      @given_executable_path = executable_path
      @diffs_path = diffs_path
    end

    def compare(expected:, actual:)
      increase_diff_index

      command = command(expected, actual, diff_path)

      exec_result = run(command)

      Comparison.new(
        expected: expected,
        actual: actual,
        score: score(exec_result),
        diff: diff(exec_result)
      )
    end

    protected

    attr_reader :diffs_path, :diff_index, :given_executable_path

    def run(command)
      exec_info = Open3.capture3(command)
      Open3Result.new(*exec_info)
    end

    def increase_diff_index
      @diff_index ||= 0
      @diff_index += 1
    end

    def diff_path
      File.join(diffs_path, "diff_#{diff_index}.#{diff_extension}")
    end

    def executable_path
      default_executable_path || given_executable_path
    end

    class Open3Result
      attr_reader :out, :err, :status

      def initialize(out, err, status)
        @out = out
        @err = err
        @status = status.exitstatus
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
similatron-0.2.0 lib/similatron/comparison_engine.rb