Class: Rakugoka::Formatter::Importer

Inherits:
Cucumber::Ast::Visitor
  • Object
show all
Defined in:
lib/rakugoka/formatter/importer.rb

Instance Method Summary collapse

Constructor Details

#initialize(step_mother, io, options) ⇒ Importer

Returns a new instance of Importer.



4
5
6
7
# File 'lib/rakugoka/formatter/importer.rb', line 4

def initialize(step_mother, io, options)
  super(step_mother)
  @options = options
end

Instance Method Details

#title_from_file_nameObject



49
50
51
# File 'lib/rakugoka/formatter/importer.rb', line 49

def title_from_file_name
  @feature_file_name.gsub(/.feature$|^features\//,'').gsub(/_/," ").capitalize
end

#visit_feature(feature) ⇒ Object



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
# File 'lib/rakugoka/formatter/importer.rb', line 14

def visit_feature(feature)
  STDERR.write(".")
  @current_feature = {:filename => feature.file}
  if feature.file && File.exists?(feature.file)
    @current_feature[:last_changed_at] = File.mtime(feature.file)
  end
  @scenarios = []
  @exceptions = []
  @feature_file_name = feature.file
  
  super
  post_attributes = {:feature => @current_feature, :api_key => API_KEY}
  
  @scenarios.each_with_index do |hash, i|
    hash.each do |k,v|
      post_attributes["feature[scenarios_attributes][#{i}][#{k}]"] = v
    end
  end

  begin
    response = RestClient.post PROJECT_URL + "/features.xml", post_attributes
  rescue => e
    STDERR.puts("\nCould not upload #{@feature_file_name}")
  end
  @feature_file_name = ""
end

#visit_feature_element(feature_element) ⇒ Object



53
54
55
56
57
58
# File 'lib/rakugoka/formatter/importer.rb', line 53

def visit_feature_element(feature_element)
  @current_scenario = {:steps => []}
  super
  @current_scenario[:steps] = @current_scenario[:steps].join("\n")
  @scenarios << @current_scenario
end

#visit_feature_name(name) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/rakugoka/formatter/importer.rb', line 41

def visit_feature_name(name)
  lines = name.split(/\r?\n/)
  title = lines[0].gsub(/^\s*Feature:\s*/,'').strip if lines[0] =~ /^\s*Feature:/
  title = title_from_file_name if title.nil? || title == ""
  @current_feature[:title] = title
  @current_feature[:narrative] = lines[1..-1].map {|l| l.strip }.join("\n")
end

#visit_features(features) ⇒ Object



9
10
11
12
# File 'lib/rakugoka/formatter/importer.rb', line 9

def visit_features(features)
  super
  STDERR.write("\n")
end

#visit_py_string(string) ⇒ Object



71
72
73
74
75
# File 'lib/rakugoka/formatter/importer.rb', line 71

def visit_py_string(string)
  if @current_scenario
    @current_scenario[:steps] << string
  end
end

#visit_scenario_name(keyword, name, file_colon_line, source_indent) ⇒ Object



60
61
62
63
# File 'lib/rakugoka/formatter/importer.rb', line 60

def visit_scenario_name(keyword, name, file_colon_line, source_indent)
  @listing_background = false
  @current_scenario[:title] = name
end

#visit_step_name(keyword, step_match, status, source_indent, background) ⇒ Object



65
66
67
68
69
# File 'lib/rakugoka/formatter/importer.rb', line 65

def visit_step_name(keyword, step_match, status, source_indent, background)
  if @current_scenario
    @current_scenario[:steps] << build_step(keyword, step_match)
  end
end