Created
June 19, 2020 15:56
-
-
Save pedrocarmona/637f1ce2da0046a7b6cd06ab24231aa1 to your computer and use it in GitHub Desktop.
Displays tests added in the new PR branch
This file contains 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
# frozen_string_literal: true | |
require "rspec/core/formatters/base_text_formatter" | |
class CustomJsonFormatter | |
# This registers the notifications this formatter supports, and tells | |
# us that this was written against the RSpec 3.x formatter API. | |
RSpec::Core::Formatters.register self, :example_started | |
def initialize(output) | |
@output = output | |
end | |
def example_started(notification) | |
@output << { | |
full_description: notification.example.full_description, | |
location: notification.example.location | |
}.to_json | |
@output << ",\n" | |
end | |
end |
This file contains 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
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
require "json" | |
results = `git diff --name-status master | grep _spec.rb` | |
files_by_git_action = { A: [], M: [], D: [] } | |
results.split("\n").each do |result_line| | |
git_action, file = result_line.split("\t") | |
files_by_git_action[git_action.to_sym] << file | |
end | |
`git checkout master` | |
puts "Running specs for files changed or deleted" | |
master_output = `bundle exec rspec #{(files_by_git_action[:M] + files_by_git_action[:D]).join(" ")} --require ./spec/support/custom_json_formatter.rb --format CustomJsonFormatter` | |
`git checkout -` | |
puts "Running specs for files changed or created" | |
branch_output = `bundle exec rspec #{(files_by_git_action[:M] + files_by_git_action[:A]).join(" ")} --require ./spec/support/custom_json_formatter.rb --format CustomJsonFormatter` | |
master_rows = JSON.parse("[#{master_output[0..-3]}]") | |
master_full_descriptions = master_rows.map{ |row| row["full_description"] } | |
branch_rows = JSON.parse("[#{branch_output[0..-3]}]") | |
branch_full_descriptions = branch_rows.map{ |row| row["full_description"] } | |
new_examples = branch_full_descriptions.uniq - (master_full_descriptions.uniq & branch_full_descriptions.uniq) | |
locations = branch_rows.select{ |row| new_examples.include?(row["full_description"]) }.map{ |row| row["location"] } | |
pr_changed_tests = "bundle exec rspec #{locations.sort.join(" ")} --format documentation" | |
puts pr_changed_tests | |
puts "Running specs...\n" | |
puts `#{pr_changed_tests}` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment