Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
lib/client.rb | 79 | 65 | 81.01%
|
78.46%
|
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
1 require 'net/http' |
2 require "rexml/document" |
3 require 'ostruct' |
4 require File.dirname(__FILE__) + '/../lib/story_generator' |
5 include StoryGenerator |
6 |
7 class Client |
8 |
9 attr_accessor :options, :errors |
10 |
11 def initialize(options) |
12 self.options = options |
13 self.errors = [] |
14 end |
15 |
16 def generate_story_files |
17 begin |
18 return process_xml get_xml |
19 rescue StandardError => e |
20 errors << "Could not connect to Branston server on " + |
21 "#{options[:Host]}:#{options[:Port]}: #{e.message}\n" + |
22 "Is Branston running?" |
23 end |
24 end |
25 |
26 def process_xml(xml) |
27 errors.clear |
28 |
29 if xml.nil? or xml.root.nil? or xml.root.elements.nil? |
30 errors << "Did not recieve XML data for story #{options[:feature]}.\n" + |
31 "Is the Branston server running, and have you provided the correct story name?" |
32 else |
33 |
34 begin |
35 root = xml.root |
36 story = OpenStruct.new |
37 story.description = root.elements["/story/description"].text |
38 story.title = root.elements["/story/title"].text |
39 story.scenarios = [] |
40 root.elements.each("/story/scenarios/scenario") { |scenario| |
41 s = OpenStruct.new |
42 s.preconditions = [] |
43 s.outcomes = [] |
44 s.title = scenario.elements["title"].text |
45 |
46 scenario.elements.each("preconditions/precondition") { |precondition| |
47 p = OpenStruct.new |
48 p.description = precondition.elements["description"].text |
49 s.preconditions << p |
50 } |
51 |
52 scenario.elements.each("outcomes/outcome") { |outcome| |
53 o = OpenStruct.new |
54 o.description = outcome.elements["description"].text |
55 s.outcomes << o |
56 } |
57 |
58 story.scenarios << s |
59 } |
60 |
61 generate(story) |
62 rescue StandardError => error |
63 errors << "Could not generate feature: " + error |
64 end |
65 end |
66 end |
67 |
68 def get_xml |
69 Net::HTTP.start(options[:Host] , options[:Port]) { |http| |
70 req = Net::HTTP::Get.new("/stories/#{options[:feature]}.xml") |
71 puts "generating /stories/#{options[:feature]}.xml" |
72 response = http.request(req) |
73 xml = REXML::Document.new response.body |
74 return xml |
75 } |
76 end |
77 |
78 end |
79 |
Generated on Fri Dec 11 11:38:48 +0000 2009 with rcov 0.9.2.1