public
Description: A super tight library to add contexts to tests.
Homepage:
Clone URL: git://github.com/jeremymcanally/context.git
Click here to lend your support to: context and make a donation at www.pledgie.com !
name age message
file .gitignore Sat Nov 08 20:31:45 -0800 2008 Ignore pkg [jeremymcanally]
file History.txt Mon Oct 06 13:04:06 -0700 2008 Tweak the way contexts are defined [jeremymcanally]
file License.txt Fri Oct 03 10:02:50 -0700 2008 First commit [jeremymcanally]
file Manifest.txt Tue Jan 06 18:33:13 -0800 2009 Add hacks for Shoulda + Rails. Rails adds setu... [jeremymcanally]
file PostInstall.txt Fri Oct 03 10:18:21 -0700 2008 Clear out PostInstall.txt for now [jeremymcanally]
file README.rdoc Fri Oct 10 01:15:05 -0700 2008 Shared behaviors. Still trying to figure out w... [jeremymcanally]
file Rakefile Fri Oct 03 10:02:50 -0700 2008 First commit [jeremymcanally]
directory config/ Sat Oct 11 07:24:06 -0700 2008 Don't need all that junk [jeremymcanally]
file context.gemspec Sat Jan 31 07:31:01 -0800 2009 Bump version. Fixed a few annoying bugs! [Jeremy McAnally]
file countloc.rb Tue Feb 10 23:23:40 -0800 2009 Added test for nested lifecycles. Signed-off-b... [mhennemeyer]
directory coverage/ Mon Jan 05 16:17:09 -0800 2009 Add support for Shoulda-esque setup/do blocks. ... [jeremymcanally]
directory lib/ Tue Feb 10 23:24:13 -0800 2009 Care about Rails tests in nested contexts. Sig... [mhennemeyer]
file setup.rb Fri Oct 03 10:02:50 -0700 2008 First commit [jeremymcanally]
directory tasks/ Fri Oct 03 10:10:16 -0700 2008 Pare the crap back a little bit [jeremymcanally]
directory test/ Tue Feb 10 23:23:40 -0800 2009 Added test for nested lifecycles. Signed-off-b... [mhennemeyer]
README.rdoc

context – The testing library you’ve been looking for

github.com/jeremymcanally/context

DESCRIPTION:

If you’ve ever wanted contexts in your Test::Unit tests, then context is for you. Your tests will be easier to read and write without all the magic and extra code smell!

FEATURES/PROBLEMS:

  • Add contexts to Test::Unit tests
  • Small DSL for specifying tests that are pretty
  • Ability to chain context lifecycle methods (coming soon)

SYNOPSIS:

  • Add contexts using familiar syntax:
        class UserTest < Test::Unit::TestCase
          context "A new User" do
            # Before/after lifecycle blocks
            before do
              @user = User.first
            end
    
            # Specify tests using DSL
            test "should have the right full_name" do
              assert_equal "Dude Man", @user.full_name
            end
    
            test "should be able to set parts of the name" do
              @user.first_name = "Mad"
              @user.last_name = "Max"
              @user.save
              assert_equal "Mad Max", @user.full_name
            end
    
            after do
              @user.first_name = "Dude"
              @user.last_name = "Man"
              @user.save!
            end
          end
        end
    
  • It also has aliases that match other library’s syntaxes (all of which can be mixed and matched):
        class UserTest < Test::Unit::TestCase
          context "A new Account" do
            test "should be new" do
              Account.new.new_record?
            end
          end
    
          # RSpec-esque
          describe "A new User" do
            it "should do things" do
              User.first.do_things!
            end
          end
    
          # Shoulda-esque
          context "Another User" do
            should "do things that are fun" do
              User.first.do_things!(:fun)
            end
          end
        end
    
  • Contexts can also be nested:
      class UserTest < Test::Unit::TestCase
        context "A new User" do
          context "with clown shoes" do
            test "should squeak" do
              assert_true User.find_by_shoes("clown").squeak?
            end
          end
    
          context "without clown shoes" do
            test "should not squeak" do
              assert_false User.find_by_shoes("dressy").squeak?
            end
          end
        end
      end
    
  • You can also share behavior among contexts:
      class UserTest < Test::Unit::TestCase
        shared "shared things" do
          test "things are shared" do
            # test logic here...
          end
        end
    
        context "the first thing" do
          uses "shared things"
    
          test "other things..." do
            # More testing...
          end
        end
      end
    
  • Shared behaviors can also use RSpec syntax
      class UserTest < Test::Unit::TestCase
        share_examples_for "shared things" do
          it "things are shared" do
            # test logic here...
          end
        end
    
        describe "the first thing" do
          it_should_behave_like "shared things"
    
          it "other things..." do
            # More testing...
          end
        end
      end
    

REQUIREMENTS:

  • Test::Unit (you have it; trust me)

INSTALL:

    $ gem sources -a http://gems.github.com
    $ sudo gem install jeremymcanally-context

LICENSE:

Copyright © 2008 Jeremy McAnally

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.

ACKNOWLEDGEMENTS:

Original implementation by myself, but heavily tweaked and borrowed from Rails Core and Pratik Naik.