qed 1.1.0 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,22 +19,29 @@ module Reporter
19
19
  attr :fail
20
20
  attr :error
21
21
 
22
- def initialize(io=STDOUT)
23
- @io = io
24
- @specs = 0
22
+ def initialize(options={})
23
+ @io = options[:io] || STDOUT
24
+ @verbose = options[:verbose]
25
+
26
+ @demos = 0
25
27
  @steps = 0
26
28
  @pass = []
27
29
  @fail = []
28
30
  @error = []
29
31
  end
30
32
 
33
+ #
34
+ def verbose?
35
+ @verbose
36
+ end
37
+
31
38
  # Before running any specifications.
32
39
  def report_intro
33
40
  end
34
41
 
35
42
  # Beginning of a specification.
36
43
  def report_start(spec)
37
- @specs += 1
44
+ @demos += 1
38
45
  end
39
46
 
40
47
  # Report a header.
@@ -67,7 +74,7 @@ module Reporter
67
74
 
68
75
  # Report step raised an error.
69
76
  def report_error(step, exception)
70
- raise exception if $RESPECT_DEBUG
77
+ raise exception if $DEBUG
71
78
  @error << [step, exception]
72
79
  end
73
80
 
@@ -53,7 +53,7 @@ module Reporter #:nodoc:
53
53
  io.puts
54
54
  end
55
55
 
56
- io.puts "%s specs, %s steps, %s failures, %s errors" % [@specs, @steps, @fail.size, @error.size] #, @pass.size ]
56
+ io.puts "%s demos, %s steps, %s failures, %s errors" % [@demos, @steps, @fail.size, @error.size] #, @pass.size ]
57
57
  end
58
58
 
59
59
  end#class DotProgress
@@ -14,9 +14,10 @@ module Reporter #:nodoc:
14
14
  end
15
15
 
16
16
  def report_comment(step)
17
- txt = step.to_s.tabto(2)
17
+ txt = step.to_s.strip.tabto(2)
18
18
  txt[0,1] = "*"
19
19
  io.puts txt
20
+ io.puts
20
21
  end
21
22
 
22
23
  def report_macro(step)
@@ -20,34 +20,34 @@ module Reporter #:nodoc:
20
20
  # end
21
21
  #end
22
22
 
23
+ #def report_intro
24
+ # io.puts
25
+ #end
26
+
23
27
  def report_header(step)
24
- io.puts ANSICode.bold("#{step}")
25
- #io.puts
28
+ io.print ANSICode.bold("#{step}")
26
29
  end
27
30
 
28
31
  def report_comment(step)
29
- io.puts step
30
- #io.puts
32
+ io.print step
31
33
  end
32
34
 
33
35
  #
34
36
  def report_macro(step)
35
37
  #io.puts
36
38
  #io.puts step.text
37
- io.puts ANSICode.magenta("#{step}")
39
+ io.print ANSICode.magenta("#{step}")
38
40
  #io.puts
39
41
  end
40
42
 
41
43
  #
42
44
  def report_pass(step)
43
- io.puts ANSICode.green("#{step}")
44
- #io.puts
45
+ io.print ANSICode.green("#{step}")
45
46
  end
46
47
 
47
48
  def report_fail(step, error)
48
49
  tab = step.to_s.index(/\S/) #step.tab
49
- io.puts ANSICode.red("#{step}")
50
- #puts
50
+ io.print ANSICode.red("#{step}")
51
51
  msg = []
52
52
  msg << ANSICode.bold(ANSICode.red("FAIL: ")) + error.to_str
53
53
  msg << ANSICode.bold(error.backtrace[0].chomp(":in \`_binding'"))
@@ -58,8 +58,7 @@ module Reporter #:nodoc:
58
58
  def report_error(step, error)
59
59
  raise error if $DEBUG
60
60
  tab = step.to_s.index(/\S/) #step.tab
61
- io.puts ANSICode.red("#{step}")
62
- #io.puts
61
+ io.print ANSICode.red("#{step}")
63
62
  msg = []
64
63
  msg << ANSICode.bold(ANSICode.red("ERROR: ")) + error.to_str.sub(/for QED::Context.*?$/,'')
65
64
  msg << ANSICode.bold(error.backtrace[0].chomp(":in \`_binding'"))
@@ -85,6 +84,6 @@ module Reporter #:nodoc:
85
84
 
86
85
  end
87
86
 
88
- end #module
87
+ end #module Reporter
89
88
  end #module QED
90
89
 
data/lib/qed/script.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  module QED
2
+ require 'yaml'
2
3
  require 'facets/dir/ascend'
3
4
 
4
5
  require 'ae'
@@ -32,10 +33,15 @@ module QED
32
33
  @output = output || Reporter::Verbatim.new #(self)
33
34
 
34
35
  source = File.read(file)
35
- index = source.rindex('---')
36
+ index = source.rindex('---') || source.size
36
37
 
37
38
  @source = source[0...index]
38
- @helper = source[index+3...-1].strip
39
+ @helper = source[index+3...-1].to_s.strip
40
+ end
41
+
42
+ # File basename less extension.
43
+ def name
44
+ @name ||= File.basename(file).chomp(File.extname(file))
39
45
  end
40
46
 
41
47
  #def convert
@@ -53,30 +59,82 @@ module QED
53
59
  output.report_header(step)
54
60
  when /^\S/
55
61
  output.report_comment(step)
62
+ context.When.each do |(regex, proc)|
63
+ if md = regex.match(step)
64
+ proc.call(*md[1..-1])
65
+ end
66
+ end
56
67
  else
57
- run_step(step)
68
+ #if context.table
69
+ # run_table(step)
70
+ #else
71
+ run_step(step)
72
+ #end
58
73
  end
59
74
  end
60
75
  end
61
76
 
62
77
  #
63
- def run_step(step, &blk)
64
- context.before.call if context.before
78
+ def run_step(step=nil, &blk)
79
+ context.Before.call if context.Before
65
80
  begin
66
81
  if blk
67
82
  blk.call #eval(step, context._binding)
68
83
  else
69
84
  eval(step, context._binding, @file) # TODO: would be nice to know file and lineno here
70
85
  end
71
- output.report_pass(step)
86
+ output.report_pass(step) if step
72
87
  rescue Assertion => error
73
88
  output.report_fail(step, error)
74
89
  rescue Exception => error
75
90
  output.report_error(step, error)
91
+ ensure
92
+ context.After.call if context.After
93
+ end
94
+ end
95
+
96
+ =begin
97
+ #
98
+ def run_table(step)
99
+ file = context.table
100
+ Dir.ascend(Dir.pwd) do |path|
101
+ f1 = File.join(path, file)
102
+ f2 = File.join(path, 'fixtures', file)
103
+ fr = File.file?(f1) ? f1 : File.exist?(f2) ? f2 : nil
104
+ (file = fr; break) if fr
105
+ end
106
+ output.report_pass(step) #step)
107
+
108
+ tbl = YAML.load(File.new(file))
109
+ key = tbl.shift
110
+ tbl.each do |set|
111
+ assign = key.zip(set).map{ |k, v| "#{k}=#{v.inspect};" }.join
112
+ run_table_step(assign + step, set)
113
+ #run_step(set.inspect.tabto(4)){ blk.call(set) }
114
+ #@_script.run_step(set.to_yaml.tabto(2)){ blk.call(set) }
115
+ #@_script.output.report_table(set)
116
+ end
117
+ #output.report_pass(step) #step)
118
+ context.table = nil
119
+ end
120
+
121
+ #
122
+ #def run_table_step(step, set)
123
+ def run_table_step(set, &blk)
124
+ context.before.call if context.before
125
+ begin
126
+ #eval(step, context._binding, @file) # TODO: would be nice to know file and lineno here
127
+ blk.call(*set)
128
+ output.report_pass(' ' + set.inspect) #step)
129
+ rescue Assertion => error
130
+ output.report_fail(set.inspect, error)
131
+ rescue Exception => error
132
+ output.report_error(set.inspect, error)
76
133
  ensure
77
134
  context.after.call if context.after
78
135
  end
79
136
  end
137
+ =end
80
138
 
81
139
  # Cut-up script into steps.
82
140
  def steps
@@ -88,14 +146,14 @@ module QED
88
146
  if /^\s*$/.match line
89
147
  str << line
90
148
  elsif /^[=]/.match line
91
- steps << str.chomp("\n")
92
- steps << line.chomp("\n")
149
+ steps << str #.chomp("\n")
150
+ steps << line #.chomp("\n")
93
151
  str = ''
94
152
  #str << line
95
153
  code = false
96
154
  elsif /^\S/.match line
97
155
  if code
98
- steps << str.chomp("\n")
156
+ steps << str #.chomp("\n")
99
157
  str = ''
100
158
  str << line
101
159
  code = false
@@ -114,6 +172,7 @@ module QED
114
172
  end
115
173
  end
116
174
  steps << str
175
+ #steps.map{ |s| s.chomp("\n") }
117
176
  steps
118
177
  )
119
178
  end
@@ -128,57 +187,105 @@ module QED
128
187
  #
129
188
  class Context < Module
130
189
 
190
+ TABLE = /^TABLE\[(.*?)\]/i
191
+
131
192
  def initialize(script)
132
193
  @_script = script
194
+ @_when = []
195
+ @_tables = []
133
196
  end
134
197
 
135
198
  def _binding
136
199
  @_binding ||= binding
137
200
  end
138
201
 
139
- # Set before step.
140
- def before(&f)
141
- @_before = f if f
202
+ # Before each step.
203
+ def Before(&procedure)
204
+ @_before = procedure if procedure
142
205
  @_before
143
206
  end
144
207
 
145
- # Set after step.
146
- def after(&f)
147
- @_after = f if f
208
+ # After each step.
209
+ def After(&procedure)
210
+ @_after = procedure if procedure
148
211
  @_after
149
212
  end
150
213
 
151
- # Table-based steps.
152
- def table(file=nil, &blk)
153
- require 'yaml'
154
-
155
- file ||= File.basename(@_script.file).chomp(File.extname(@_script.file)) + '.yaml'
156
-
157
- Dir.ascend(Dir.pwd) do |path|
158
- f1 = File.join(path, file)
159
- f2 = File.join(path, 'fixtures', file)
160
- fr = File.file?(f1) ? f1 : File.exist?(f2) ? f2 : nil
161
- (file = fr; break) if fr
214
+ #
215
+ def When(pattern=nil, &procedure)
216
+ return @_when unless procedure
217
+ raise ArgumentError unless pattern
218
+ unless Regexp === pattern
219
+ pattern = __when_string_to_regexp(pattern)
162
220
  end
221
+ @_when << [pattern, procedure]
222
+ end
163
223
 
224
+ # Table-based steps.
225
+ def Table(file=nil, &blk)
226
+ file = file || @_tables.last
164
227
  tbl = YAML.load(File.new(file))
165
228
  tbl.each do |set|
166
- @_script.run_step(set.to_yaml.tabto(2)){ blk.call(set) }
167
- #@_script.output.report_table(set)
229
+ blk.call(*set)
168
230
  end
231
+ @_tables << file
169
232
  end
170
233
 
171
- def fixture(fname, content=nil)
172
- raise if File.directory?(fname)
234
+ # Read/Write a fixture.
235
+ def Data(file, &content)
236
+ raise if File.directory?(file)
173
237
  if content
174
238
  FileUtils.mkdir_p(File.dirname(fname))
175
- File.open(fname, 'w'){ |f| f << content }
239
+ case File.extname(file)
240
+ when '.yml', '.yaml'
241
+ File.open(file, 'w'){ |f| f << content.call.to_yaml }
242
+ else
243
+ File.open(file, 'w'){ |f| f << content.call }
244
+ end
176
245
  else
177
- raise LoadError, "no such fixture file -- #{fname}" unless File.exist?(fname)
178
- File.read(fname)
246
+ #raise LoadError, "no such fixture file -- #{fname}" unless File.exist?(fname)
247
+ case File.extname(file)
248
+ when '.yml', '.yaml'
249
+ YAML.load(File.new(file))
250
+ else
251
+ File.read(file)
252
+ end
179
253
  end
180
254
  end
181
255
 
256
+ private
257
+
258
+ def __when_string_to_regexp(str)
259
+ str = str.split(/(\(\(.*?\)\))(?!\))/).map{ |x|
260
+ x =~ /\A\(\((.*)\)\)\z/ ? $1 : Regexp.escape(x)
261
+ }.join
262
+ str = str.gsub(/(\\\ )+/, '\s+')
263
+ Regexp.new(str, Regexp::IGNORECASE)
264
+
265
+ #rexps = []
266
+ #str = str.gsub(/\(\((.*?)\)\)/) do |m|
267
+ # rexps << '(' + $1 + ')'
268
+ # "\0"
269
+ #end
270
+ #str = Regexp.escape(str)
271
+ #rexps.each do |r|
272
+ # str = str.sub("\0", r)
273
+ #end
274
+ #str = str.gsub(/(\\\ )+/, '\s+')
275
+ #Regexp.new(str, Regexp::IGNORECASE)
276
+ end
277
+
278
+ #
279
+ # check only local and maybe start paths
280
+ #def __locate_file(file)
281
+ # Dir.ascend(Dir.pwd) do |path|
282
+ # f1 = File.join(path, file)
283
+ # f2 = File.join(path, 'fixtures', file)
284
+ # fr = File.file?(f1) ? f1 : File.exist?(f2) ? f2 : nil
285
+ # (file = fr; break) if fr
286
+ # end
287
+ #end
288
+
182
289
  end
183
290
 
184
291
  end
data/meta/description CHANGED
@@ -1,2 +1,2 @@
1
- QED (Quality Enahancing Demos) is a slick Interface-Driven Development
2
- (IDD) system utilizing Literate Programming concepts.
1
+ QED (Quality Enahancing Demos) is a API-Driven Development
2
+ framework utilizing concepts in Literate Programming.
data/meta/homepage CHANGED
@@ -1 +1 @@
1
- http://proutils.rubyforge.org/qed
1
+ http://proutils.github.com/qed
File without changes
data/meta/repository ADDED
@@ -0,0 +1 @@
1
+ git://github.com/proutils/qed.git
File without changes
data/meta/version CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qed
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: "1.2"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Sawyer <transfire@gmail.com>
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-05 00:00:00 -04:00
12
+ date: 2009-12-07 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -43,9 +43,9 @@ dependencies:
43
43
  version: "0"
44
44
  version:
45
45
  description: |-
46
- QED (Quality Enahancing Demos) is a slick Interface-Driven Development
47
- (IDD) system utilizing Literate Programming concepts.
48
- email: Thomas Sawyer <transfire@gmail.com>
46
+ QED (Quality Enahancing Demos) is a API-Driven Development
47
+ framework utilizing concepts in Literate Programming.
48
+ email:
49
49
  executables:
50
50
  - qedoc
51
51
  - qed
@@ -60,10 +60,12 @@ files:
60
60
  - bin/qed
61
61
  - bin/qedoc
62
62
  - demo/01_spec.qed
63
- - demo/01_spec.yaml
64
- - demo/qed_helper.rb
63
+ - demo/data.txt
64
+ - demo/helper.rb
65
+ - demo/table.yml
65
66
  - doc/qedoc/index.html
66
67
  - doc/qedoc/jquery.js
68
+ - lib/qed/command.rb
67
69
  - lib/qed/document/jquery.js
68
70
  - lib/qed/document/markup.rb
69
71
  - lib/qed/document/template.rhtml
@@ -80,10 +82,11 @@ files:
80
82
  - meta/created
81
83
  - meta/description
82
84
  - meta/homepage
83
- - meta/package
84
- - meta/project
85
+ - meta/name
86
+ - meta/repository
85
87
  - meta/requires
86
88
  - meta/ruby
89
+ - meta/suite
87
90
  - meta/summary
88
91
  - meta/title
89
92
  - meta/version
@@ -92,14 +95,13 @@ files:
92
95
  - COPYING
93
96
  - MANIFEST
94
97
  has_rdoc: true
95
- homepage: http://proutils.rubyforge.org/qed
98
+ homepage: http://proutils.github.com/qed
96
99
  licenses: []
97
100
 
98
101
  post_install_message:
99
102
  rdoc_options:
100
- - --inline-source
101
103
  - --title
102
- - qed api
104
+ - QED API
103
105
  require_paths:
104
106
  - lib
105
107
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -116,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
118
  version:
117
119
  requirements: []
118
120
 
119
- rubyforge_project: proutils
121
+ rubyforge_project: qed
120
122
  rubygems_version: 1.3.5
121
123
  signing_key:
122
124
  specification_version: 3