Class: TestLauncher::Frameworks::Implementation::TestCase

Inherits:
Object
  • Object
show all
Defined in:
lib/test_launcher/frameworks/implementation/test_case.rb

Direct Known Subclasses

Base::TestCase

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file:, example: nil, request:, line_number: nil) ⇒ TestCase

Returns a new instance of TestCase.



13
14
15
16
17
18
# File 'lib/test_launcher/frameworks/implementation/test_case.rb', line 13

def initialize(file:, example: nil, request:, line_number: nil)
  @file = file
  @example = example
  @line_number = line_number
  @request = request
end

Instance Attribute Details

#exampleObject (readonly)

Returns the value of attribute example.



7
8
9
# File 'lib/test_launcher/frameworks/implementation/test_case.rb', line 7

def example
  @example
end

#fileObject (readonly)

Returns the value of attribute file.



7
8
9
# File 'lib/test_launcher/frameworks/implementation/test_case.rb', line 7

def file
  @file
end

#line_numberObject (readonly)

Returns the value of attribute line_number.



7
8
9
# File 'lib/test_launcher/frameworks/implementation/test_case.rb', line 7

def line_number
  @line_number
end

#requestObject (readonly)

Returns the value of attribute request.



7
8
9
# File 'lib/test_launcher/frameworks/implementation/test_case.rb', line 7

def request
  @request
end

Class Method Details

.from_search(file:, query:, request:) ⇒ Object



9
10
11
# File 'lib/test_launcher/frameworks/implementation/test_case.rb', line 9

def self.from_search(file:, query:, request:)
  new(file: file, example: query, request: request)
end

Instance Method Details

#app_rootObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/test_launcher/frameworks/implementation/test_case.rb', line 28

def app_root
  if exploded_path.select { |dir| dir == test_root_dir_name }.size > 1
    candidates = exploded_path

    while !candidates.empty?
      if candidates.last == test_root_dir_name
        root_path = File.join("/", candidates[0..-2])
        return root_path if Dir.entries(root_path).any? {|e| e.match /Gemfile|gemspec|mix.exs|config.ru/} # TODO: extract this
      end

      candidates.pop
    end
  end

  path = exploded_path[0...exploded_path.index(test_root_dir_name)]
  File.join("/", path)
end

#exploded_pathObject



54
55
56
# File 'lib/test_launcher/frameworks/implementation/test_case.rb', line 54

def exploded_path
  Pathname.new(file).each_filename.to_a
end

#is_example?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/test_launcher/frameworks/implementation/test_case.rb', line 20

def is_example?
  !example.nil?
end

#mtimeObject



24
25
26
# File 'lib/test_launcher/frameworks/implementation/test_case.rb', line 24

def mtime
  @mtime ||= File.mtime(file)
end

#test_rootObject



46
47
48
# File 'lib/test_launcher/frameworks/implementation/test_case.rb', line 46

def test_root
  File.join(app_root, test_root_dir_name)
end

#test_root_dir_nameObject

Raises:

  • (NotImplementedError)


50
51
52
# File 'lib/test_launcher/frameworks/implementation/test_case.rb', line 50

def test_root_dir_name
  raise NotImplementedError
end