Skip to content

Launching test at specific line #154

@alain-andre

Description

@alain-andre

I have created a class returning the file and the first changed line based on git. I want to launch the test of the file at only this line.

class GitModifiedMatcher
  class MyMatchData
    def initialize(result)
      @result = result
    end

    def to_a
      @result.values
    end

    def [](name)
      @result[name]
    end
  end

  def match(file)
    diff = `git diff --no-ext-diff --unified=0 --exit-code -a --no-prefix #{file}`
    modified_lines = diff.to_enum(:scan, /^@@ -\d+,?.* [+](\d+),?.* @@.*/).map { Regexp.last_match(1) }

    MyMatchData.new(file: file, lines: modified_lines.first)
  end
end

So in my Guardfile I am able to do something like this (notice the m[:file] and m[:line]) :

guard :minitest, all_on_start: false do
  watch(GitModifiedMatcher.new) { |m| "#{m[:file]} --line #{m[:line]}" }
end

I could not find a way to make it. Anyone can help ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions