This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
forked from toptal/crystalball
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If the Gemfile (or Gemfile.lock) has changed, all tests neeed to be run to ensure correctness.
- Loading branch information
1 parent
be8888a
commit 46c0ddc
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'crystalball/predictor/strategy' | ||
|
||
module Crystalball | ||
class Predictor | ||
# Used with `predictor.use Crystalball::Predictor::Gemfile.new`. Return every file if the Gemfile or Gemfile.lock file are changed | ||
class Gemfile | ||
include Strategy | ||
|
||
# @param [Crystalball::SourceDiff] diff - the diff from which to predict | ||
# which specs should run | ||
# @param [Crystalball::ExampleGroupMap] map - the map with the relations of | ||
# examples and used files | ||
# @return [Array<String>] the spec paths associated with the changes | ||
def call(diff, map) | ||
super do | ||
return [] unless diff.detect{ |file_diff| ['Gemfile', 'Gemfile.lock'].include?(file_diff.path) } | ||
map.example_groups.keys.compact | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :spec_pattern | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe Crystalball::Predictor::Gemfile do | ||
subject(:predictor) { described_class.new } | ||
let(:repository) { Git::Base.new } | ||
let(:path1) { 'Gemfile' } | ||
let(:file_diff1) { Crystalball::SourceDiff::FileDiff.new(Git::Diff::DiffFile.new(repository, path: path1)) } | ||
let(:diff) { [file_diff1] } | ||
let(:map) { instance_double('Crystalball::MapGenerator::ExecutionMap', example_groups: example_groups) } | ||
let(:example_groups) { {'spec_file' => [], 'spec_file_2' => [] } } | ||
|
||
describe '#call' do | ||
subject { predictor.call(diff, map) } | ||
|
||
it { is_expected.to eq(['./spec_file', './spec_file_2']) } | ||
|
||
context 'when gemfile.lock is included in changed files' do | ||
let(:path1) { 'Gemfile.lock' } | ||
|
||
it { is_expected.to eq(['./spec_file', './spec_file_2']) } | ||
end | ||
|
||
context 'when neither Gemfile or Gemfile.lock are changed' do | ||
let(:path1) { 'version.rb' } | ||
|
||
it { is_expected.to eq([]) } | ||
end | ||
end | ||
end |