Class: Fishbone::Generator

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

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Generator

Returns a new instance of Generator.



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

def initialize(opts)
  @options = opts
end

Instance Method Details

#aliases(options) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/fishbone.rb', line 13

def aliases(options)
  if options[:capybara]
    capybara_aliases 
  else
    spec_aliases 
  end
end

#capybara_aliasesObject



52
53
54
55
56
57
# File 'lib/fishbone.rb', line 52

def capybara_aliases
  { :level_one => 'feature',
    :level_two => 'scenario',
    :hook  => 'background'
  }
end

#make_spec(options) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fishbone.rb', line 21

def make_spec(options)
  local_aliases        = aliases(options)
  feature_name         = options[:feature] || "Give your feature a name"
  base_template        = File.read(options[:rspec]) if options[:rspec]
  before_all_template  = File.read(options[:before_all]) if options[:before_all]
  before_each_template = File.read(options[:before_each]) if options[:before_each]
  edge_template        = File.read(options[:edge]) if options[:edge]
  simple_template      = File.read(options[:simple]) if options[:simple]
  renderer             = ERB.new(base_template)
  renderer.result(binding)
end

#objectObject



38
39
40
41
42
43
# File 'lib/fishbone.rb', line 38

def object
  obj_def = @options[:object]
  obj_template = File.read('./lib/templates/object.erb')
  renderer = ERB.new(obj_template)
  renderer.result(binding)
end

#rootObject



9
10
11
# File 'lib/fishbone.rb', line 9

def root
  File.expand_path '../..', __FILE__
end

#spec_aliasesObject



45
46
47
48
49
50
# File 'lib/fishbone.rb', line 45

def spec_aliases
  { :level_one => 'describe',
    :level_two => 'it',
    :hook  => 'before'
  }
end

#table_testsObject



59
60
61
62
63
64
# File 'lib/fishbone.rb', line 59

def table_tests
  local_aliases = aliases(@options)
  test_def_template = File.read('./lib/templates/table.erb')
  renderer          = ERB.new(test_def_template)
  renderer.result(binding)
end

#write_to_file(text_out) ⇒ Object



33
34
35
36
# File 'lib/fishbone.rb', line 33

def write_to_file(text_out)
  file = @options[:output]
  File.write(file, text_out)
end