Created
December 28, 2011 07:43
-
-
Save lsegal/1527001 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TestCaseMixin | |
include YARD::CodeObjects | |
def create_test_method(name) | |
test_name = 'test_' + name.to_s.gsub(/\W/, '_') | |
register MethodObject.new(namespace, test_name, :instance) | |
end | |
end | |
class LegacyTestCaseHandler < YARD::Handlers::Ruby::Legacy::Base | |
include TestCaseMixin | |
handles /^test(?:\(|\s)/ | |
namespace_only | |
process { create_test_method tokval(statement.tokens[2], :attr) } | |
end | |
class TestCaseHandler < YARD::Handlers::Ruby::Base | |
include TestCaseMixin | |
handles method_call(:test) | |
namespace_only | |
process { create_test_method statement.parameters[0].jump(:tstring_content, :ident).source } | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yard' | |
require './a_yard_handler' | |
YARD.parse('test/test_something.rb') | |
obj = YARD::Registry.at('MyTestClass#test_something_1') | |
obj.source # => "def test_something_1\n assert_equals 1, 1\n assert_equals 'foo', 'bar'\nend" | |
obj.line # => 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyTestClass | |
def test_something_1 | |
assert_equals 1, 1 | |
assert_equals 'foo', 'bar' | |
end | |
end |
Nevermind, I just found
http://yardoc.org/guides/extending-yard/writing-handlers.html
And that works great. :)
Having trouble with tests defined dynamically now:
https://github.com/qrush/m/blob/master/test/examples/multiple_example_test.rb
I can just wait until you're up :)
Here's my progress so far, I think I'd prefer to use YARD if it works :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Loren, this doesn't work with dynamically created methods.
m
supportsActiveSupport::TestCase
's#test
method, like here:https://github.com/qrush/m/blob/master/test/examples/active_support_example_test.rb
Basically, doing
YARD::Registry.at("ActiveSupportExampleTest#test_carrot")
doesn't work for me.