An open API service indexing awesome lists of open source software.

https://github.com/tansengming/yaml_test

Creates unit tests out of YAML files
https://github.com/tansengming/yaml_test

Last synced: 3 months ago
JSON representation

Creates unit tests out of YAML files

Awesome Lists containing this project

README

        

= yaml_test

I build this to make it easier to build unit tests for text processing objects. I.e. instead of typing

# assuming PhoneParser#parse exists.
assert_equal '515-222-1234', PhoneParser.new('You can call me at 515-222-1234').parse
assert_not_equal '515', PhoneParser.new('I live in room 515 but you can call me at 515-222-1234').parse

You'd write a YAML file:
-
text: > You can call me at 515-222-1234
expected: > 515-222-1234
method: parse
-
text: > I live in room 515 but you can call me at 515-222-1234
expected: > 515
method: parse
assertion: assert_not_equal

Which may seem like a waste of keystrokes but generally makes the tests a lot more readable. To include it in your unit tests just include the module and pass in the class you are testing together with the YAML path. Like so:

class TestYamlTest < Test::Unit::TestCase
include YAMLTest

yaml_test ObjectToTest, 'path_to_yaml_file.yml'
end

See tests/test_yaml_test.rb for a working example of how to do this.

== Contributing to yaml_test

* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
* Fork the project
* Start a feature/bugfix branch
* Commit and push until you are happy with your contribution
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

== Copyright

Copyright (c) 2011 SengMing Tan. See LICENSE.txt for
further details.