Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

James Robertson http://www.r0bertson.co.uk

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

A simple test case using Ruby and XML - Part II

This code tests for the success of a single Class. It reads in the test variables from an xml file and then performs a simple test. Refer to Part I (http://urltea.com/1p7h [dzone.com]) of the ruby code (testdata.rb), and Part III (http://urltea.com/1p7p [dzone.com])

#file: test_feed.rb

require 'testdata.rb'
require 'feed.rb'

include REXML

class Test_feed < Testdata

  def initialize()

    url = 'http://jamesrobertson.eu/test/feed/'
    testfile = "testfile.xml"
    load(url + testfile)

    @in_filepath = get_input('filepath')
    @in_project = get_input('project')
    @in_date = get_input('date')
    @out_filepath = get_output('filepath')
    @out_file = get_output('file')
  end

  def tested
    feed = Feed.new
    feed.create_file(@in_filepath, @in_project)
    File.exist?(@out_filepath + @out_file)
  end

end

#test 
#test_feed = Test_feed.new()
#puts test_feed.tested

A simple test case using Ruby and XML - Part I

Inspired by Gregg Pollack's, Ruby on Rails testing video http://tinyurl.com/ystb4o, this code reads an XML file containing test related variables, to use in an actual test case. Refer to parts II (http://urltea.com/1p7m [dzone.com]), and III (http://urltea.com/1p7p [dzone.com])

#file: testdata.rb

require 'net/http'
require 'rexml/document'

include REXML

class Testdata

  def initialize
  end

  def load(url)
    xml_data = Net::HTTP.get_response(URI.parse(url)).body
    @doc = Document.new(xml_data)
    true
  end

  def get_input(name)
    @doc.root.elements['test/inputs/input/' + name].text
  end

  def get_output(name)
    @doc.root.elements['test/outputs/output/' + name].text
  end

  def tested?()

  end

  def print(method, result)
    puts "<result method='#{method}'>#{result}</result>"
  end

  def plan
    @doc
  end

end

#test 
#url = 'http://m.jamesrobertson.eu/test/testdata/'
#testfile = "testfile.xml"

#td = Testdata.new
#td.load(url + testfile)
#print('get_input', #td.get_input('input1').scan('instring').length > 0)
#print('get_output', td.get_output('output1').scan('outstring').length > 0)

#puts test_feed.tested?


« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS