Class: GenTool

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/acceptance_test/gen_tool.rb

Instance Method Summary collapse

Instance Method Details

#generate_feature(spec_file_name) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/acceptance_test/gen_tool.rb', line 57

def generate_feature spec_file_name
  keywords_exp = /step\s+('|")(.*)('|")/

  File.open(spec_file_name).each_line do |line|
    line = line.strip

    if line =~ keywords_exp
      if line =~ /^#/
        puts "# " + line.scan(keywords_exp)[0][1]
      else
        puts line.scan(keywords_exp)[0][1]
      end
    end
  end
end

#generate_steps(feature_file_name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
# File 'lib/acceptance_test/gen_tool.rb', line 6

def generate_steps feature_file_name
  keywords_exp = /^(Given|When|Then|And|But)/

  File.open(feature_file_name).each_line do |line|
    line = line.strip

    if line !~ /^#/ and line =~ keywords_exp
      title = line.gsub(keywords_exp, "").strip

      params = line.gsub(/('<\w+>')|("<\w+>")|(<\w+>)|(".+")|('.+')/).to_a
      new_params = []

      params.each_with_index do |param, index|
        key = param.gsub(/(<|>|'|")/, "").downcase

        if key =~ /\s+/
          key = key.underscore.gsub(/\s+/, "_")
        end

        value = param.gsub(/('|")/, "")

        new_params[index] = [key, value]
        title.gsub!(param, ":#{key}")
      end

      new_params.each do |key, value|
        print "\n"
        print "input[:#{key}] = \"#{value}\""
        print "\n"
      end

      print "\n"
      print "step '#{title}' do "

      if new_params.size > 0
        print "|"

        new_params.each_with_index do |array, index|
          print "#{array.first}"
          print ", " if index < params.size-1
        end

        print "|"
      end

      print "\n\n"
      print "end\n"
    end
  end
end