Class: Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/why_test/generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(framework) ⇒ Generator

Returns a new instance of Generator.



5
6
7
# File 'lib/why_test/generator.rb', line 5

def initialize(framework)
  @details = create(framework)
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



3
4
5
# File 'lib/why_test/generator.rb', line 3

def directory
  @directory
end

Instance Method Details

#create(framework_name) ⇒ Hash

Creates a hash with the relevant information for generating our testing files.

to be created (:files), and the rakefile (:rakfile).

Parameters:

  • the (String)

    name of a testing framework

Returns:

  • (Hash)

    hash with keys for framework name (:framework), files



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/why_test/generator.rb', line 15

def create(framework_name)
  results = Hash[:framework => framework_name, :directories => [],
    :files => [], :rakefile => 'Rakefile']

  dir = File.join(File.dirname(File.expand_path(__FILE__)), 'generators', framework_name)
  Dir.chdir dir
  Dir["**/*"].each do |f|
    results[:files].push f unless f == 'Rakefile' or File.directory? f 
    results[:directories].push f if File.directory? f
  end

  results
end

#write_files(root_directory = '.') ⇒ Object

Write the files.

directory)

Parameters:

  • the (String)

    name of a root directory (default is current



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/why_test/generator.rb', line 33

def write_files(root_directory='.')
  base_dir = File.expand_path root_directory
  @template_directory = File.join(File.dirname(__FILE__), 'generators', @details[:framework])

  system "mkdir -p #{base_dir}" unless File.exists?(base_dir)
  Dir.chdir base_dir

  create_rakefile
  create_directories
  write_test_files
end