qed 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,179 @@
1
+ module QED
2
+ require 'facets/dir/ascend'
3
+
4
+ require 'ae'
5
+
6
+ require 'qed/reporter/dotprogress'
7
+ require 'qed/reporter/summary'
8
+ require 'qed/reporter/verbatim'
9
+
10
+ #Assertion = AE::Assertion
11
+ Expectation = Assertor
12
+
13
+ # New Specification
14
+ #def initialize(specs, output=nil)
15
+ # @specs = [specs].flatten
16
+ #end
17
+
18
+ # = Script
19
+ #
20
+ class Script
21
+
22
+ #def self.load(file, output=nil)
23
+ # new(File.read(file), output)
24
+ #end
25
+
26
+ attr :file
27
+ attr :output
28
+
29
+ # New Script
30
+ def initialize(file, output=nil)
31
+ @file = file
32
+ @source = File.read(file)
33
+ @output = output || Reporter::Verbatim.new #(self)
34
+ end
35
+
36
+ #def convert
37
+ # @source.gsub(/^\w/, '# \1')
38
+ #end
39
+
40
+ # Run the script.
41
+ def run
42
+ #steps = @source.split(/\n\s*$/)
43
+ steps.each do |step|
44
+ output.report_step(step)
45
+ case step
46
+ when /^[=#]/
47
+ output.report_header(step)
48
+ when /^\S/
49
+ output.report_comment(step)
50
+ else
51
+ run_step(step)
52
+ end
53
+ end
54
+ end
55
+
56
+ #
57
+ def run_step(step, &blk)
58
+ context.before.call if context.before
59
+ begin
60
+ if blk
61
+ blk.call #eval(step, context._binding)
62
+ else
63
+ eval(step, context._binding, @file) # TODO: would be nice to know file and lineno here
64
+ end
65
+ output.report_pass(step)
66
+ rescue Assertion => error
67
+ output.report_fail(step, error)
68
+ rescue Exception => error
69
+ output.report_error(step, error)
70
+ ensure
71
+ context.after.call if context.after
72
+ end
73
+ end
74
+
75
+ # Cut-up script into steps.
76
+ def steps
77
+ @steps ||= (
78
+ code = false
79
+ str = ''
80
+ steps = []
81
+ @source.each_line do |line|
82
+ if /^\s*$/.match line
83
+ str << line
84
+ elsif /^[=]/.match line
85
+ steps << str.chomp("\n")
86
+ steps << line.chomp("\n")
87
+ str = ''
88
+ #str << line
89
+ code = false
90
+ elsif /^\S/.match line
91
+ if code
92
+ steps << str.chomp("\n")
93
+ str = ''
94
+ str << line
95
+ code = false
96
+ else
97
+ str << line
98
+ end
99
+ else
100
+ if code
101
+ str << line
102
+ else
103
+ steps << str
104
+ str = ''
105
+ str << line
106
+ code = true
107
+ end
108
+ end
109
+ end
110
+ steps << str
111
+ steps
112
+ )
113
+ end
114
+
115
+ # The run context.
116
+ def context
117
+ @context ||= Context.new(self)
118
+ end
119
+
120
+ end
121
+
122
+ #
123
+ class Context < Module
124
+
125
+ def initialize(script)
126
+ @_script = script
127
+ end
128
+
129
+ def _binding
130
+ @_binding ||= binding
131
+ end
132
+
133
+ # Set before step.
134
+ def before(&f)
135
+ @_before = f if f
136
+ @_before
137
+ end
138
+
139
+ # Set after step.
140
+ def after(&f)
141
+ @_after = f if f
142
+ @_after
143
+ end
144
+
145
+ # Table-based steps.
146
+ def table(file=nil, &blk)
147
+ require 'yaml'
148
+
149
+ file ||= File.basename(@_script.file).chomp(File.extname(@_script.file)) + '.yaml'
150
+
151
+ Dir.ascend(Dir.pwd) do |path|
152
+ f1 = File.join(path, file)
153
+ f2 = File.join(path, 'fixtures', file)
154
+ fr = File.file?(f1) ? f1 : File.exist?(f2) ? f2 : nil
155
+ (file = fr; break) if fr
156
+ end
157
+
158
+ tbl = YAML.load(File.new(file))
159
+ tbl.each do |set|
160
+ @_script.run_step(set.to_yaml.tabto(2)){ blk.call(set) }
161
+ #@_script.output.report_table(set)
162
+ end
163
+ end
164
+
165
+ def fixture(fname, content=nil)
166
+ raise if File.directory?(fname)
167
+ if content
168
+ FileUtils.mkdir_p(File.dirname(fname))
169
+ File.open(fname, 'w'){ |f| f << content }
170
+ else
171
+ raise LoadError, "no such fixture file -- #{fname}" unless File.exist?(fname)
172
+ File.read(fname)
173
+ end
174
+ end
175
+
176
+ end
177
+
178
+ end
179
+
@@ -0,0 +1,137 @@
1
+ require 'fileutils'
2
+
3
+ raise "not ready yet"
4
+
5
+ module QED
6
+
7
+ # Extractor is a tool for extracting code from embedded
8
+ # comment blocks.
9
+ #
10
+ # TODO:
11
+ # - Should extract_block handle more than the first matching block?
12
+ # - How can we handle embedded code in standard comments? Eg. #
13
+ #
14
+ module Extract
15
+
16
+ extend self
17
+
18
+ # Extract unit tests. This task scans every package script
19
+ # looking for sections of the form:
20
+ #
21
+ # =begin test
22
+ # ...
23
+ # =end
24
+ #
25
+ # With appropriate headers, it copies these sections to files
26
+ # in your project's test/ dir, which then can be run using the
27
+ # Ratchet test task. The exact directory layout of the files to
28
+ # be tested is reflected in the test directory. You can then
29
+ # use project.rb's test task to run the tests.
30
+ #
31
+ # files Files to extract ['lib/**/*.rb']
32
+ # output Test directory ['test/']
33
+ #
34
+
35
+ def test_extract(files=nil)
36
+ output = 'test/embedded' # Don't think output should be setable.
37
+
38
+ files = files || 'lib/**/*.rb'
39
+ files = 'lib/**/*.rb' if TrueClass == files
40
+ files = [files].flatten.compact
41
+
42
+ filelist = files.collect{ |f| Dir.glob(f) }
43
+ filelist.flatten!
44
+ if filelist.empty?
45
+ puts "No scripts found from which to extract tests."
46
+ return
47
+ end
48
+
49
+ FileUtils.mkdir_p(output) unless File.directory?(output)
50
+
51
+ #vrunner = VerbosityRunner.new("Extracting", verbosity?)
52
+ #vrunner.setup(filelist.size)
53
+
54
+ filelist.each do |file|
55
+ #vrunner.prepare(file)
56
+
57
+ testing = extract_test_from_file( file )
58
+ if testing.strip.empty?
59
+ status = "[NONE]"
60
+ else
61
+ complete_test = create_test(testing, file)
62
+ libpath = File.dirname(file)
63
+ testfile = "test_" + File.basename(file)
64
+ fp = File.join(output, libpath, testfile)
65
+ unless File.directory?( File.dirname(fp))
66
+ FileUtils.mkdir_p(File.dirname(fp))
67
+ end
68
+ File.open(fp, "w"){ |fw| fw << complete_test }
69
+ status = "[TEST]"
70
+ end
71
+
72
+ #vrunner.complete(file, status)
73
+ end
74
+
75
+ #vrunner.finish(
76
+ # :normal => "#{filelist.size} files had tests extracted.",
77
+ # :check => false
78
+ #)
79
+ end
80
+
81
+ private
82
+
83
+ # Extract test from a file's testing comments.
84
+
85
+ def extract_test_from_file(file)
86
+ return nil if ! File.file?(file)
87
+ tests = ""; inside = false
88
+ fstr = File.read(file)
89
+ fstr.split(/\n/).each do |l|
90
+ if l =~ /^=begin[ ]*test/i
91
+ tests << "\n"
92
+ inside = true
93
+ next
94
+ elsif inside and l =~ /^=[ ]*end/
95
+ inside = false
96
+ next
97
+ end
98
+ if inside
99
+ tests << l << "\n"
100
+ end
101
+ end
102
+ tests
103
+ end
104
+
105
+ # Generate the test.
106
+
107
+ def create_test(testing, file)
108
+ fp = file.split(/[\/]/)
109
+ if fp[0] == 'lib'
110
+ reqf = "require '#{fp[1..-1].join('/')}'"
111
+ else
112
+ reqf = ''
113
+ end
114
+ teststr = []
115
+ teststr << "# _____ _"
116
+ teststr << "# |_ _|__ ___| |_"
117
+ teststr << "# | |/ _ \\/ __| __|"
118
+ teststr << "# | | __/\\__ \\ |_"
119
+ teststr << "# |_|\\___||___/\\__|"
120
+ teststr << "#"
121
+ teststr << "# for #{file}"
122
+ teststr << "#"
123
+ teststr << "# Extracted #{Time.now}"
124
+ teststr << "# Project.rb Test Extraction"
125
+ teststr << "#"
126
+ teststr << ""
127
+ teststr << "#{reqf}"
128
+ teststr << ""
129
+ teststr << testing
130
+ teststr << ""
131
+ teststr.join("\n")
132
+ end
133
+
134
+ end #module Extract
135
+
136
+ end #module Quarry
137
+
@@ -0,0 +1,23 @@
1
+ BEGIN {
2
+ module Kernel
3
+
4
+ h = Hash.new
5
+
6
+ define_method(:requiree) do
7
+ h
8
+ end
9
+
10
+ r = method :require
11
+
12
+ define_method(:require) do |a|
13
+ r.call(a)
14
+ h[a] = caller
15
+ end
16
+
17
+ end
18
+ }
19
+
20
+
21
+ def p(*args)
22
+ super *(args << caller[0])
23
+ end
@@ -0,0 +1 @@
1
+ Thomas Sawyer <transfire@gmail.com>
@@ -0,0 +1 @@
1
+ 2006-12-16
@@ -0,0 +1,2 @@
1
+ QED (Quality Enahancing Demos) is a slick Interface-Driven Development
2
+ (IDD) system utilizing Literate Programming concepts.
@@ -0,0 +1 @@
1
+ http://proutils.rubyforge.org/qed
@@ -0,0 +1 @@
1
+ qed
@@ -0,0 +1 @@
1
+ proutils
@@ -0,0 +1 @@
1
+ ae
@@ -0,0 +1,2 @@
1
+ - 1.8.6
2
+ - 1.8.7
@@ -0,0 +1 @@
1
+ Quality Enhanced Demos
@@ -0,0 +1 @@
1
+ QED
@@ -0,0 +1 @@
1
+ 1.0.0
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qed
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Thomas Sawyer <transfire@gmail.com>
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-04 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ae
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: |-
26
+ QED (Quality Enahancing Demos) is a slick Interface-Driven Development
27
+ (IDD) system utilizing Literate Programming concepts.
28
+ email: Thomas Sawyer <transfire@gmail.com>
29
+ executables:
30
+ - qedoc
31
+ - qed
32
+ extensions: []
33
+
34
+ extra_rdoc_files:
35
+ - MANIFEST
36
+ - LICENSE
37
+ - README.rdoc
38
+ - HISTORY
39
+ files:
40
+ - bin/qed
41
+ - bin/qedoc
42
+ - demo/01_spec.qed
43
+ - demo/01_spec.yaml
44
+ - demo/qed_helper.rb
45
+ - doc/qedoc/index.html
46
+ - doc/qedoc/jquery.js
47
+ - lib/qed/assertion.rb
48
+ - lib/qed/document/jquery.js
49
+ - lib/qed/document/markup.rb
50
+ - lib/qed/document/template.rhtml
51
+ - lib/qed/document.rb
52
+ - lib/qed/doubles/mock.rb
53
+ - lib/qed/doubles/spy.rb
54
+ - lib/qed/doubles/stub.rb
55
+ - lib/qed/expectation.rb
56
+ - lib/qed/grammar/assert.rb
57
+ - lib/qed/grammar/expect.rb
58
+ - lib/qed/grammar/legacy/assert.rb
59
+ - lib/qed/grammar/should.rb
60
+ - lib/qed/reporter/base.rb
61
+ - lib/qed/reporter/dotprogress.rb
62
+ - lib/qed/reporter/summary.rb
63
+ - lib/qed/reporter/verbatim.rb
64
+ - lib/qed/runner.rb
65
+ - lib/qed/script.rb
66
+ - lib/qed/utilities/extract.rb
67
+ - lib/qed/utilities/monitor.rb
68
+ - lib/qed.rb
69
+ - meta/authors
70
+ - meta/created
71
+ - meta/description
72
+ - meta/homepage
73
+ - meta/package
74
+ - meta/project
75
+ - meta/requires
76
+ - meta/ruby
77
+ - meta/summary
78
+ - meta/title
79
+ - meta/version
80
+ - LICENSE
81
+ - README.rdoc
82
+ - HISTORY
83
+ - MANIFEST
84
+ has_rdoc: true
85
+ homepage: http://proutils.rubyforge.org/qed
86
+ licenses: []
87
+
88
+ post_install_message:
89
+ rdoc_options:
90
+ - --inline-source
91
+ - --title
92
+ - qed api
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: "0"
100
+ version:
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: "0"
106
+ version:
107
+ requirements: []
108
+
109
+ rubyforge_project: proutils
110
+ rubygems_version: 1.3.5
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Quality Enhanced Demos
114
+ test_files: []
115
+