class Grspec
Attributes
base_ref[R]
diff_ref[R]
options[R]
Public Class Methods
new(base_ref:, diff_ref:, options: OpenStruct.new)
click to toggle source
# File lib/grspec.rb, line 10 def initialize(base_ref:, diff_ref:, options: OpenStruct.new) @base_ref = base_ref @diff_ref = diff_ref @options = options end
Public Instance Methods
run()
click to toggle source
# File lib/grspec.rb, line 16 def run if changed_files.empty? display("No changed files found") return end display_listing('Changed files:', changed_files) display_listing( 'Files without specs:', mismatching_files.map(&:first) ) if mismatching_files.any? if spec_matchings.any? display_listing( 'Matching specs:', spec_matchings.map { |matching_spec| matching_spec.join(' -> ') } ) if non_existent_specs.any? display_listing( 'Removed specs:', non_existent_specs ) end if specs_to_run.any? if dry_run? puts specs_to_run else SpecRunner.run(specs_to_run) end end else display("No matching specs found") end end
Private Instance Methods
changed_files()
click to toggle source
# File lib/grspec.rb, line 60 def changed_files @changed_files ||= FindChangedFiles.new( base_ref: base_ref, diff_ref: diff_ref ).call end
display(string)
click to toggle source
# File lib/grspec.rb, line 95 def display(string) return unless display_output? puts puts string end
display_listing(header, listing)
click to toggle source
# File lib/grspec.rb, line 102 def display_listing(header, listing) return unless display_output? puts puts header puts listing end
display_output?()
click to toggle source
# File lib/grspec.rb, line 91 def display_output? !dry_run? end
dry_run?()
click to toggle source
# File lib/grspec.rb, line 56 def dry_run? options.dry_run end
file_spec_pairs()
click to toggle source
# File lib/grspec.rb, line 67 def file_spec_pairs @file_spec_pairs ||= FindMatchingSpecs.new(changed_files).call end
matching_specs()
click to toggle source
# File lib/grspec.rb, line 79 def matching_specs @matching_specs ||= spec_matchings.map(&:second).uniq end
mismatching_files()
click to toggle source
# File lib/grspec.rb, line 71 def mismatching_files @mismatching_files ||= file_spec_pairs.select { |_, spec| spec.nil? } end
non_existent_specs()
click to toggle source
# File lib/grspec.rb, line 83 def non_existent_specs @non_existent_specs ||= matching_specs.reject { |spec_file| File.file?(spec_file) } end
spec_matchings()
click to toggle source
# File lib/grspec.rb, line 75 def spec_matchings @spec_matchings ||= file_spec_pairs - mismatching_files end
specs_to_run()
click to toggle source
# File lib/grspec.rb, line 87 def specs_to_run @specs_to_run ||= matching_specs - non_existent_specs end