Sha256: c376e4b73ea7843481491cbe9cd9447499e0496fcaff29362f8ce1a32873e626

Contents?: true

Size: 1.25 KB

Versions: 23

Compression:

Stored size: 1.25 KB

Contents


if ENV['SHOW_STEPS']
  module Cucumber
    module RbSupport
      class RbStepDefinition
        alias :alias_for_invoke :invoke
        def invoke(args)
          $scenario_names ||= {}
          scenario_name = @rb_language.instance_variable_get("@step_mother").instance_variable_get("@current_scenario").name
          $scenario_names[scenario_name] ||= []
        
          step_file_name = File.join("#{File.dirname(__FILE__)}/../../", file_colon_line.split(":").first)
          line_num = file_colon_line.split(":").last
        
          source = File.open(step_file_name, "r") do |f|
            f.readlines
          end
         
          source.each_with_index do |line, i|
            if i >= line_num.to_i
              break if line.match(/^end\s+/)
              $scenario_names[scenario_name] << line
            end
          end
          alias_for_invoke(args)
        end
      end
    end
  end
  at_exit do  
    doc_lines = []
    $scenario_names.each do |name, lines|
      doc_lines << "# #{name}\n"
      lines.each do |line|
        doc_lines << line
      end
      doc_lines << "\n"
    end
    
    File.open(File.join(File.dirname(__FILE__), '..', '..', 'doc', 'steps_code.rb'), 'w') do |f|
      f.write doc_lines.join("")
    end
    
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
360_services-0.0.3 features/support/document_steps.rb
360_services-0.0.2 features/support/document_steps.rb
360_services-0.0.1 features/support/document_steps.rb