pax_global_header00006660000000000000000000000064116426071460014521gustar00rootroot0000000000000052 comment=180c21c86d9987db37d63a1e8d4df3ef698e2764 ruby-contest-0.1.3/000077500000000000000000000000001164260714600141605ustar00rootroot00000000000000ruby-contest-0.1.3/LICENSE000066400000000000000000000021051164260714600151630ustar00rootroot00000000000000Copyright (c) 2009 Damian Janowski and Michel Martens for Citrusbyte 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. ruby-contest-0.1.3/README.markdown000066400000000000000000000054161164260714600166670ustar00rootroot00000000000000Contest ======= Contexts for Test::Unit. Description ----------- Write declarative tests using nested contexts without performance penalties. Contest is less than 100 lines of code and gets the job done. Usage ----- Declare your tests as you would in RSpec or Shoulda: require 'contest' class SomeTest < Test::Unit::TestCase setup do @value = 1 end teardown do @value = nil end test "sample test" do assert_equal 1, @value end context "a context" do setup do @value += 1 end test "more tests" do assert_equal 2, @value end context "a nested context" do setup do @value += 1 end test "yet more tests" do assert_equal 3, @value end end end end For your convenience, `context` is aliased as `describe` and `test` is aliased as `should`, so this is valid: class SomeTest < Test::Unit::TestCase setup do @value = 1 end describe "something" do setup do @value += 1 end should "equal 2" do assert_equal 2, @value end end end You can run it normally, it's Test::Unit after all. If you want to run a particular test, say "yet more tests", try this: $ testrb my_test.rb -n test_yet_more_tests Or with a regular expression: $ testrb my_test.rb -n /yet_more_tests/ Installation ------------ $ sudo gem install contest If you want to use it with Rails, add this to config/environment.rb: config.gem "contest" Then you can vendor the gem: rake gems:install rake gems:unpack License ------- Copyright (c) 2009 Damian Janowski and Michel Martens for Citrusbyte 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. ruby-contest-0.1.3/Rakefile000066400000000000000000000002331164260714600156230ustar00rootroot00000000000000require 'rake' require 'rake/testtask' task :default => :test Rake::TestTask.new(:test) do |t| t.pattern = 'test/**/*_test.rb' t.verbose = false end ruby-contest-0.1.3/lib/000077500000000000000000000000001164260714600147265ustar00rootroot00000000000000ruby-contest-0.1.3/lib/contest.rb000066400000000000000000000033461164260714600167400ustar00rootroot00000000000000require "test/unit" # Test::Unit loads a default test if the suite is empty, whose purpose is to # fail. Since having empty contexts is a common practice, we decided to # overwrite TestSuite#empty? in order to allow them. Having a failure when no # tests have been defined seems counter-intuitive. class Test::Unit::TestSuite def empty? false end end # Contest adds +teardown+, +test+ and +context+ as class methods, and the # instance methods +setup+ and +teardown+ now iterate on the corresponding # blocks. Note that all setup and teardown blocks must be defined with the # block syntax. Adding setup or teardown instance methods defeats the purpose # of this library. class Test::Unit::TestCase def self.setup(&block) define_method :setup do super(&block) instance_eval(&block) end end def self.teardown(&block) define_method :teardown do instance_eval(&block) super(&block) end end def self.context(*name, &block) subclass = Class.new(self) remove_tests(subclass) subclass.class_eval(&block) if block_given? const_set(context_name(name.join(" ")), subclass) end def self.test(name, &block) define_method(test_name(name), &block) end class << self alias_method :should, :test alias_method :describe, :context end private def self.context_name(name) "Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}".to_sym end def self.test_name(name) "test_#{sanitize_name(name).gsub(/\s+/,'_')}".to_sym end def self.sanitize_name(name) name.gsub(/\W+/, ' ').strip end def self.remove_tests(subclass) subclass.public_instance_methods.grep(/^test_/).each do |meth| subclass.send(:undef_method, meth.to_sym) end end end ruby-contest-0.1.3/metadata.yml000066400000000000000000000024061164260714600164650ustar00rootroot00000000000000--- !ruby/object:Gem::Specification name: contest version: !ruby/object:Gem::Version prerelease: version: 0.1.3 platform: ruby authors: - Damian Janowski - Michel Martens autorequire: bindir: bin cert_chain: [] date: 2011-05-08 00:00:00 Z dependencies: [] description: Write declarative tests using nested contexts without performance penalties. Contest is less than 100 lines of code and gets the job done. email: - djanowski@dimaion.com - michel@soveran.com executables: [] extensions: [] extra_rdoc_files: [] files: - lib/contest.rb - README.markdown - LICENSE - Rakefile - rails/init.rb - test/all_test.rb - test/setup_and_teardown_order_test.rb homepage: http://github.com/citrusbyte/contest licenses: [] post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ">=" - !ruby/object:Gem::Version version: "0" required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ">=" - !ruby/object:Gem::Version version: "0" requirements: [] rubyforge_project: contest rubygems_version: 1.8.1 signing_key: specification_version: 3 summary: Write more readable tests in Test::Unit with this tiny script. test_files: [] ruby-contest-0.1.3/rails/000077500000000000000000000000001164260714600152725ustar00rootroot00000000000000ruby-contest-0.1.3/rails/init.rb000066400000000000000000000012401164260714600165570ustar00rootroot00000000000000# ActiveStupor defines its own idiom for the class-level setup method # (using callback chains). This hack is to ensure that Contest users can # still call the setup method with a block. if RAILS_ENV == 'test' require File.join(File.dirname(__FILE__), '..', 'lib', 'contest') require "active_support/test_case" class Test::Unit::TestCase class << self alias contest_setup setup end end class ActiveSupport::TestCase class << self alias activesupport_setup setup end def self.setup(*args, &block) if args.empty? contest_setup(&block) else activesupport_setup(*args) end end end end ruby-contest-0.1.3/test/000077500000000000000000000000001164260714600151375ustar00rootroot00000000000000ruby-contest-0.1.3/test/all_test.rb000066400000000000000000000037061164260714600173010ustar00rootroot00000000000000require File.expand_path(File.join("..", "lib", "contest"), File.dirname(__FILE__)) class FooTest < Test::Unit::TestCase setup do @value = 1 end teardown do @value = nil end test "truth" do assert_equal 1, @value end context "context's non-word characters " do should "run the test inside" do assert_equal 1, @value end end context "context", "with multiple", "arguments", 123, FooTest do should "run the test inside" do assert_equal 1, @value end end context "some context" do setup do @value += 1 end test "another truth" do assert_equal 2, @value end context "and a nested context" do setup do @value += 1 end test "more" do assert_equal 3, @value end end end context "some other context" do setup do @value += 1 end test "yet another truth" do assert_equal 2, @value end end describe "context with should" do setup do @value += 1 end should "yet another truth" do assert_equal 2, @value end end end class BarTest < Test::Unit::TestCase setup do @value = 1 end context "some context" do setup do @value += 1 end test "another truth" do assert_equal 2, @value end test "yet another truth" do assert_equal 2, @value end end end class TestBaz < Test::Unit::TestCase def foo 42 end def setup @value = 1 super end context "some context" do def setup super @value += 2 end def bar foo + 1 end test "a helper" do assert_equal 42, foo assert_equal 3, @value end test "another helper" do assert_equal 43, bar end context "another context" do setup do @value += 3 end test "blah" do assert_equal 6, @value end end end context "empty context" end ruby-contest-0.1.3/test/setup_and_teardown_order_test.rb000066400000000000000000000013201164260714600235770ustar00rootroot00000000000000require File.expand_path(File.join("..", "lib", "contest"), File.dirname(__FILE__)) class BaseTest < Test::Unit::TestCase def setup @order = [] @order << "Grandparent Setup" end def teardown @order << "Grandparent Teardown" assert_equal ["Grandparent Setup", "Parent Setup", "Child Setup", "Test Case", "Child Teardown", "Parent Teardown", "Grandparent Teardown"], @order end end class MidLayerTest < BaseTest setup { @order << "Parent Setup" } teardown { @order << "Parent Teardown" } end class LeafTest < MidLayerTest setup { @order << "Child Setup" } teardown { @order << "Child Teardown" } test "my actual test" do @order << "Test Case" end end