Class: Coverfield::Source::TestFile

Inherits:
Object
  • Object
show all
Includes:
FileMethods
Defined in:
lib/coverfield/source/test_file.rb

Overview

Represents a spec file

Instance Attribute Summary

Attributes included from FileMethods

#file_name

Instance Method Summary collapse

Methods included from FileMethods

#relative_file_name

Constructor Details

#initialize(config, file_name) ⇒ TestFile

Constructor



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/coverfield/source/test_file.rb', line 9

public def initialize(config, file_name)
  @config = config
  @file_name = config.app_root + '/' + file_name
  @file_exists = File.exists?(file_name) && !File.zero?(file_name)
  @describes = {}

  # If the file doesn't exist, do nothing
  if file_exists?
    parse_code
    find_describes
  end
rescue Exception => e
  raise RuntimeError, "Error while processing file #{file_name}: #{e.message}", e.backtrace
end

Instance Method Details

#cover?(class_name, method_name) ⇒ Boolean

Tells if that file covers a method of a class pair

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
# File 'lib/coverfield/source/test_file.rb', line 32

public def cover?(class_name, method_name)
  return false unless file_exists?

  @describes.each_pair do |subject, test_methods|
    return true if subject == class_name &&
                   test_methods.include?(method_name.to_s)
  end

  false
end

#file_exists?Boolean

Tells if the test file even exists

Returns:

  • (Boolean)


26
27
28
# File 'lib/coverfield/source/test_file.rb', line 26

public def file_exists?
  @file_exists
end