Class: Cucumber2RSpec::Scenario

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

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feature, cucumber_ast_scenario) ⇒ Scenario

Returns a new instance of Scenario.



7
8
9
10
# File 'lib/cucumber2rspec/scenario.rb', line 7

def initialize feature, cucumber_ast_scenario
  @feature   = feature
  @_scenario = cucumber_ast_scenario # Cucumber::Ast::Scenario
end

Instance Attribute Details

#_scenarioObject (readonly)

Returns the value of attribute _scenario.



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

def _scenario
  @_scenario
end

#featureObject (readonly)

Returns the value of attribute feature.



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

def feature
  @feature
end

Instance Method Details

#codeObject



31
32
33
34
35
36
# File 'lib/cucumber2rspec/scenario.rb', line 31

def code
  Cucumber2RSpec.log { '  ' + name }
  the_code = '  it ' + name.inspect + " do\n"
  the_code << code_without_block
  the_code << '  end'
end

#code_without_blockObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/cucumber2rspec/scenario.rb', line 20

def code_without_block
  code = Step.code_for_steps(steps)

  if background = feature.background
    # remove the background code from the scenario
    code = code.sub background.code_without_block.sub(/\n$/, ''), ''
  else
    code
  end
end

#nameObject



12
13
14
# File 'lib/cucumber2rspec/scenario.rb', line 12

def name
  _scenario.name
end

#stepsObject



16
17
18
# File 'lib/cucumber2rspec/scenario.rb', line 16

def steps
  _scenario.instance_variable_get('@steps').map {|step| Step.new(self, step) }
end