Class: GitSpec::File

Inherits:
Object
  • Object
show all
Defined in:
lib/git_spec/file.rb

Constant Summary collapse

EXCLUDED_FILE_PATTERNS =

TODO: Move this to the config

[/^exe\//, /^spec\//, /^vendor\//, /^config\//, /^regression_tests\//, /^\./]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, configuration = GitSpec.configuration) ⇒ File

Returns a new instance of File.



8
9
10
11
# File 'lib/git_spec/file.rb', line 8

def initialize(filename, configuration = GitSpec.configuration)
  @path = filename.strip
  @configuration = configuration
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



6
7
8
# File 'lib/git_spec/file.rb', line 6

def configuration
  @configuration
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/git_spec/file.rb', line 6

def path
  @path
end

Instance Method Details

#excluded?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
38
39
# File 'lib/git_spec/file.rb', line 30

def excluded?
  return true, 'Invalid file type' unless is_ruby?
  filtered = should_filter?(path)

  if filtered
    return filtered, 'Excluded by file pattern match'
  else
    return filtered
  end
end

#is_ruby?Boolean

TODO: Make this a whitelisted file extension configuration

Returns:

  • (Boolean)


42
43
44
# File 'lib/git_spec/file.rb', line 42

def is_ruby?
  ::File.extname(path) == '.rb'
end

#should_filter?(filename) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/git_spec/file.rb', line 46

def should_filter?(filename)
  should_exclude = false
  EXCLUDED_FILE_PATTERNS.each do |pattern|
    match = filename =~ pattern

    unless match.nil?
      should_exclude = true
      break
    end
  end
  should_exclude
end

#spec_pathObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/git_spec/file.rb', line 13

def spec_path
  # TODO: Get test dir from config
  # TODO: Get spec naming convention from config
  @spec_path ||= begin
    filename = path
    filename = "spec/" << filename
    filename.gsub!(".rb", "_spec.rb")

    filename.gsub!(configuration.src_root, "")

    filename
  end
rescue => e
  # TODO: Log helpful info when this happens
  raise
end