testdata 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/testdata.rb +19 -26
- metadata +2 -2
data/lib/testdata.rb
CHANGED
@@ -4,38 +4,19 @@
|
|
4
4
|
|
5
5
|
require 'rexml/document'
|
6
6
|
|
7
|
-
class Select
|
8
|
-
include REXML
|
9
|
-
|
10
|
-
def initialize(type, node) @node, @type = node, type end
|
11
|
-
|
12
|
-
def data(*raw_x)
|
13
|
-
|
14
|
-
stringify = Proc.new {|x| x.texts.length <= 1 ? x.text : x.cdatas.join.strip}
|
15
|
-
|
16
|
-
procs = {}
|
17
|
-
procs[:String] = Proc.new do |type,x|
|
18
|
-
e = XPath.first(@node, "records/io/summary[type='#{type}']/#{x}")
|
19
|
-
stringify.call(e)
|
20
|
-
end
|
21
|
-
procs[:Array] = Proc.new do |type,a|
|
22
|
-
xpath = a.map {|x| "records/io/summary[type='#{type}']/#{x}"}.join(' | ')
|
23
|
-
XPath.match(@node, xpath).map {|x| stringify.call(x)}
|
24
|
-
end
|
25
|
-
|
26
|
-
x = raw_x.length > 1 ? raw_x : raw_x[0]
|
27
|
-
values = procs[x.class.to_s.to_sym].call(@type, x)
|
28
|
-
block_given? ? yield(values) : values
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
7
|
class Path
|
33
8
|
include REXML
|
34
9
|
|
35
10
|
def initialize(doc, success) @doc, @success = doc, success end
|
36
11
|
|
37
12
|
def tested? description
|
13
|
+
|
14
|
+
stringify = Proc.new {|x| x.text.to_s.gsub(/[\n\s]/,'').length > 0 ? x.text : x.cdatas.join.strip}
|
15
|
+
|
38
16
|
node = XPath.first(@doc.root, "records/test[summary/description='#{description}']")
|
17
|
+
input_values = XPath.match(node, "records/io/summary[type='input']/*").map(&stringify)
|
18
|
+
output_values = XPath.match(node, "records/io/summary[type='output']/*").map(&stringify)
|
19
|
+
|
39
20
|
path_no = node.text('summary/path')
|
40
21
|
raise "Path error: node not found" unless node
|
41
22
|
|
@@ -43,13 +24,24 @@ class Path
|
|
43
24
|
@success << [nil, path_no.to_i]
|
44
25
|
|
45
26
|
begin
|
46
|
-
|
27
|
+
|
28
|
+
values = input_values - ['input']
|
29
|
+
expected = (output_values - ['output']).first
|
30
|
+
|
31
|
+
yield
|
32
|
+
|
33
|
+
raw_result = test(*values)
|
34
|
+
result = raw_result.strip == expected.strip
|
35
|
+
|
47
36
|
rescue
|
48
37
|
result = false
|
49
38
|
ensure
|
50
39
|
@success[-1][0] = result
|
51
40
|
end
|
52
41
|
end
|
42
|
+
|
43
|
+
def test(*values)
|
44
|
+
end
|
53
45
|
end
|
54
46
|
|
55
47
|
class Testdata
|
@@ -58,6 +50,7 @@ class Testdata
|
|
58
50
|
attr_reader :success
|
59
51
|
|
60
52
|
def initialize(s)
|
53
|
+
#puts 'filex : ' + $0
|
61
54
|
buffer = self.send('read_' + (s[/https?:\/\//] ? 'file' : 'url'), s)
|
62
55
|
@doc = Document.new(buffer)
|
63
56
|
raise "Testdata error: doc %s not found" % s unless @doc
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: testdata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors: []
|
7
7
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-12-23 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|