testdata 0.8.0 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/testdata.rb +34 -14
  2. metadata +2 -2
@@ -17,9 +17,22 @@ class Testdata
17
17
  @debug = false
18
18
 
19
19
  # open the testdata document
20
- buffer = self.send('read_' + (s[/https?:\/\//] ? 'url' : 'file'), s)
21
- @doc = Document.new(buffer)
20
+ procs = {
21
+ String: proc {|x|
22
+
23
+ if x.strip[/^</] then
24
+ x
25
+ elsif x[/https?:\/\//] then
26
+ read_url x
27
+ else
28
+ read_file x
29
+ end
30
+ },
31
+ Polyrex: proc {|x| x.to_xml}
32
+ }
22
33
 
34
+ buffer = procs[s.class.to_s.to_sym].call(s)
35
+ @doc = Document.new(buffer)
23
36
  o = {log: false}.merge(options)
24
37
  @log = o[:log] == true ? Document.new(tests) : nil
25
38
  end
@@ -37,8 +50,10 @@ class Testdata
37
50
  path_no = node.text('summary/path').to_s
38
51
 
39
52
  xpath = "records/io/summary[type='input']/*"
40
- input_values = XPath.match(node, xpath)[1..-1].map(&stringify)
41
-
53
+ input_nodes = XPath.match(node, xpath)[1..-1]
54
+ input_values = input_nodes.map(&stringify)
55
+ input_names = input_nodes.map(&:name)
56
+
42
57
  # find the type or description
43
58
  xpath = "summary/type/text() | summary/description/text()"
44
59
  type_or_desc = XPath.match(node, xpath).map(&:to_s).find{|x| x != ''}
@@ -47,7 +62,7 @@ class Testdata
47
62
  raw_output = XPath.match(node, xpath)
48
63
  output_values = raw_output.length > 0 ? raw_output[1..-1].map(&stringify) : []
49
64
 
50
- [path_no, input_values, type_or_desc, output_values]
65
+ [path_no, input_values, input_names, type_or_desc, output_values]
51
66
  end
52
67
 
53
68
  def run(x=nil, debug2=nil)
@@ -69,8 +84,8 @@ class Testdata
69
84
 
70
85
  def test_id(id='')
71
86
 
72
- path_no, @inputs, tod, expected = testdata_values(id.to_s)
73
- routes()
87
+ path_no, @inputs, input_names, tod, expected = testdata_values(id.to_s)
88
+ tests() # load the routes
74
89
  raw_actual = run_route tod
75
90
 
76
91
  result = nil
@@ -79,13 +94,17 @@ class Testdata
79
94
  begin
80
95
 
81
96
  if raw_actual then
82
- a = [raw_actual].flatten.map(&:strip)
97
+
98
+ a = raw_actual.is_a?(String) ? [raw_actual].flatten.map(&:strip) : raw_actual
83
99
  b = expected.map(&:strip)
84
100
 
85
101
  if @debug == true or @debug2 == true then
86
- puts "\n" + tod
87
- puts "\nexpected : " + b.inspect
88
- puts "\nactual : " + a.inspect + "\n"
102
+ inputs = input_names.zip(@inputs).map{|x| ' ' + x.join(": ")}\
103
+ .join("\n")
104
+ puts "\ninputs: \n" + inputs
105
+ puts "\ntype or description:\n " + tod
106
+ puts "\nexpected : \n " + b.inspect
107
+ puts "\nactual : \n " + a.inspect + "\n"
89
108
  end
90
109
 
91
110
  result = a == b
@@ -103,22 +122,23 @@ class Testdata
103
122
  end
104
123
  end
105
124
 
106
- def routes(*args)
125
+ def tests(*args)
107
126
  # override this method in the child class
108
127
  end
109
128
 
110
129
  def read_file(s) File.open(s, 'r').read end
111
130
  def read_url(xml_url) open(xml_url, 'UserAgent' => 'S-Rscript').read end
112
131
 
113
- def get(s)
132
+ def test(s)
114
133
  @inputs = @inputs.first if @inputs.length == 1
115
- super(s){yield(@inputs)}
134
+ get(s){yield(@inputs)}
116
135
  end
117
136
 
118
137
  def summary()
119
138
  success = @success.map(&:first)
120
139
  a = @success.map(&:last).sort
121
140
  {
141
+ passed: success.all?,
122
142
  score: [success.grep(true), success].map(&:length).join('/'),
123
143
  failed: @success.select{|x| x[0] == false}.map(&:last).sort
124
144
  }
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: testdata
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.8.0
5
+ version: 0.8.3
6
6
  platform: ruby
7
7
  authors: []
8
8
 
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-31 00:00:00 +01:00
13
+ date: 2011-04-22 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency