testdata 0.2.8 → 0.2.9

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 +40 -0
  2. metadata +2 -2
data/lib/testdata.rb CHANGED
@@ -56,6 +56,7 @@ class Testdata
56
56
 
57
57
  def initialize(s)
58
58
  #puts 'filex : ' + $0
59
+ @filepath = File.dirname s
59
60
  buffer = self.send('read_' + (s[/https?:\/\//] ? 'file' : 'url'), s)
60
61
  @doc = Document.new(buffer)
61
62
  raise "Testdata error: doc %s not found" % s unless @doc
@@ -73,6 +74,45 @@ class Testdata
73
74
  {false: @success.select{|x| x[0] == false}.map(&:last).sort,
74
75
  nil: ((a[0]..a[-1]).to_a - a)}
75
76
  end
77
+
78
+ def tests()
79
+ script = XPath.first(@doc.root, "summary/script/text()").to_s
80
+ s = File.open(@filepath + '/' + script,'r').read
81
+
82
+ stringify = Proc.new {|x| x.text.to_s.gsub(/[\n\s]/,'').length > 0 ? x.text : x.cdatas.join.strip}
83
+
84
+ raw_paths = s[/testdata\.paths(.*)(?=end)/m,1].split(/(?=path\.tested\?)/)
85
+ raw_paths.shift
86
+
87
+ content = raw_paths.map do |x|
88
+ title = x[/path\.tested\?\s(.*)\sdo/,1][1..-2]
89
+ path_test = x[/def.*(?=end)/m]
90
+ raw_vars = path_test[/def path.test\(([^\)]+)/,1]
91
+ vars = raw_vars.split(/\s*,\s*/) if raw_vars
92
+ body = path_test[/def path\.test\([^\)]*\)(.*)(?=end)/m,1]
93
+ [title, vars, body]
94
+ end
95
+
96
+ r = (0..content.length - 1).map do |i|
97
+ node = XPath.first(@doc.root, "records/test[#{i+1}]")
98
+ input_values = XPath.match(node, "records/io/summary[type='input']/*").map(&stringify)
99
+ path_no = node.text('summary/path').to_s
100
+ output_values = XPath.match(node, "records/io/summary[type='output']/*").map(&stringify)
101
+ raw_output = (output_values - ['output'])
102
+ output = "#=> " + raw_output.join("\n")
103
+
104
+ values = input_values - ['input']
105
+ body = content[i][2].strip.gsub("\n ","\n")
106
+ if content[i][1] then
107
+ content[i][1].zip(values).each do |keyword, value|
108
+ body.gsub!(/#{keyword}(?!:)/, value)
109
+ end
110
+ end
111
+ ["# #{path_no}) #{content[i][0]}\n", body + "\n", output + "\n\n"]
112
+ end
113
+
114
+ r.each {|x| x.join("\n")}.join("\n")
115
+ end
76
116
 
77
117
  def find_by(s)
78
118
  XPath.match(@doc.root, "records/test/summary[type='#{s}']/description/text()").map(&:to_s)
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.8
4
+ version: 0.2.9
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-27 00:00:00 +00:00
12
+ date: 2011-01-03 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies: []
15
15