Module: Cucumber2RSpec

Defined in:
lib/cucumber2rspec.rb,
lib/cucumber2rspec/step.rb,
lib/cucumber2rspec/feature.rb,
lib/cucumber2rspec/scenario.rb,
lib/cucumber2rspec/background.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Background, Feature, Scenario, Step

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject

Returns the value of attribute logger.



19
20
21
# File 'lib/cucumber2rspec.rb', line 19

def logger
  @logger
end

Class Method Details

.block_variable_names(a_proc) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/cucumber2rspec.rb', line 58

def self.block_variable_names a_proc
  sexp               = a_proc.to_sexp
  local_assignments  = []

  # this is where the variables hang out ...
  if sexp[2] and sexp[2].is_a?(Sexp)
    
    # there's only 1 local assigned variable
    if sexp[2][0] == :lasgn
      local_assignments << sexp[2][1]
      
    # there's an array of locally assigned variables
    elsif sexp[2][0] == :masgn and sexp[2][1][0] == :array # mass assignment using an array
      array_of_variables = a_proc.to_sexp[2][1]
      the_type           = array_of_variables.shift
      array_of_variables.each do |sub_sexp|
        local_assignments << sub_sexp[1] if sub_sexp[0] == :lasgn
      end
    end
  end

  local_assignments
end

.log(&block) ⇒ Object



22
23
24
# File 'lib/cucumber2rspec.rb', line 22

def self.log &block
  logger.debug(&block) if logger
end

.parserObject



26
27
28
29
# File 'lib/cucumber2rspec.rb', line 26

def self.parser
  Cucumber.load_language('en')
  @parser ||= Cucumber::Parser::FeatureParser.new
end

.replace_in_sexp(sexp, to_replace, replace_with) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cucumber2rspec.rb', line 44

def self.replace_in_sexp sexp, to_replace, replace_with
  while sexp.include?(to_replace)
    index = sexp.index(to_replace)
    sexp.delete_at index
    sexp.insert    index, replace_with
  end
  
  sexp.each do|obj|
    replace_in_sexp(obj, to_replace, replace_with) if obj.is_a?(Sexp)
  end

  sexp
end

.step_match(text) ⇒ Object



31
32
33
# File 'lib/cucumber2rspec.rb', line 31

def self.step_match text
  $step_match.call(text)
end

.translate(feature_text) ⇒ Object



35
36
37
# File 'lib/cucumber2rspec.rb', line 35

def self.translate feature_text
  Cucumber2RSpec::Feature.new(feature_text).code
end

.translate_file(filepath) ⇒ Object



39
40
41
42
# File 'lib/cucumber2rspec.rb', line 39

def self.translate_file filepath
  Cucumber2RSpec.log { "translate_file(#{filepath.inspect})" }
  translate File.read(filepath)
end