= TestBelt == Description This is my Ruby testing "tool belt". It packages up the most common testing tools and paradigms I use. It is opinionated and custom to how I like to test. == Installation gem install test-belt TestBelt only impacts your testing environment or setup and is designed only for testing scenarios. Here are a few ways of bringing it in to your tool: * As a development dependency for a gem: Gem::Specification.new do |s| # your spec stuff ... s.add_development_dependency("test-belt") end * As a Gemfile test dependency: source 'http://rubygems.org' # other gem dependencies ... group :test do gem 'test-belt', :require => 'test_belt' # other testing gem dependencies ... end == Test Helpers Requiring test belt loads in the testing libraries I like and use. In your test files or a common test helper file, require in test belt: require 'test_belt' This will give you the following tools. I use most of these helpers in testing this gem. To see examples of these in action, peruse this gem's test files (https://github.com/kelredd/test-belt/tree/master/test) and run the test suite with: $ rake test === Test::Unit just write Test::Unit tests with assertions === Leftright https://github.com/jordi/leftright === Shoulda https://github.com/thoughtbot/shoulda === Shoulda enhancements I've added some handy macros and extensions to some things Shoulda does. None of these are required so just use them as you see fit. Here's a sampling of what is added: * Class interface macros: * should_have_class_methods * should_have_readers * etc * Files macros: * should_have_files * should_have_directories * etc * Context macros: * before/after aliases for setup/teardown * etc === Additional Test::Unit context callbacks I've added some contexts callbacks in addition to the setup/teardown callbacks Shoulda provides: * setup_once / before_once - runs one time before any of the tests in the test case are run * teardown_once / after_once - runs one time after all of the tests in the test case are run * suite_started / on_suite_started - runs one time before any of the tests across the entire test suite are run * suite_finished / on_suite_finished - runs one time after all of the tests across the entire test suite are run === Test::Unit 'skip' directive Test::Unit already provides a 'flunk' directive that will fail the current test. I've added a 'skip' directive that will skip the test when running the suite. I use it to ignore certain tests while I focus on others. Skipping while using LeftRight allows me to ignore the test but not forget about it when looking at my test results. class TestCaseTest < Test::Unit::TestCase context "Something" do should "be something awesome" do skip # anything after the 'skip' directive will not be executed # => use skip(false) to not halt execution assert something_is_in_fact_awesome end end end == Generated Rake tasks === For running tests TestBelt can provide an automatic set of rake tasks for testing subsets of your code base. These tasks are defined based on the structure of your test files. To use this first add this to your Rakefile: require 'rubygems' require 'test_belt/rake_tasks' TestBelt::RakeTasks.for :test # this assumes your test files are located in /test To see what this gives you: $ rake -T === IRB with your environment loaded Many times in developing code, I need to quickly load up IRB with my environment. TestBelt will give you a rake task for doing that. Simply create an env.rb file that loads your environment in your test file directory (/test for example). See https://github.com/kelredd/test-belt/tree/master/test/env.rb and demo for this gem with: $ rake irb > TestBelt => TestBelt > == License Copyright (c) 2010 Kelly D. Redding Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.