Created
December 18, 2011 00:49
-
-
Save daveworth/1491978 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
| require 'test_helper' | |
| class TestDynamic < Test::Unit::TestCase | |
| def setup; end | |
| def teardown; end | |
| def test_method1; end | |
| def test_method2; end | |
| end | |
| # This re-opening of the test-suite class is to add the "ugly" | |
| # dynamic `#test_parse_*` methods | |
| class TestDynamic | |
| addrs = [ | |
| {:text => "test_data", | |
| :result => "test data"}, | |
| {:text => "different data", | |
| :result => "different data", | |
| ].each do |fixture| | |
| define_method "test_parse_#{fixture[:text].tr('.,', '').gsub(/\s+/, '_')}" do | |
| assert_equal fixture[:result], some_method(fixture[:text]) | |
| end | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The punchline as to how this works is weird... I wanted to do something like
This does not work because
#setupis only called before each test (kinda likebefore (:each); dofor RSpec). Instead, relying on the fact that all code in a class is executed, works perfectly.