Class: RubyDocTest::SpecialDirective
- Defined in:
- lib/special_directive.rb
Constant Summary collapse
- NAMES =
["doctest:", "it:", "!!!", "doctest_require:"]
- NAMES_FOR_RX =
NAMES.map{ |n| Regexp.escape(n) }.join("|")
Instance Method Summary collapse
-
#name ⇒ Object
Test.
-
#value ⇒ Object
Test.
Methods inherited from Lines
#initialize, #inspect, #line_number, #lines, #range
Constructor Details
This class inherits a constructor from RubyDocTest::Lines
Instance Method Details
#name ⇒ Object
Test
doctest: The name of the directive should be detected in the first line
s = RubyDocTest::SpecialDirective.new(["doctest: Testing Stuff", "Other Stuff"]) s.name => "doctest:"
doctest: "it:" is a valid directive
s = RubyDocTest::SpecialDirective.new(["it: should test stuff"]) s.name => "it:"
22 23 24 25 26 |
# File 'lib/special_directive.rb', line 22 def name if m = lines.first.match(/^#{Regexp.escape(indentation)}(#{NAMES_FOR_RX})/) m[1] end end |
#value ⇒ Object
Test
doctest: The value of the directive should be detected in the first line
s = RubyDocTest::SpecialDirective.new(["doctest: Testing Stuff", "Other Stuff"]) s.value => "Testing Stuff"
s = RubyDocTest::SpecialDirective.new([" # doctest: Testing Stuff", " # Other Stuff"]) s.value => "Testing Stuff"
doctest: Multiple lines for the directive value should work as well
s = RubyDocTest::SpecialDirective.new(["doctest: Testing Stuff", " On Two Lines"]) s.value => "Testing Stuff\nOn Two Lines"
doctest: "it" should also work as a directive
s = RubyDocTest::SpecialDirective.new(["it: should do something"]) s.value => "should do something"
48 49 50 51 52 |
# File 'lib/special_directive.rb', line 48 def value if m = lines.join("\n").match(/^#{Regexp.escape(indentation)}(#{NAMES_FOR_RX})(.*)/m) m[2].strip end end |