Class: MightyTest::FileSystem

Inherits:
Object
  • Object
show all
Defined in:
lib/mighty_test/file_system.rb

Instance Method Summary collapse

Instance Method Details

#find_matching_test_path(path) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity



10
11
12
13
14
15
16
# File 'lib/mighty_test/file_system.rb', line 10

def find_matching_test_path(path) # rubocop:disable Metrics/CyclomaticComplexity
  return nil unless path && File.exist?(path) && !Dir.exist?(path)
  return path if path.match?(%r{^test/.*_test.rb$})

  test_path = path[%r{^(?:app|lib)/(.+)\.[^\.]+$}, 1]&.then { "test/#{_1}_test.rb" }
  test_path if test_path && File.exist?(test_path)
end

#find_new_and_changed_pathsObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mighty_test/file_system.rb', line 29

def find_new_and_changed_paths
  out, _err, status = Open3.capture3(*%w[git status --porcelain=1 -uall -z --no-renames -- test app lib])
  return [] unless status.success?

  out
    .split("\x0")
    .filter_map { |line| line[/^.. (.+)/, 1] }
    .uniq
rescue SystemCallError
  []
end

#find_test_paths(directory = "test") ⇒ Object



18
19
20
21
# File 'lib/mighty_test/file_system.rb', line 18

def find_test_paths(directory="test")
  glob = File.join(directory, "**/*_test.rb")
  Dir[glob]
end

#listenObject



5
6
7
8
# File 'lib/mighty_test/file_system.rb', line 5

def listen(&)
  require "listen"
  Listen.to(*%w[app lib test].select { |p| Dir.exist?(p) }, relative: true, &).tap(&:start)
end

#slow_test_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/mighty_test/file_system.rb', line 23

def slow_test_path?(path)
  return false if path.nil?

  path.match?(%r{^test/(e2e|feature|features|integration|system)/})
end