Created
September 14, 2018 15:29
-
-
Save gaetanm/c686c300cc728b6e42167de9963791e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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