Class: Cukehead::FeatureReader

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

Instance Method Summary collapse

Constructor Details

#initialize(mm_xml = nil) ⇒ FeatureReader

Parameters

mm_xml - Optional string containing XML representation of a FreeMind mind map into which a Cucumber Features node will be inserted.



12
13
14
# File 'lib/cukehead/feature_reader.rb', line 12

def initialize(mm_xml = nil)
  @builder = FreemindBuilder.new(mm_xml)
end

Instance Method Details

#extract_features(filename, text) ⇒ Object

Parameters

filename - The name of the file from which text was read.

text - String containing the text of a Cucumber feature file.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cukehead/feature_reader.rb', line 22

def extract_features(filename, text)
  @section = nil
  in_literal_text = false
  literal_text = ''
  tags = []
  text.each do |line|
    s = line.strip
    #$stderr.puts "DEBUG: LINE='#{s}'"
    if s == '"""'
      if in_literal_text
        @section.add(literal_text + "\n\"\"\"") unless @section == nil
        in_literal_text = false
      else
        literal_text = "\"\"\"\n"
        in_literal_text = true
      end
    else
      if in_literal_text
        literal_text << line
      else
        case s
          when /^\@.*/i
            tags = s.split(' ')
          when /^Feature:.*/i
            @section.finish unless @section == nil
            @section = FeatureSection.new(@builder, line, filename)
            @section.set_tags tags
            tags.clear
          when /^Background:.*/i
            @section.finish unless @section == nil
            @section = BackgroundSection.new(@builder, line)
            @section.set_tags tags
            tags.clear
          when /^(Scenario|Scenario Outline):.*/i
            @section.finish unless @section == nil
            @section = ScenarioSection.new(@builder, line)
            @section.set_tags tags
            tags.clear
          else
            @section.add(line) unless @section == nil
        end
      end
    end
  end
  @section.finish unless @section == nil
end

#freemind_xmlObject

Returns a string that is the FreeMind mind map XML.



72
73
74
# File 'lib/cukehead/feature_reader.rb', line 72

def freemind_xml
  @builder.xml
end