qed 2.9.2 → 3.0.1

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.
data/lib/qed/parser.rb CHANGED
@@ -62,10 +62,15 @@ module QED
62
62
  # TODO: It would be nice if we could get ther require statement for the
63
63
  # comment mode to be relative to an actual loadpath.
64
64
 
65
+ # A YARD tag or directive at the start of a comment, as in
66
+ # `# @deprecated Use #bar instead.`
67
+ YARD_TAG = /\A@!?((?:\w\.?)+)/
68
+
65
69
  # Parse comment lines into a format that the parse method can use.
66
70
  def parse_comment_lines
67
71
  ruby_omit = false
68
72
  rdoc_omit = false
73
+ yard_tag = nil
69
74
  lines = [
70
75
  [0, "Load #{File.basename(file)} script.\n"],
71
76
  [0, "\n"],
@@ -87,8 +92,12 @@ module QED
87
92
  when /^\s*##/
88
93
  ## skip internal comments
89
94
  when /^\s*\#/
90
- lines << [index, l.lstrip.sub(/^\#\ ?/, '')] unless (ruby_omit or rdoc_omit)
95
+ unless (ruby_omit or rdoc_omit)
96
+ text, yard_tag = yard_comment(l.lstrip.sub(/^\#\ ?/, ''), yard_tag)
97
+ lines << [index, text]
98
+ end
91
99
  else
100
+ yard_tag = nil
92
101
  lines << [index, "\n"] unless lines.last[1] == "\n" unless (ruby_omit or rdoc_omit)
93
102
  end
94
103
  index += 1
@@ -96,35 +105,87 @@ module QED
96
105
  lines
97
106
  end
98
107
 
108
+ # YARD continues a tag's text on the indented lines after it, across
109
+ # blank lines, until a line that is not indented. Those lines are part
110
+ # of the tag, not example code, so they are passed on unindented. The
111
+ # exception is `@example`, whose lines are code.
112
+ #
113
+ # @return [Array(String, String)] The comment text, and the name of the
114
+ # tag it belongs to, if any.
115
+ def yard_comment(text, tag)
116
+ if md = YARD_TAG.match(text)
117
+ [text, md[1]]
118
+ elsif tag.nil? || text.strip.empty?
119
+ [text, tag]
120
+ elsif !text.start_with?(' ', "\t")
121
+ [text, nil]
122
+ elsif tag == 'example'
123
+ [text, tag]
124
+ else
125
+ [text.lstrip, tag]
126
+ end
127
+ end
128
+
99
129
  # Parse demo file into steps.
100
130
  def parse
101
131
  steps = []
102
132
  blank = false
103
133
  indented = false
134
+ fenced = false # inside a ``` ruby/bare code fence
135
+ foreign = false # inside a ``` non-ruby code fence
104
136
  explain = []
105
137
  example = [] #Step.new(file)
106
138
 
107
139
  lines.each do |lineno, line|
108
140
  case line
109
- when /^\s*$/ # blank line
110
- blank = true
111
- if indented
112
- example << [lineno, line]
141
+ when /\A```ruby\s*$/ # ```ruby opens a ruby fence
142
+ fenced = true
143
+ foreign = false
144
+ next
145
+ when /\A```\s*$/ # bare ``` either opens or closes a fence
146
+ if fenced || foreign
147
+ fenced = false
148
+ foreign = false
149
+ next
113
150
  else
114
- explain << [lineno, line]
151
+ fenced = true # bare ``` opens a ruby fence
152
+ next
115
153
  end
116
- when /\A\s+/ #/\A(\t|\ \ +)/ # indented
154
+ when /\A```\S/ # ```<language> opens a foreign fence
155
+ foreign = true
156
+ next
157
+ else
158
+ # skip lines inside foreign code fences
159
+ next if foreign
160
+ end
161
+
162
+ if fenced
163
+ # lines inside a ruby fence are treated as example code
117
164
  indented = true
118
165
  blank = false
119
166
  example << [lineno, line]
120
167
  else
121
- if indented or blank
122
- steps << Step.new(demo, explain, example, steps.last)
123
- explain, example = [], [] #Step.new(file)
168
+ case line
169
+ when /^\s*$/ # blank line
170
+ blank = true
171
+ if indented
172
+ example << [lineno, line]
173
+ else
174
+ explain << [lineno, line]
175
+ end
176
+ when /\A\s+/ # indented
177
+ indented = true
178
+ blank = false
179
+ example << [lineno, line]
180
+ else
181
+ if indented or blank
182
+ steps << Step.new(demo, explain, example, steps.last)
183
+ explain, example = [], []
184
+ end
185
+ indented = false
186
+ blank = false
187
+ explain << [lineno, line]
124
188
  end
125
- indented = false
126
- blank = false
127
- explain << [lineno, line]
128
189
  end
129
190
  end
130
191
  steps << Step.new(demo, explain, example, steps.last)
@@ -1,160 +1,167 @@
1
- # encoding: UTF-8
1
+ require 'erb'
2
+ require 'kramdown'
3
+ require 'qed/reporter/abstract'
2
4
 
3
5
  module QED
4
6
  module Reporter
5
7
 
6
- require 'qed/reporter/abstract'
7
-
8
8
  # = Html Reporter
9
9
  #
10
- # NOTE: This must be completely redesigned since we moved back
11
- # to text based evaluation --which makes generting HTML with
12
- # modifications from the evaluation tricky. But I've come up
13
- # with a farily clever way to handle this. Take the original
14
- # and use Tilt to translate it into HTML, then take the
15
- # evaluation results for code steps and use it to search
16
- # the HTML for "the closest match". Find the \<pre> tag
17
- # associated with the text and add class and color style.
18
- # Of course the tricky part is the matching, but if we
19
- # run the text snippet through Tilt as well we should be
20
- # able to get an exact match. It won't be fast, but it should
21
- # work.
22
-
10
+ # Generates a self-contained HTML report of a QED session,
11
+ # with color-coded pass/fail/error results.
12
+ #
23
13
  class Html < Abstract
24
14
 
25
- #
26
- def initialize(*args)
27
- require 'erb'
28
-
29
- begin
30
- require 'rubygems'
31
- gem 'rdoc'
32
- require 'rdoc'
33
- rescue
34
- end
35
-
36
- super(*args)
37
- end
38
-
39
- #
40
15
  def before_session(session)
41
- io.puts <<-END
42
- <html>
43
- <head>
44
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
45
- <title>QED Report</title>
46
- <style>
47
- body{width:800px; margin:0 auto;}
48
- pre{font-family: courier,monospace;}
49
- .pass{color: #020;}
50
- .pass pre{color: green;}
51
- .fail{color: #200; background: pink;}
52
- .fail pre{color: green;}
53
- .error{color: #200; background: pink;}
54
- .error pre{color: red;}
55
- </style>
56
- </head>
57
- <body>
58
- END
16
+ super(session)
17
+ io.puts HTML_HEAD
59
18
  end
60
19
 
61
- #
62
20
  def before_demo(demo)
63
- io.puts <<-END
64
- <h2>#{localize_file(demo.file)}</h2>
65
- END
21
+ super(demo)
22
+ io.puts %[<div class="demo">]
23
+ io.puts %[<h2 class="demo-file">#{escape(localize_file(demo.file))}</h2>]
66
24
  end
67
25
 
68
26
  def step(step)
69
27
  @_explain = step.explain.dup
70
28
  end
71
29
 
72
- #
73
30
  def match(step, md)
74
- #@match = md
75
31
  unless md[0].empty?
76
- @_explain.sub!(md[0], "<b>#{md[0]}</b>")
32
+ @_explain.sub!(md[0], "<mark>#{escape(md[0])}</mark>")
77
33
  end
78
34
  end
79
35
 
80
- #
81
36
  def pass(step)
82
- io.puts <<-END
83
- <div class="test pass">
84
- #{render(@_explain)}
85
-
86
- <pre>#{step.example}</pre>
87
- </div>
88
- END
37
+ super(step)
38
+ io.puts %[<div class="step pass">]
39
+ io.puts render(@_explain)
40
+ if step.has_example?
41
+ io.puts %[<pre class="code pass">#{escape(step.example)}</pre>]
42
+ end
43
+ io.puts %[</div>]
89
44
  end
90
45
 
91
- #
92
46
  def fail(step, assertion)
93
- io.puts ERB.new(<<-END).result(binding)
94
- <div class="test fail">
95
- #{render(@_explain)}
96
-
97
- <pre>#{step.example}</pre>
98
-
99
- <div class="assertion">
100
- <p>#{assertion.class} - #{assertion.message}</p>
101
- <ol>
102
- <% assertion.backtrace.each do |bt| %>
103
- <li><%= bt %></li>
104
- <% end %>
105
- </ol>
106
- </div>
107
- </div>
108
- END
47
+ super(step, assertion)
48
+ io.puts %[<div class="step fail">]
49
+ io.puts render(@_explain)
50
+ if step.has_example?
51
+ io.puts %[<pre class="code fail">#{escape(step.example)}</pre>]
52
+ end
53
+ io.puts %[<div class="details">]
54
+ io.puts %[<p class="message">FAIL: #{escape(assertion.message)}</p>]
55
+ io.puts %[<pre class="backtrace">#{escape(sane_backtrace(assertion).join("\n"))}</pre>]
56
+ io.puts %[</div>]
57
+ io.puts %[</div>]
109
58
  end
110
59
 
111
- #
112
60
  def error(step, exception)
113
- io.puts ERB.new(<<-END).result(binding)
114
- <div class="test error">
115
- #{render(@_explain)}
116
-
117
- <pre>#{step.example}</pre>
118
-
119
- <div class="exception">
120
- <p>#{exception.class} - #{exception.message}</p>
121
- <ol>
122
- <% exception.backtrace.each do |bt| %>
123
- <li><%= bt %></li>
124
- <% end %>
125
- </ol>
126
- </div>
127
- </div>
128
- END
61
+ super(step, exception)
62
+ io.puts %[<div class="step error">]
63
+ io.puts render(@_explain)
64
+ if step.has_example?
65
+ io.puts %[<pre class="code error">#{escape(step.example)}</pre>]
66
+ end
67
+ io.puts %[<div class="details">]
68
+ io.puts %[<p class="message">ERROR: #{escape(exception.class.to_s)} - #{escape(exception.message)}</p>]
69
+ io.puts %[<pre class="backtrace">#{escape(sane_backtrace(exception).join("\n"))}</pre>]
70
+ io.puts %[</div>]
71
+ io.puts %[</div>]
129
72
  end
130
73
 
131
- #
132
74
  def after_demo(demo)
75
+ super(demo)
76
+ io.puts %[</div>]
133
77
  end
134
78
 
135
- #
136
79
  def after_session(session)
137
- io.puts <<-END
138
- </body>
139
- </html>
140
- END
80
+ super(session)
81
+
82
+ pass_count = passes.size
83
+ fail_count = fails.size
84
+ error_count = errors.size
85
+ total = steps.size
86
+
87
+ status = (fail_count + error_count) == 0 ? 'pass' : 'fail'
88
+
89
+ io.puts %[<div class="summary #{status}">]
90
+ io.puts %[<p>#{demos.size} demos, #{total} steps: #{fail_count} failures, #{error_count} errors</p>]
91
+ io.puts %[<p class="time">Finished in %.5f seconds</p>] % [Time.now - @start_time]
92
+ io.puts %[</div>]
93
+ io.puts HTML_FOOT
141
94
  end
142
95
 
143
96
  private
144
97
 
145
98
  def render(str)
146
- rdoc.convert(str.strip)
99
+ Kramdown::Document.new(str.strip).to_html
147
100
  end
148
101
 
149
- def rdoc
150
- @rdoc ||= RDoc::Markup::ToHtml.new
102
+ def escape(str)
103
+ ERB::Util.html_escape(str.to_s)
151
104
  end
152
105
 
153
- #def h(str)
154
- # ERB::Util.html_escape(str)
155
- #end
156
- end
106
+ HTML_HEAD = <<~'HTML'
107
+ <!DOCTYPE html>
108
+ <html>
109
+ <head>
110
+ <meta charset="utf-8">
111
+ <title>QED Report</title>
112
+ <style>
113
+ * { box-sizing: border-box; margin: 0; padding: 0; }
114
+ body {
115
+ max-width: 860px; margin: 2em auto; padding: 0 1em;
116
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
117
+ font-size: 15px; line-height: 1.6; color: #24292e; background: #fff;
118
+ }
119
+ h1 { font-size: 1.6em; margin: 0 0 1em; padding-bottom: 0.3em; border-bottom: 1px solid #eaecef; }
120
+ h2.demo-file {
121
+ font-size: 1.1em; margin: 1.5em 0 0.5em; padding: 0.4em 0.6em;
122
+ background: #f1f3f5; border-radius: 4px; font-family: monospace;
123
+ }
124
+ .step { margin: 0.5em 0; padding: 0.6em 0.8em; border-left: 3px solid #ddd; }
125
+ .step.pass { border-left-color: #28a745; }
126
+ .step.fail { border-left-color: #d73a49; background: #ffeef0; }
127
+ .step.error { border-left-color: #b31d28; background: #ffeef0; }
128
+ .step p { margin: 0.3em 0; }
129
+ .step h1, .step h2, .step h3 { margin: 0.3em 0; font-size: 1.1em; }
130
+ pre.code {
131
+ margin: 0.4em 0; padding: 0.6em 0.8em;
132
+ font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
133
+ font-size: 13px; line-height: 1.45;
134
+ background: #f6f8fa; border-radius: 4px; overflow-x: auto;
135
+ }
136
+ pre.code.pass { background: #f0fff0; color: #22863a; }
137
+ pre.code.fail { background: #fff0f0; color: #b31d28; }
138
+ pre.code.error { background: #fff0f0; color: #b31d28; }
139
+ .details { margin: 0.4em 0; }
140
+ .details .message { font-weight: 600; color: #d73a49; margin: 0.3em 0; }
141
+ .details .backtrace {
142
+ font-size: 12px; color: #6a737d; background: #fafbfc;
143
+ padding: 0.5em; border-radius: 4px; white-space: pre-wrap;
144
+ }
145
+ .summary {
146
+ margin: 2em 0 1em; padding: 0.8em 1em;
147
+ border-radius: 4px; font-weight: 600;
148
+ }
149
+ .summary.pass { background: #dcffe4; color: #165c26; }
150
+ .summary.fail { background: #ffeef0; color: #b31d28; }
151
+ .summary .time { font-weight: normal; font-size: 0.9em; color: #586069; }
152
+ mark { background: #fff3cd; padding: 0 2px; border-radius: 2px; }
153
+ </style>
154
+ </head>
155
+ <body>
156
+ <h1>QED Report</h1>
157
+ HTML
158
+
159
+ HTML_FOOT = <<~'HTML'
160
+ </body>
161
+ </html>
162
+ HTML
157
163
 
158
- end#module Reporter
159
- end#module QED
164
+ end
160
165
 
166
+ end
167
+ end
@@ -148,8 +148,8 @@ module Reporter #:nodoc:
148
148
  #'expected' => nil,
149
149
  'time' => time_since_start,
150
150
  'exception' => {
151
- 'message' => assertion.message, #unansi
152
- 'class' => assertion.class.name,
151
+ 'message' => exception.message, #unansi
152
+ 'class' => exception.class.name,
153
153
  'file' => file,
154
154
  'line' => line,
155
155
  'source' => source,
data/lib/qed/session.rb CHANGED
@@ -84,7 +84,7 @@ module QED
84
84
 
85
85
  #
86
86
  def directory
87
- settings.tmpdir
87
+ rooted ? settings.root_directory : settings.tmpdir
88
88
  end
89
89
 
90
90
  # Top-level configuration.
@@ -160,7 +160,7 @@ module QED
160
160
 
161
161
  # Clear temporary testing directory.
162
162
  def clear_directory
163
- settings.clear_directory
163
+ settings.clear_directory unless rooted
164
164
  end
165
165
 
166
166
  # Set $ASSERTION_COUNTS to zero point.
@@ -0,0 +1,3 @@
1
+ module QED
2
+ VERSION = '3.0.1'
3
+ end
data/lib/qed.rb CHANGED
@@ -1,24 +1,6 @@
1
- module QED
1
+ require_relative 'qed/version'
2
2
 
3
- # Access to project metadata.
4
- def self.metadata
5
- @metadata ||= (
6
- require 'yaml'
7
- YAML.load(File.new(File.dirname(__FILE__) + '/qed.yml')) rescue {}
8
- )
9
- end
10
-
11
- # Access to project metadata as constants.
12
- def self.const_missing(name)
13
- key = name.to_s.downcase
14
- metadata[key] || super(name)
15
- end
16
-
17
- # TODO: Only b/c of Ruby 1.8.x bug.
18
- VERSION = metadata['version']
19
-
20
- end
3
+ module QED; end
21
4
 
22
5
  require 'qed/session'
23
6
  require 'qed/document'
24
-
metadata CHANGED
@@ -1,86 +1,84 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qed
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.2
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - trans
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2015-03-01 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: ansi
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - '>='
16
+ - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '0'
18
+ version: '1.6'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - '>='
23
+ - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '0'
25
+ version: '1.6'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: brass
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
- - - '>='
30
+ - - "~>"
32
31
  - !ruby/object:Gem::Version
33
- version: '0'
32
+ version: '1.3'
34
33
  type: :runtime
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
- - - '>='
37
+ - - "~>"
39
38
  - !ruby/object:Gem::Version
40
- version: '0'
39
+ version: '1.3'
41
40
  - !ruby/object:Gem::Dependency
42
- name: ae
41
+ name: kramdown
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
- - - '>='
44
+ - - "~>"
46
45
  - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
46
+ version: '2.4'
47
+ type: :runtime
49
48
  prerelease: false
50
49
  version_requirements: !ruby/object:Gem::Requirement
51
50
  requirements:
52
- - - '>='
51
+ - - "~>"
53
52
  - !ruby/object:Gem::Version
54
- version: '0'
53
+ version: '2.4'
55
54
  - !ruby/object:Gem::Dependency
56
- name: rulebow
55
+ name: ae
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
- - - '>='
58
+ - - "~>"
60
59
  - !ruby/object:Gem::Version
61
- version: '0'
60
+ version: '1.9'
62
61
  type: :development
63
62
  prerelease: false
64
63
  version_requirements: !ruby/object:Gem::Requirement
65
64
  requirements:
66
- - - '>='
65
+ - - "~>"
67
66
  - !ruby/object:Gem::Version
68
- version: '0'
67
+ version: '1.9'
69
68
  description: QED (Quality Ensured Demonstrations) is a TDD/BDD framework utilizing
70
69
  Literate Programming techniques.
71
70
  email:
72
71
  - transfire@gmail.com
73
72
  executables:
74
- - qedoc
75
73
  - qed
74
+ - qedoc
76
75
  extensions: []
77
- extra_rdoc_files:
76
+ extra_rdoc_files: []
77
+ files:
78
+ - Gemfile
79
+ - HISTORY.md
78
80
  - LICENSE.txt
79
81
  - README.md
80
- - HISTORY.md
81
- files:
82
- - .index
83
- - .yardopts
84
82
  - bin/qed
85
83
  - bin/qedoc
86
84
  - demo/01_demos.md
@@ -93,6 +91,8 @@ files:
93
91
  - demo/09_cross_script.md
94
92
  - demo/10_constant_lookup.md
95
93
  - demo/11_embedded_rules.md
94
+ - demo/13_fenced_code_blocks.md
95
+ - demo/14_comment_mode.md
96
96
  - demo/99_issues/02_topcode.md
97
97
  - demo/applique/ae.rb
98
98
  - demo/applique/constant.rb
@@ -105,17 +105,19 @@ files:
105
105
  - demo/helpers/toplevel.rb
106
106
  - demo/samples/data.txt
107
107
  - demo/samples/table.yml
108
+ - demo/samples/yard.rb
109
+ - lib/qed.rb
108
110
  - lib/qed/applique.rb
111
+ - lib/qed/cli.rb
109
112
  - lib/qed/cli/qed.rb
110
113
  - lib/qed/cli/qedoc.rb
111
- - lib/qed/cli.rb
112
114
  - lib/qed/configure.rb
113
115
  - lib/qed/core_ext.rb
114
116
  - lib/qed/demo.rb
117
+ - lib/qed/document.rb
115
118
  - lib/qed/document/jquery.js
116
119
  - lib/qed/document/markup.rb
117
120
  - lib/qed/document/template.rhtml
118
- - lib/qed/document.rb
119
121
  - lib/qed/evaluator.rb
120
122
  - lib/qed/helpers/file_fixtures.rb
121
123
  - lib/qed/helpers/shell_session.rb
@@ -132,34 +134,26 @@ files:
132
134
  - lib/qed/settings.rb
133
135
  - lib/qed/step.rb
134
136
  - lib/qed/utils.rb
135
- - lib/qed.rb
136
- - lib/qed.yml
137
- - LICENSE.txt
138
- - HISTORY.md
139
- - README.md
140
- homepage: http://rubyworks.github.com/qed
137
+ - lib/qed/version.rb
138
+ homepage: https://github.com/rubyworks/qed
141
139
  licenses:
142
140
  - BSD-2-Clause
143
141
  metadata: {}
144
- post_install_message:
145
142
  rdoc_options: []
146
143
  require_paths:
147
144
  - lib
148
145
  required_ruby_version: !ruby/object:Gem::Requirement
149
146
  requirements:
150
- - - '>='
147
+ - - ">="
151
148
  - !ruby/object:Gem::Version
152
- version: '0'
149
+ version: '3.1'
153
150
  required_rubygems_version: !ruby/object:Gem::Requirement
154
151
  requirements:
155
- - - '>='
152
+ - - ">="
156
153
  - !ruby/object:Gem::Version
157
154
  version: '0'
158
155
  requirements: []
159
- rubyforge_project:
160
- rubygems_version: 2.0.3
161
- signing_key:
156
+ rubygems_version: 3.6.9
162
157
  specification_version: 4
163
158
  summary: Quod Erat Demonstrandum
164
159
  test_files: []
165
- has_rdoc: