Class: TestDiff::RunableTests
- Inherits:
-
Object
- Object
- TestDiff::RunableTests
- Defined in:
- lib/test_diff/runable_tests.rb
Overview
class used to find tests that are runable
Instance Attribute Summary collapse
-
#tests_folder ⇒ Object
readonly
Returns the value of attribute tests_folder.
Class Method Summary collapse
Instance Method Summary collapse
- #_add_calculated_tests(files) ⇒ Object
- #_add_rails_view_spec(file_name) ⇒ Object
- #_build_tests_to_run ⇒ Object
- #add_changed_files ⇒ Object
-
#initialize(list_to_add_to, tests_folder) ⇒ RunableTests
constructor
A new instance of RunableTests.
Constructor Details
#initialize(list_to_add_to, tests_folder) ⇒ RunableTests
Returns a new instance of RunableTests.
18 19 20 21 |
# File 'lib/test_diff/runable_tests.rb', line 18 def initialize(list_to_add_to, tests_folder) @tests_to_run = list_to_add_to @tests_folder = tests_folder end |
Instance Attribute Details
#tests_folder ⇒ Object (readonly)
Returns the value of attribute tests_folder.
16 17 18 |
# File 'lib/test_diff/runable_tests.rb', line 16 def tests_folder @tests_folder end |
Class Method Details
.add_all(spec_folder, list, continue = false) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/test_diff/runable_tests.rb', line 5 def self.add_all(spec_folder, list, continue = false) if File.file?(spec_folder) list << spec_folder else Dir["#{spec_folder}/**/*_spec.rb"].each do |spec_name| has_no_data = Config.storage.get(spec_name).empty? list << spec_name if has_no_data || !continue end end end |
Instance Method Details
#_add_calculated_tests(files) ⇒ Object
44 45 46 |
# File 'lib/test_diff/runable_tests.rb', line 44 def _add_calculated_tests(files) @tests_to_run << Config.storage.select_tests_for(files, tests_folder) end |
#_add_rails_view_spec(file_name) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/test_diff/runable_tests.rb', line 48 def _add_rails_view_spec(file_name) # try and find a matching view spec return unless file_name.include?('app/views') view_spec_name = file_name.gsub('app/views', "#{tests_folder}/views").gsub('.erb', '.erb_spec.rb') return unless File.exist?("#{Config.working_directory}/#{view_spec_name}") @tests_to_run << Config.storage.test_info_for(view_spec_name) end |
#_build_tests_to_run ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/test_diff/runable_tests.rb', line 31 def _build_tests_to_run files = [] Config.version_control.changed_files.each do |file_name| if Config.test_pattern.match(file_name) @tests_to_run << Config.storage.test_info_for(file_name) elsif !file_name.start_with?(@tests_folder) files << file_name _add_rails_view_spec(file_name) end end _add_calculated_tests(files) end |
#add_changed_files ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/test_diff/runable_tests.rb', line 23 def add_changed_files _build_tests_to_run @tests_to_run.flatten! @tests_to_run.sort! @tests_to_run.uniq!(&:filename) end |