Skip to content

Instantly share code, notes, and snippets.

@gaetanm
Created September 14, 2018 15:29
Show Gist options
  • Save gaetanm/c686c300cc728b6e42167de9963791e4 to your computer and use it in GitHub Desktop.
Save gaetanm/c686c300cc728b6e42167de9963791e4 to your computer and use it in GitHub Desktop.
require 'open3'
class LazySpec
GIT_CMD = "git diff --name-only --exit-code"
RSPEC_CMD = "bundle exec rspec "
def self.launch
new.launch
end
def launch
select_files(git_diff)
summarize
puts launch_specs
end
private
def git_diff
stdout, status = Open3.capture2(GIT_CMD)
stdout
end
def select_files(git_diff)
@files = git_diff.split.select { |file| file.include?("_spec.rb") }
end
def summarize
@files.each { |file| puts "🍺 #{file}" }
end
def launch_specs
stdout, status = Open3.capture2("bundle exec rspec #{@files.join(" ")}")
stdout
end
end
LazySpec.launch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment