matthewrudy-rubydoctest 1.0.1 → 1.0.2
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/runner.rb +16 -1
- data/lib/special_directive.rb +11 -1
- data/rubydoctest.gemspec +1 -1
- metadata +1 -1
data/lib/runner.rb
CHANGED
@@ -299,7 +299,7 @@ module RubyDocTest
|
|
299
299
|
current_statements = []
|
300
300
|
when SpecialDirective
|
301
301
|
case g.name
|
302
|
-
when "doctest:"
|
302
|
+
when "doctest:", "it:"
|
303
303
|
blocks << CodeBlock.new(current_statements) unless current_statements.empty?
|
304
304
|
current_statements = []
|
305
305
|
when "doctest_require:"
|
@@ -352,6 +352,18 @@ module RubyDocTest
|
|
352
352
|
#
|
353
353
|
# >> r.tests.first.code_blocks.size
|
354
354
|
# => 2
|
355
|
+
#
|
356
|
+
# doctest: When using the "it:" directive, it should re-append "it" to the description;
|
357
|
+
# >> r = RubyDocTest::Runner.new("it: should behave\n>> t = 1\n>> t + 2\n=> 3\n>> u = 1", "test.doctest")
|
358
|
+
# >> r.prepare_tests
|
359
|
+
# >> r.tests.size
|
360
|
+
# => 1
|
361
|
+
#
|
362
|
+
# >> r.tests.first.description
|
363
|
+
# => "it should behave"
|
364
|
+
#
|
365
|
+
# >> r.tests.first.code_blocks.size
|
366
|
+
# => 2
|
355
367
|
def organize_tests(blocks = @blocks)
|
356
368
|
tests = []
|
357
369
|
assigned_blocks = nil
|
@@ -365,6 +377,9 @@ module RubyDocTest
|
|
365
377
|
when "doctest:"
|
366
378
|
assigned_blocks = []
|
367
379
|
tests << Test.new(g.value, assigned_blocks)
|
380
|
+
when "it:"
|
381
|
+
assigned_blocks = []
|
382
|
+
tests << Test.new("it #{g.value}", assigned_blocks)
|
368
383
|
when "!!!"
|
369
384
|
tests << g
|
370
385
|
end
|
data/lib/special_directive.rb
CHANGED
@@ -5,7 +5,7 @@ require 'lines'
|
|
5
5
|
|
6
6
|
module RubyDocTest
|
7
7
|
class SpecialDirective < Lines
|
8
|
-
NAMES = ["doctest:", "!!!", "doctest_require:"]
|
8
|
+
NAMES = ["doctest:", "it:", "!!!", "doctest_require:"]
|
9
9
|
NAMES_FOR_RX = NAMES.map{ |n| Regexp.escape(n) }.join("|")
|
10
10
|
|
11
11
|
# === Test
|
@@ -14,6 +14,11 @@ module RubyDocTest
|
|
14
14
|
# >> s = RubyDocTest::SpecialDirective.new(["doctest: Testing Stuff", "Other Stuff"])
|
15
15
|
# >> s.name
|
16
16
|
# => "doctest:"
|
17
|
+
#
|
18
|
+
# doctest: "it:" is a valid directive
|
19
|
+
# >> s = RubyDocTest::SpecialDirective.new(["it: should test stuff"])
|
20
|
+
# >> s.name
|
21
|
+
# => "it:"
|
17
22
|
def name
|
18
23
|
if m = lines.first.match(/^#{Regexp.escape(indentation)}(#{NAMES_FOR_RX})/)
|
19
24
|
m[1]
|
@@ -35,6 +40,11 @@ module RubyDocTest
|
|
35
40
|
# >> s = RubyDocTest::SpecialDirective.new(["doctest: Testing Stuff", " On Two Lines"])
|
36
41
|
# >> s.value
|
37
42
|
# => "Testing Stuff\nOn Two Lines"
|
43
|
+
#
|
44
|
+
# doctest: "it" should also work as a directive
|
45
|
+
# >> s = RubyDocTest::SpecialDirective.new(["it: should do something"])
|
46
|
+
# >> s.value
|
47
|
+
# => "should do something"
|
38
48
|
def value
|
39
49
|
if m = lines.join("\n").match(/^#{Regexp.escape(indentation)}(#{NAMES_FOR_RX})(.*)/m)
|
40
50
|
m[2].strip
|
data/rubydoctest.gemspec
CHANGED