This post originated from an RSS feed registered with Ruby Buzz
by Jay Fields.
Original Post: RubyGems: Dust
Feed Title: Jay Fields Thoughts
Feed URL: http://feeds.feedburner.com/jayfields/mjKQ
Feed Description: Blog about Ruby, Agile, Testing and other topics related to software development.
I've often shown examples similar to the following snippet.
functional_tests do test "given no name, when validated, then error is in the objects error collection"do instance =Klass.new instance.valid? assert_equal "can't be empty", instance.errors.on(:name) end end
Forgetting the body of the test, the interesting thing about the snippet is that it's a grouping of tests that contains a single test. I prefer this syntax to defining a class that inherits from Test::Unit::TestCase and then defining tests by creating methods that start with "test_". All of the projects that I'm a part of use this syntax and I've yet to hear anyone say that they prefer the classic Test::Unit syntax.
Adding this to your project just got a bit easier. I extracted the core methods and created a new gem: Dust.
Dust gives you unit_tests, functional_tests, and test methods that can be used for defining tests. Dust also includes additional methods that can help enforce design decisions. For example, if you subscribe to the theory that setup and helper methods should be removed if possible, the Test::Unit::TestCase.disallow_setup! and Test::Unit::TestCase.disallow_helpers! should interest you.