Class: Testifier::FileMaker

Inherits:
Object
  • Object
show all
Defined in:
lib/testifier/file_maker.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileMaker

Returns a new instance of FileMaker.



6
7
8
# File 'lib/testifier/file_maker.rb', line 6

def initialize(path)
  @initial_path =  path
end

Instance Method Details

#basenameObject



26
27
28
# File 'lib/testifier/file_maker.rb', line 26

def basename
  File.basename(@initial_path, File.extname(@initial_path))
end

#class_definitionObject



51
52
53
54
55
56
# File 'lib/testifier/file_maker.rb', line 51

def class_definition
  <<-CLASS
class #{class_name}
end
CLASS
end

#class_fileObject



18
19
20
# File 'lib/testifier/file_maker.rb', line 18

def class_file
  "lib/#{dirname}#{basename}.rb"
end

#create_class_fileObject



37
38
39
40
41
42
# File 'lib/testifier/file_maker.rb', line 37

def create_class_file
  unless File.exist?(class_file)
    puts "creating #{class_file}"
    File.open(class_file, "w") { |file| file.puts class_definition }
  end
end

#create_filesObject



30
31
32
33
34
35
# File 'lib/testifier/file_maker.rb', line 30

def create_files
  make_dir_if_necessary(target_dir)
  make_dir_if_necessary(test_dir)
  create_class_file
  create_test_file
end

#create_test_fileObject



44
45
46
47
48
49
# File 'lib/testifier/file_maker.rb', line 44

def create_test_file
  unless File.exist?(test_file)
    puts "creating #{test_file}"
    File.open(test_file, "w") { |file| file.puts test_definition }
  end
end

#target_dirObject



10
11
12
# File 'lib/testifier/file_maker.rb', line 10

def target_dir
  "lib/#{dirname}"
end

#test_definitionObject



58
59
60
61
62
63
64
65
# File 'lib/testifier/file_maker.rb', line 58

def test_definition
  <<-TEST
require "#{dirname}#{basename}"

describe #{class_name} do
end
TEST
end

#test_dirObject



14
15
16
# File 'lib/testifier/file_maker.rb', line 14

def test_dir
  "spec/lib/#{dirname}"
end

#test_fileObject



22
23
24
# File 'lib/testifier/file_maker.rb', line 22

def test_file
  "spec/lib/#{dirname}#{basename}_spec.rb"
end