Class: Testifier::FileMaker
- Inherits:
-
Object
- Object
- Testifier::FileMaker
- Defined in:
- lib/testifier/file_maker.rb
Instance Method Summary collapse
- #basename ⇒ Object
- #class_definition ⇒ Object
- #class_file ⇒ Object
- #create_class_file ⇒ Object
- #create_files ⇒ Object
- #create_test_file ⇒ Object
-
#initialize(path) ⇒ FileMaker
constructor
A new instance of FileMaker.
- #target_dir ⇒ Object
- #test_definition ⇒ Object
- #test_dir ⇒ Object
- #test_file ⇒ Object
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
#basename ⇒ Object
26 27 28 |
# File 'lib/testifier/file_maker.rb', line 26 def basename File.basename(@initial_path, File.extname(@initial_path)) end |
#class_definition ⇒ Object
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_file ⇒ Object
18 19 20 |
# File 'lib/testifier/file_maker.rb', line 18 def class_file "lib/#{dirname}#{basename}.rb" end |
#create_class_file ⇒ Object
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_files ⇒ Object
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_file ⇒ Object
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_dir ⇒ Object
10 11 12 |
# File 'lib/testifier/file_maker.rb', line 10 def target_dir "lib/#{dirname}" end |
#test_definition ⇒ Object
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_dir ⇒ Object
14 15 16 |
# File 'lib/testifier/file_maker.rb', line 14 def test_dir "spec/lib/#{dirname}" end |
#test_file ⇒ Object
22 23 24 |
# File 'lib/testifier/file_maker.rb', line 22 def test_file "spec/lib/#{dirname}#{basename}_spec.rb" end |