test-unit-context-0.5.1/0000755000004100000410000000000013316030414015156 5ustar www-datawww-datatest-unit-context-0.5.1/.travis.yml0000644000004100000410000000076513316030414017277 0ustar www-datawww-datalanguage: ruby rvm: - 1.9.3 - 2.2.3 - 2.3.0 - jruby-1.7.22 - jruby-9.0.4.0 jdk: - openjdk7 env: - TEST_UNIT="~> 2.5" - TEST_UNIT="~> 3.0" - TEST_UNIT="~> 3.1" before_install: - ((ruby -v | grep 1.8.7) && ruby -S gem install bundler -v '~> 1.8.9') || true - ((ruby -v | grep 1.9.3) && ruby -S gem install bundler -v '~> 1.8.9') || true matrix: include: - rvm: 1.8.7 env: TEST_UNIT="~> 2.5" jdk: openjdk6 # jdk_switcher use ["openjdk7"]" failed and exited with 1 test-unit-context-0.5.1/test/0000755000004100000410000000000013316030414016135 5ustar www-datawww-datatest-unit-context-0.5.1/test/test/0000755000004100000410000000000013316030414017114 5ustar www-datawww-datatest-unit-context-0.5.1/test/test/unit/0000755000004100000410000000000013316030414020073 5ustar www-datawww-datatest-unit-context-0.5.1/test/test/unit/patches_test.rb0000644000004100000410000000166213316030414023113 0ustar www-datawww-datarequire File.expand_path('../../test_helper', File.dirname(__FILE__)) class PatchesTest < Test::Unit::TestCase self.test_order = :alphabetic @@tests_run = [] def self.add_test(test) @@tests_run << test end module TestMethods def test_1 PatchesTest.add_test :test_1 end end include TestMethods def test_2 PatchesTest.add_test :test_2 end context do def test_3 PatchesTest.add_test :test_3 end end context 'empty' do end extend Test::Unit::Assertions def self.shutdown assert_equal [:test_1, :test_2, :test_3], @@tests_run end end #module TestMethods # # def test_0 # puts 0 # end # #end # #class Test1 < Test::Unit::TestCase # include TestMethods # # def test_1 # puts 1 # end # # test # def a_test_1x # puts '1x' # end # #end # #class Test2 < Test1 # # def test_2 # puts 2 # end # # test # def a_test_2x # puts '2x' # end # #endtest-unit-context-0.5.1/test/test/unit/context_test.rb0000644000004100000410000001304713316030414023150 0ustar www-datawww-datarequire File.expand_path('../../test_helper', File.dirname(__FILE__)) module Test::Unit class TestContext < Test::Unit::TestCase def test_test_without_context assert true end test "another test without a context" do assert true end def test_context_aliases assert self.class.respond_to? :context assert self.class.respond_to? :contexts end def test_context_naming Class.new(Test::Unit::TestCase) do context("kiss = simple_name") {} context("a_(not-so)_simple; name") {} context("an '&\" name !?") {} end end class Default < Test::Unit::TestCase @_context_ = context "When testing" do def test_this_thing true end end context "More testing" do # @todo implement more tests here ... end end setup do @default_context = Default.instance_variable_get :@_context_ end test "[default context] sets the context name" do assert_equal "When testing", @default_context.context_name end test "[default context] is a Test::Unit::TestCase" do assert @default_context.ancestors.include?(Test::Unit::TestCase) end test "[default context] is defived from the test class" do assert_equal Default, @default_context.superclass end test "[default context] reports among test case's context defs" do assert Default.respond_to?(:context_definitions) assert_include Default.context_definitions, @default_context assert_equal 2, Default.context_definitions.size end test "has a (context name derived) class name" do namespace = 'Test::Unit::TestContext::Default::' assert_equal "#{namespace}ContextWhenTesting", @default_context.name end class Anonymous < Test::Unit::TestCase @@_context_ = self.context do def test_some_thing true end end context do test 'another_thing' do end end context do # end end setup do @anonymous_context = Anonymous.send :class_variable_get, :@@_context_ end test "[anonymous context] has a generated context name" do assert_not_nil @anonymous_context.name end test "[anonymous context] is defived from the test class" do assert_equal Anonymous, @anonymous_context.superclass end test "[anonymous context] reports among test case's context defs" do assert Anonymous.respond_to?(:context_definitions) assert_include Anonymous.context_definitions, @anonymous_context assert_equal 3, Anonymous.context_definitions.size assert_equal 3, Anonymous.context_definitions(true).size end test "[anonymous context] has a (context name derived) class name" do namespace = 'Test::Unit::TestContext::Anonymous::' context_name = @anonymous_context.context_name assert_equal "#{namespace}Context#{context_name}", @anonymous_context.name end class Nested < Test::Unit::TestCase @@_context_ = context "and we're testing" do @nested = context "should be nested" do def test_a_thing true end end def self.nested; @nested; end end end setup do @parent_context = Nested.send :class_variable_get, :@@_context_ @nested_context = @parent_context.nested end test "[nested context] sets a nested context name" do assert_equal "and we're testing should be nested", @nested_context.context_name end test "[nested context] is also a Test::Unit::TestCase" do assert @nested_context.ancestors.include?(Test::Unit::TestCase) end test "[nested context] is defived from the prev context class" do assert_equal @parent_context, @nested_context.superclass end test "[nested context] reports context defs correctly" do assert Nested.respond_to?(:context_definitions) assert_equal 1, Nested.context_definitions.size assert_equal 1, @parent_context.context_definitions.size assert_equal 0, @nested_context.context_definitions.size assert_equal 2, Nested.context_definitions(true).size end test "[nested context] has a (context name derived) class name" do namespace = 'Test::Unit::TestContext::Nested::' assert_equal "#{namespace}ContextAndWeReTesting::ContextShouldBeNested", @nested_context.name end class Redefined < Test::Unit::TestCase CONTEXT = context 42 do def test_everything true end end @@warns = nil def self.warn(message) ( @@warns ||= [] ) << message end def self.warns; @@warns; end def self.reset_warns; @@warns = nil; end end setup do @redefined_context = Redefined::CONTEXT end test "[redefined context] sets the context name" do assert_equal 42, @redefined_context.context_name end test "[redefined context] warns when same context name used" do assert_nil Redefined.warns class Redefined context 42 do def test_something_else assert true end end end assert_not_nil Redefined.warns assert_equal 2, @redefined_context.instance_methods(false).grep(/test/).size Redefined.reset_warns assert_nil Redefined.warns class Redefined context '42' do # same class-name def test_a_little_thing end end end assert_not_nil Redefined.warns assert_equal 3, @redefined_context.instance_methods(false).grep(/test/).size end end endtest-unit-context-0.5.1/test/test/unit/context/0000755000004100000410000000000013316030414021557 5ustar www-datawww-datatest-unit-context-0.5.1/test/test/unit/context/hooks_test.rb0000644000004100000410000001452613316030414024276 0ustar www-datawww-datarequire File.expand_path('../../../test_helper', File.dirname(__FILE__)) module Test::Unit::Context class TestHooks < Test::Unit::TestCase class << self; alias_method :it, :test; end setup do @inherited_before_each_var ||= 0 @inherited_before_each_var += 1 end attr_reader :inherited_before_each_var def setup @inherited_before_each_var ||= 0 @inherited_before_each_var_2 ||= 0 @inherited_before_each_var += 2 @inherited_before_each_var_2 += 1 end attr_reader :inherited_before_each_var_2 def teardown @inherited_after_each_var ||= 0 @inherited_after_each_var += 1 end attr_reader :inherited_after_each_var startup do @inherited_before_all_var ||= 0 @inherited_before_all_var += 1 end attr_reader :inherited_before_all_var shutdown do @inherited_after_all_var ||= 0 @inherited_after_all_var += 1 end attr_reader :inherited_after_all_var SAMPLE_TEST1 = context "hooks1" do setup do @inherited_before_each_var ||= 0 @inherited_before_each_var += 4 end teardown do @after_each_var ||= 0 @after_each_var += 1 end attr_reader :after_each_var teardown :a_method test "foo" do assert :foo end # @override so its not auto-run alias_method :default_run, :run def run(result); result end end setup def a_setup @superclass_before_each_var ||= 0 @superclass_before_each_var += 1 end attr_reader :superclass_before_each_var teardown def a_teardown @superclass_after_each_var ||= 0 @superclass_after_each_var += 1 end attr_reader :superclass_after_each_var context "with (inherited) setup/teadown hooks" do it "runs superclass before callbacks in order" do assert_equal 1, @test.superclass_before_each_var end it "runs inherited before callbacks in order" do assert_equal 7, @test.inherited_before_each_var end it "runs before callbacks in order" do assert_equal 1, @test.inherited_before_each_var_2 end it "runs superclass after callbacks" do assert_equal 1, @test.superclass_after_each_var end it "runs inherited after callbacks" do assert_equal 1, @test.inherited_after_each_var end it "runs after callbacks" do assert_equal 1, @test.after_each_var end it "runs after callbacks specified with method names, instead of blocks" do assert_equal "a method ran", @test.ivar end setup do result = Test::Unit::TestResult.new @test = SAMPLE_TEST1.new("test: foo") @test.default_run(result) { |inherited_after_each_var, v| } verify_result_passed! result end end SAMPLE_TEST2 = context "hooks2" do setup do @inherited_before_each_var ||= 0 @inherited_before_each_var += 4 end teardown do @after_each_var ||= 0 @after_each_var += 1 end def setup @superclass_before_each_var ||= 0 @inherited_before_each_var_2 ||= 9 end def teardown @superclass_after_each_var ||= 0 end attr_reader :after_each_var test "foo" do assert :foo end # @override so its not auto-run alias_method :default_run, :run def run(result); result end end context "with redefined setup/teadown methods" do setup do @result = Test::Unit::TestResult.new @test = SAMPLE_TEST2.new("test: foo") @test.default_run(@result) { |inherited_after_each_var, v| } end it "runs superclass before callbacks" do assert_equal 1, @test.superclass_before_each_var end it "runs superclass after callbacks" do assert_equal 1, @test.superclass_after_each_var end it "does not run inherited (re-defined) setup method" do assert_equal 9, @test.inherited_before_each_var_2 end it "runs inherited before callbacks (except previous setup method)" do assert_equal 5, @test.inherited_before_each_var end end SAMPLE_TEST3 = context "hooks3" do setup do #puts "hooks3 setup \n #{caller.join("\n ")}" @inherited_before_each_var ||= 0 @inherited_before_each_var += 4 end teardown do @after_each_var ||= 0 @after_each_var += 1 end attr_reader :after_each_var test "foo" do assert :foo end # @override so its not auto-run alias_method :default_run, :run def run(result); result end end # test that we aren't stomping on defined setup method context "with setup/teardown methods" do SAMPLE_TEST3.class_eval { attr_reader :one, :two } setup def custom_setup #SAMPLE_TEST3.setup { @one = 1 } #SAMPLE_TEST3.teardown { @two = 10 } @test = SAMPLE_TEST3.new("test: foo") @test.class.setup do @one = 1 end @test.class.teardown do @two = 10 end result = Test::Unit::TestResult.new @test.default_run(result) { |inherited_after_each_var, v| } verify_result_passed! result end it "runs setup method block a la Shoulda" do assert_equal 1, @test.one end it "runs teardown method block a la Shoulda" do assert_equal 10, @test.two end it "runs teardown method block and regular callbacks" do assert_equal 7, @test.inherited_before_each_var assert_equal 1, @test.after_each_var end end def self.startup @superclass_before_all_var ||= 0 @superclass_before_all_var += 1 end def self.shutdown @superclass_after_all_var ||= 0 @superclass_after_all_var += 1 end protected attr_reader :ivar def a_method @ivar = "a method ran" end private def verify_result_passed!(test_result) unless test_result.passed? #raise test_result.faults[0] if test_result.faults.size == 1 #raise "test run failed: #{result.summary}\n#{faults.inspect}" warn "test run failed: #{test_result.summary}\n#{test_result.inspect}" raise test_result.faults.first unless test_result.faults.empty? end end end endtest-unit-context-0.5.1/test/test/unit/context/spec_spec.rb0000644000004100000410000000114113316030414024045 0ustar www-datawww-data# #see spec_test.rb class User42; end describe User42 do it 'can create a new instance' do assert_nothing_raised do User42.new end end describe 'nested' do it 'sets SPEC_SAMPLE constant' do User42.const_set(:SPEC_SAMPLE, true) end end end describe User42, '#new' do setup do @user = User42.new end test 'setup a new instance' do assert_not_nil @user assert_instance_of User42, @user end end class Foo def bar; :baz; end end describe Foo, 'bar', :baz do it 'works' do assert_equal :'baz', Foo.new.bar end end test-unit-context-0.5.1/test/test/unit/context/spec_test.rb0000644000004100000410000000301713316030414024076 0ustar www-datawww-datarequire File.expand_path('../../../test_helper', File.dirname(__FILE__)) module Test::Unit::Context class SpecTest < Test::Unit::TestCase require 'test/unit/context/spec' require 'test/unit/context/spec_spec' def test_sets_up_describe assert self.class.respond_to?(:describe) assert ::Object.respond_to?(:describe) end #def test_sets_up_it_alias #assert self.class.respond_to? :it #end test "set-up spec_spec TestCase constants" do # describe User42 assert Object.const_defined?(:User42Test) user_42_test = Object.const_get(:User42Test) assert_equal Test::Unit::TestCase, user_42_test.superclass #assert_equal 'User42', user_42_test.name # describe 'nested' assert user_42_test.const_defined?(:NestedTest) user_42_nested_test = user_42_test.const_get(:NestedTest) #assert_equal user_42_test, user_42_nested_test.superclass assert_equal Test::Unit::TestCase, user_42_nested_test.superclass #assert_equal 'nested', user_42_nested_test.name # describe User42, '#new' assert Object.const_defined?(:User42NewTest) user_42_new_test = Object.const_get(:User42NewTest) assert_equal Test::Unit::TestCase, user_42_new_test.superclass #assert_equal 'User42#new', user_42_new_test.name # describe Foo, 'bar', :baz assert Object.const_defined?(:FoobarbazTest) end test "run spec_spec 'it' tests" do at_exit { assert ::User42::SPEC_SAMPLE } end end end test-unit-context-0.5.1/test/test/unit/context/shared_test.rb0000644000004100000410000000776613316030414024431 0ustar www-datawww-datarequire File.expand_path('../../../test_helper', File.dirname(__FILE__)) module Test::Unit::Context class SharedTest < Test::Unit::TestCase def test_shared_aliases #%w(shared_behavior share_as share_behavior_as shared_examples_for).each do |method_alias| #assert self.class.respond_to?(method_alias.to_sym) #end assert self.class.respond_to?(:shared) assert self.class.respond_to?(:share_as) end def test_like_aliases #%w(uses it_should_behave_like behaves_like uses_examples_from).each do |method_alias| #assert self.class.respond_to?(method_alias.to_sym) #end assert self.class.respond_to? :like assert self.class.respond_to? :use assert self.class.respond_to? :uses end class << self; alias_method :it, :test; end context "A shared group" do context "creates a module" do test "based on a string name" do self.class.shared "things and fun" do end assert Shared::Behavior.const_defined?(:ThingsAndFun) assert_instance_of Shared::Behavior, Shared::Behavior.const_get(:ThingsAndFun) end test "based on a symbol name" do self.class.shared :fun_and_games do end assert Shared::Behavior.const_defined?(:FunAndGames) assert_instance_of Shared::Behavior, Shared::Behavior.const_get(:FunAndGames) end test "unless the name is not a String or Symbol" do assert_raise ArgumentError do self.class.shared 42 do end end end end context "should be locatable" do shared "hello sir" do def amazing! puts "back off!" end end it "by a symbol" do assert_nothing_raised do self.class.use :hello_sir end end shared "hello madam" do def fantastic! puts "you know me!" end end it "by a string" do assert_nothing_raised do self.class.use "hello madam" end end shared "hi dog" do def stupendous! puts "hoo hah!" end end it "by direct reference" do assert_nothing_raised do self.class.use HiDog end end it "by behavior reference" do assert_nothing_raised do self.class.use Shared::Behavior::HiDog end end end context "should include its shared behavior" do shared "Athos" do test "en_garde" do true end end test "no en_garde" do assert_raise NoMethodError do send("test: en_garde") end end context 'use by a symbol' do like :athos test "athos" do assert_nothing_raised do send("test: en_garde") end end end shared "Porthos" do def parry! true end end test "by a string" do self.class.use "Porthos" assert parry! end shared "Aramis" do def lunge! true end end test "by direct reference" do self.class.uses Aramis assert lunge! end end test "locates all shared behaviors with their names" do assert_not_nil shareds = self.class.shared_definitions assert shareds.size >= 4, shareds.inspect assert_include shareds, Test::Unit::Context::Shared::Behavior::HiDog assert_equal 'hi dog', Test::Unit::Context::Shared::Behavior::HiDog.shared_name [ :Athos, :Porthos, :Aramis ].each do |name| assert_include shareds, behavior = self.class.const_get(name) assert_equal name.to_s, behavior.shared_name end end end end endtest-unit-context-0.5.1/test/test_helper.rb0000644000004100000410000000051113316030414020775 0ustar www-datawww-databegin require 'test/unit/version' puts "using Test::Unit::VERSION = #{Test::Unit::VERSION}" if $VERBOSE rescue LoadError => e require('rubygems') && retry fail "`bundle install` to install Test::Unit 2.x (#{e.inspect})" end $LOAD_PATH.unshift File.expand_path('../lib', File.dirname(__FILE__)) require 'test/unit/context'test-unit-context-0.5.1/README.md0000644000004100000410000000452213316030414016440 0ustar www-datawww-data# Test::Unit::Context [![Build Status][0]](http://travis-ci.org/kares/test-unit-context) Makes `Test::Unit::TestCase` 'context-able' and thus (subjectively - hopefully) much easier to read and write. If you have ever seen RSpec than it's the very same *context do ... end* re-invented for **Test::Unit**. Inspired by [gem 'context'](https://github.com/jm/context) that does the same for the good 'old' test-unit 1.2.3 bundled with Ruby 1.8.x standard libraries. ## Installation Add it to your application's *Gemfile* (along with **test-unit**) e.g. : group :test do gem 'test-unit' gem 'test-unit-context' end Or install it yourself, if you're not using Bundler : $ gem install test-unit-context ## Usage ```ruby class ChuckNorrisTest < Test::Unit::TestCase setup do @subject = ChuckNorris.new end test "can be divided by zero" assert_equal @subject * 2, @subject / 0 end context 'frozen' do setup { @subject.freeze } test "won't answer" do assert_raise NoMemoryError do @subject.frozen? end end test "sqrt works" assert_nothing_raised do Math.sqrt -2 end end end shared 'elementary math facts' do test "square root is rational" assert_kind_of Rational, Math.sqrt(@subject) end test "greater than infinity" assert @infinity < @subject end private setup def create_infinity @infinity = 1 / 0.0 end end uses 'elementary math facts' context 'cloned' do setup do @subject = @subject.clone end test 'is Arnold Schwarzenegger' do assert_instance_of Terminator, @subject assert_nil @subject.is_a?(ChuckNorris) end like 'elementary math facts' end end ``` ### Spec Mode ```ruby require 'test/unit/context/spec' describe ChuckNorris, '#fart' do setup do @subject = ChuckNorris.new @subject.fart end it "creates a parallel universe" do assert Object.const_defined?(:Universe) assert_equal @subject, Universe.instance assert_empty ObjectSpace.each_object(Universe).to_a end end # NOTE: do not try running this at home! ``` ## Copyright Copyright (c) 2016 [Karol Bucek](https://github.com/kares). See LICENSE (http://www.apache.org/licenses/LICENSE-2.0) for details. [0]: https://secure.travis-ci.org/kares/test-unit-context.png test-unit-context-0.5.1/.gitignore0000644000004100000410000000014613316030414017147 0ustar www-datawww-data*.rbc .bundle .config .yardoc Gemfile.lock _yardoc coverage doc/ lib/bundler/man pkg rdoc test/tmp tmptest-unit-context-0.5.1/test-unit-context.gemspec0000644000004100000410000000212713316030414022143 0ustar www-datawww-data# -*- encoding: utf-8 -*- Gem::Specification.new do |gem| gem.name = 'test-unit-context' gem.authors = ['Karol Bucek'] gem.email = ['self@kares.org'] gem.licenses = ['Apache-2.0'] path = File.expand_path("lib/test/unit/context/version.rb", File.dirname(__FILE__)) gem.version = File.read(path).match( /.*VERSION\s*=\s*['"](.*)['"]/m )[1] gem.summary = %q{Context for Test::Unit (2.x)} gem.description = %q{Makes Test::Unit::TestCases 'contextable' and thus much easier to read and write. If you've seen RSpec than it's the very same 'context do ... end' re-invendet for Test::Unit. Inspired by gem 'context' that does a similar job for the 'old' Test::Unit bundled with Ruby 1.8.x standard libraries.} gem.homepage = "https://github.com/kares/test-unit-context" gem.require_paths = ["lib"] gem.files = `git ls-files`.split("\n") gem.test_files = `git ls-files -- {test}/*`.split("\n") gem.extra_rdoc_files = %w[ README.md LICENSE ] gem.add_dependency 'test-unit', '>= 2.4.0' gem.add_development_dependency 'rake' end test-unit-context-0.5.1/LICENSE0000644000004100000410000002615213316030414016171 0ustar www-datawww-data Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright (c) 2012-2016 [Karol Bucek](http://kares.org) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. test-unit-context-0.5.1/Rakefile0000644000004100000410000000032213316030414016620 0ustar www-datawww-data#!/usr/bin/env rake require "bundler/gem_tasks" require 'rake/testtask' Rake::TestTask.new do |t| t.libs << "test" t.test_files = FileList['test/**/*test.rb'] t.verbose = true end task :default => :testtest-unit-context-0.5.1/lib/0000755000004100000410000000000013316030414015724 5ustar www-datawww-datatest-unit-context-0.5.1/lib/test/0000755000004100000410000000000013316030414016703 5ustar www-datawww-datatest-unit-context-0.5.1/lib/test/unit/0000755000004100000410000000000013316030414017662 5ustar www-datawww-datatest-unit-context-0.5.1/lib/test/unit/patches.rb0000644000004100000410000000303413316030414021636 0ustar www-datawww-datarequire 'test/unit' module Test::Unit unless const_defined? :TestSuiteCreator begin require 'test/unit/test-suite-creator' # TU 3.x rescue LoadError require 'test/unit/testsuitecreator' # <= 2.5.5 end end TestSuiteCreator.class_eval do unless respond_to?(:test_method?) require 'test/unit/attribute' unless Test::Unit.const_defined? :Attribute if Test::Unit::Attribute::ClassMethods.method_defined?(:find_attribute) def self.test_method?(test_case, method_name) method_name = method_name.to_s ( method_name.start_with?('test') && method_name.length > 4 ) || test_case.find_attribute(method_name, :test) end else def self.test_method?(test_case, method_name) method_name = method_name.to_s ( method_name.start_with?('test') && method_name.length > 4 ) || test_case.attributes(method_name)[:test] end end end private def collect_test_names methods = @test_case.public_instance_methods(true) super_test_case = @test_case.superclass while super_test_case && super_test_case != TestCase methods -= super_test_case.public_instance_methods(true) super_test_case = super_test_case.superclass end method_names = methods.map!(&:to_s) test_names = method_names.find_all do |method_name| self.class.test_method?(@test_case, method_name) end __send__("sort_test_names_in_#{@test_case.test_order}_order", test_names) end end end test-unit-context-0.5.1/lib/test/unit/context.rb0000644000004100000410000000132313316030414021672 0ustar www-datawww-datarequire 'test/unit' require 'test/unit/patches' require 'test/unit/context/helpers' require 'test/unit/context/version' module Test module Unit module Context def context_name if superclass.respond_to?(:context_name) "#{superclass.context_name} #{@context_name}".gsub(/^\s+/, "") else @context_name end end def context_name=(name); @context_name=name; end end end end require 'test/unit/context/context' Test::Unit::TestCase.extend Test::Unit::Context::Context require 'test/unit/context/shared' Test::Unit::TestCase.extend Test::Unit::Context::Shared # NOTE: this pollutes it's left to the user to load it : # require 'test/unit/context/spec'test-unit-context-0.5.1/lib/test/unit/context/0000755000004100000410000000000013316030414021346 5ustar www-datawww-datatest-unit-context-0.5.1/lib/test/unit/context/version.rb0000644000004100000410000000012713316030414023360 0ustar www-datawww-datamodule Test module Unit module Context VERSION = '0.5.1' end end end test-unit-context-0.5.1/lib/test/unit/context/spec.rb0000644000004100000410000000410213316030414022622 0ustar www-datawww-datamodule Test::Unit::Context module Spec PREFIX = nil # :nodoc: SUFFIX = 'Test'.freeze # :nodoc: # Spec style Test::Unit::TestCase (sub-classes) : # # describe User do # it "creates a new instance" do # assert_nothing_raised { User.new } # end # end # # You need to `require 'test/unit/context/spec'` ( e.g. in test_helper.rb). # # The generated Test::Unit::TestCase sub-class follows the "Test" suffix # naming convention e.g. `describe User` ends up as `UserTest < TestCase`. # def describe(*args, &block) name = args.map { |arg| arg.is_a?(Class) ? arg.name : arg }.join class_name = Helpers.to_const_name(name.freeze, PREFIX, SUFFIX) self_klass = self.is_a?(Class) ? self : self.class # nested describes if self_klass.const_defined?(class_name) klass = self_klass.const_get(class_name) if klass <= Test::Unit::TestCase warn "duplicate test-case describe with args #{args.inspect} " << "found at #{caller.first} it is going to be merged with " << "the previous TestCase definition" else raise "could not create a test-case with args #{args.inspect} " << "as a constant #{class_name} is already defined and is not " << "another TestCase definition" end else # NOTE: context inherits from nesting case but describe should not : #is_test_case = ( self_klass <= Test::Unit::TestCase ) #klass = Class.new is_test_case ? self_klass : Test::Unit::TestCase klass = Class.new(Test::Unit::TestCase) klass.send(:define_method, :name) { name } klass.extend Methods self_klass.const_set(class_name, klass) end klass.class_eval(&block) klass end module Methods # It is an alias for Test::Unit's test method. # @see Test::Unit::TestCase#test def it(*args, &block); test(*args, &block); end end end end Object.send :include, Test::Unit::Context::Spec test-unit-context-0.5.1/lib/test/unit/context/helpers.rb0000644000004100000410000000114713316030414023340 0ustar www-datawww-datarequire 'time' module Test::Unit::Context module Helpers CONST_NAME_SUB_ = /[\s:\-'",\.~;!?#=\(\)&]+/ # :nodoc: module_function def to_const_name(str, prefix = nil, suffix = nil) name = str.dup name.lstrip! if prefix name.rstrip! if suffix name.gsub!(CONST_NAME_SUB_, '_') name.gsub!(/\/(.?)/) { $1.upcase } name.gsub!(/(?:^|_)(.)/) { $1.upcase } "#{prefix}#{name}#{suffix}" end def generate_uuid uuid = [ (Time.now.to_f * 1000).to_i % 10 ] 15.times { uuid << rand(16).to_s(16) } uuid.join end end endtest-unit-context-0.5.1/lib/test/unit/context/context.rb0000644000004100000410000000556513316030414023372 0ustar www-datawww-datamodule Test::Unit::Context module Context PREFIX = 'Context'.freeze # :nodoc: SUFFIX = nil # :nodoc: # Add a context to a set of tests. # # context "A new account" do # test "does not have users" do # assert Account.new.users.empty? # end # end # # The context name is prepended to the test name, so failures look like this: # # 1) Failure: # test_a_new_account_does_not_have_users() [./test/test_accounts.rb:4]: # is not true. # # Contexts can also be nested like so: # # context "A new account" do # context "created from the web application" do # test "has web as its vendor" do # assert_equal "web", users(:web_user).vendor # end # end # end # # Context should have unique names within a given scope, otherwise they # end-up being merged as if it where one single context declaration. # Anonymous (un-named) contexts are supported as well - contrary they # never get merged (a unique name is generated for each such context). # def context(name = nil, &block) name ||= Helpers.generate_uuid # context "created with defaults" ... 'ContextCreatedWithDefaults' class_name = Helpers.to_const_name(name.to_s, PREFIX, SUFFIX) if const_defined?(class_name) klass = const_get(class_name) if ( klass.superclass == self rescue nil ) warn "duplicate context definition with the name #{name.inspect} " + "found at #{caller.first} it is going to be merged with " + "the previous context definition" else raise "could not create a context with the name #{name.inspect} " + "as a constant #{class_name} is already defined and is not " + "another context definition" end else klass = Class.new(self) klass.extend Test::Unit::Context klass.context_name = name # NOTE: make sure by default we run "inherited" setup/teardown hooks # unless context code does re-define the hook method e.g. `def setup` # instead of using the `setup do` or the setup method marker syntax : klass.class_eval do def setup; super; end def cleanup; super; end def teardown; super; end end const_set(class_name, klass) end context_definitions << klass klass.class_eval(&block) klass end %w( contexts group ).each { |m| alias_method m, :context } def context_definitions(nested = false) @_context_definitions ||= [] if nested contexts = @_context_definitions.dup @_context_definitions.each do |context| contexts.concat context.context_definitions(nested) end contexts else @_context_definitions end end end endtest-unit-context-0.5.1/lib/test/unit/context/shared.rb0000644000004100000410000000742313316030414023147 0ustar www-datawww-datamodule Test::Unit::Context module Shared # Share behavior among different contexts. # This creates a module (actually, a Module subclass) that is included # using the +like+ method (or one of its aliases) provided by context (or # +include+ if you know the module's constant name). # # ==== Examples # # shared "aasome-things" do # test "does some thing" do # # some-thing is awesome # end # end # # like "aasome-things" # # or # use "aasome-things" # # share_as :client do # test "is a client to our server" do # # ... # end # end # # like_a :client # # or # uses "client" # def shared(name, &block) if ! name.is_a?(String) && ! name.is_a?(Symbol) raise ArgumentError, "use a String or Symbol as the name e.g. " + "`shared #{name.to_s.inspect} do ...`" end const_name = Helpers.to_const_name(name.to_s) if Behavior.const_defined?(const_name) const = Behavior.const_get(const_name) if Behavior === const raise "duplicate shared definition with the name #{name.inspect} " << "found at #{caller.first} please provide an unique name" else raise "could not create a shared definition with the name " << "#{name.inspect} as a constant #{Behavior.name}::#{const_name} " << "already exists" end else behavior = Behavior.new(name, block) Behavior.const_set(const_name, behavior) # expose at current top-level test-case as a constant as well : test_case = self while test_case.is_a?(Test::Unit::Context) test_case = test_case.superclass end unless test_case.const_defined?(const_name) test_case.const_set(const_name, behavior) end behavior end end %w( share_as ).each { |m| alias_method m, :shared } # Pull in behavior shared by +shared+ or a module. # # ==== Examples # # shared "awesome things" do # test "does some thing" do # # some-thing is awesome # end # end # # like "awesome things" # # module AwesomeThings # # ... # end # # uses AwesomeThings # def like(shared_name) case shared_name when String, Symbol const_name = Helpers.to_const_name(shared_name.to_s) if Behavior.const_defined?(const_name) const = Behavior.const_get(const_name) if Behavior === const include const else raise "#{shared_name.inspect} does not resolve into a shared " << "behavior instance but to a #{const.inspect}" end else raise "shared behavior with name #{shared_name.inspect} not defined" end when Behavior, Module include shared_name else raise ArgumentError, "pass a String or Symbol as the name e.g. " + "`like #{shared_name.to_s.inspect} do ...`" end end %w( like_a use uses ).each { |m| alias_method m, :like } # Returns all available shared definitions. def shared_definitions shareds = [] constants.each do |name| const = const_get(name) if const.is_a?(Behavior) shareds << const end end shareds end class Behavior < Module attr_reader :shared_name def initialize(name, block) super() @shared_name = name @_block = block end def included(klass) # :nodoc: klass.class_eval(&@_block) # @_block.call end end end endtest-unit-context-0.5.1/Gemfile0000644000004100000410000000024413316030414016451 0ustar www-datawww-datasource 'https://rubygems.org' gemspec if path = ENV['test-unit'] gem 'test-unit', :path => path elsif version = ENV['TEST_UNIT'] gem 'test-unit', version end