Class: Client
- Inherits:
-
Object
- Object
- Client
- Defined in:
- lib/branston/lib/client.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #generate_story_files ⇒ Object
- #get_xml ⇒ Object
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
- #process_xml(xml) ⇒ Object
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
11 12 13 14 |
# File 'lib/branston/lib/client.rb', line 11 def initialize() self. = self.errors = [] end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
9 10 11 |
# File 'lib/branston/lib/client.rb', line 9 def errors @errors end |
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/branston/lib/client.rb', line 9 def @options end |
Instance Method Details
#generate_story_files ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/branston/lib/client.rb', line 16 def generate_story_files begin return process_xml get_xml rescue StandardError => e errors << "Could not connect to Branston server on " + "#{[:Host]}:#{[:Port]}: #{e.}\n" + "Is Branston running?" end end |
#get_xml ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/branston/lib/client.rb', line 68 def get_xml Net::HTTP.start([:Host] , [:Port]) { |http| req = Net::HTTP::Get.new("/stories/#{[:feature]}.xml") puts "generating /stories/#{[:feature]}.xml" response = http.request(req) xml = REXML::Document.new response.body return xml } end |
#process_xml(xml) ⇒ Object
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 |
# File 'lib/branston/lib/client.rb', line 26 def process_xml(xml) errors.clear if xml.nil? or xml.root.nil? or xml.root.elements.nil? errors << "Did not recieve XML data for story #{[:feature]}.\n" + "Is the Branston server running, and have you provided the correct story name?" else begin root = xml.root story = OpenStruct.new story.description = root.elements["/story/description"].text story.title = root.elements["/story/title"].text story.scenarios = [] root.elements.each("/story/scenarios/scenario") { |scenario| s = OpenStruct.new s.preconditions = [] s.outcomes = [] s.title = scenario.elements["title"].text scenario.elements.each("preconditions/precondition") { |precondition| p = OpenStruct.new p.description = precondition.elements["description"].text s.preconditions << p } scenario.elements.each("outcomes/outcome") { |outcome| o = OpenStruct.new o.description = outcome.elements["description"].text s.outcomes << o } story.scenarios << s } generate(story) rescue StandardError => error errors << "Could not generate feature: " + error end end end |