Class: StepsTemplator

Inherits:
Object
  • Object
show all
Includes:
Templator
Defined in:
lib/generators/feature/steps_templator.rb

Direct Known Subclasses

DeleteSteps, EditSteps, IndexSteps, NewSteps, ShowSteps

Constant Summary collapse

VALID_TYPES =
%w(given when then).map(&:to_sym)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Templator

#render

Constructor Details

#initialize(generator, user, file) ⇒ StepsTemplator

Returns a new instance of StepsTemplator.



8
9
10
11
12
# File 'lib/generators/feature/steps_templator.rb', line 8

def initialize(generator, user, file)
  @generator = generator
  @user = user
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



5
6
7
# File 'lib/generators/feature/steps_templator.rb', line 5

def file
  @file
end

#generatorObject (readonly)

Returns the value of attribute generator.



5
6
7
# File 'lib/generators/feature/steps_templator.rb', line 5

def generator
  @generator
end

Instance Method Details

#create_methods(template) ⇒ Object



14
15
16
17
18
# File 'lib/generators/feature/steps_templator.rb', line 14

def create_methods(template)
  generator.prepend_to_file file do
    render File.join('step_definitions', template)
  end if File.exists? file
end

#create_step(type, template) ⇒ Object



20
21
22
23
24
25
# File 'lib/generators/feature/steps_templator.rb', line 20

def create_step(type, template)
  fail "type '#{type}' must be one of #{VALID_TYPES}" unless VALID_TYPES.include? type
  generator.insert_into_file file, after: "### #{type.to_s.upcase} ###\n\n" do
    render File.join('step_definitions', template)
  end if File.exists? file
end