Class: TestCase

Inherits:
Object
  • Object
show all
Defined in:
lib/sfb_scripts/test_running/test_case.rb

Constant Summary collapse

TestDirectoryError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(full_path: raise, line: '') ⇒ TestCase

Returns a new instance of TestCase.



6
7
8
9
10
11
# File 'lib/sfb_scripts/test_running/test_case.rb', line 6

def initialize(full_path: raise, line: '')
  raise 'Bad Test File' unless full_path.match(/_test\.rb/)

  @test_name = test_name_from_grepped_line(line)
  @full_path = full_path
end

Instance Attribute Details

#full_pathObject (readonly)

Returns the value of attribute full_path.



4
5
6
# File 'lib/sfb_scripts/test_running/test_case.rb', line 4

def full_path
  @full_path
end

#relative_pathObject (readonly)

Returns the value of attribute relative_path.



4
5
6
# File 'lib/sfb_scripts/test_running/test_case.rb', line 4

def relative_path
  @relative_path
end

#test_nameObject (readonly)

Returns the value of attribute test_name.



4
5
6
# File 'lib/sfb_scripts/test_running/test_case.rb', line 4

def test_name
  @test_name
end

#working_dirObject (readonly)

Returns the value of attribute working_dir.



4
5
6
# File 'lib/sfb_scripts/test_running/test_case.rb', line 4

def working_dir
  @working_dir
end

Instance Method Details

#is_method?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/sfb_scripts/test_running/test_case.rb', line 22

def is_method?
  ! @test_name.nil?
end

#raise_file_path_errorObject

Raises:



30
31
32
# File 'lib/sfb_scripts/test_running/test_case.rb', line 30

def raise_file_path_error
  raise TestDirectoryError.new("Can't find test's relative path")
end

#test_name_from_grepped_line(line) ⇒ Object



34
35
36
37
# File 'lib/sfb_scripts/test_running/test_case.rb', line 34

def test_name_from_grepped_line(line)
  return unless line && line.match(/^\s*def\s+test_/)
  @test_name = line.strip.gsub(/^\s*def\s+/, '').strip
end