[macruby-changes] [793] MacRuby/trunk/test-macruby
source_changes at macosforge.org
source_changes at macosforge.org
Thu Jan 15 08:33:17 PST 2009
Revision: 793
http://trac.macosforge.org/projects/ruby/changeset/793
Author: eloy.de.enige at gmail.com
Date: 2009-01-15 08:33:16 -0800 (Thu, 15 Jan 2009)
Log Message:
-----------
Moved test/spec extensions into mini-test-spec.rb and added Kernel::describe which allows test cases to be created with a human readable description.
Modified Paths:
--------------
MacRuby/trunk/test-macruby/cases/objc_test.rb
MacRuby/trunk/test-macruby/test_helper/temp_dir_helper.rb
MacRuby/trunk/test-macruby/test_helper/test_unit_helper.rb
Added Paths:
-----------
MacRuby/trunk/test-macruby/test_helper/mini-test-spec.rb
Modified: MacRuby/trunk/test-macruby/cases/objc_test.rb
===================================================================
--- MacRuby/trunk/test-macruby/cases/objc_test.rb 2009-01-15 15:28:56 UTC (rev 792)
+++ MacRuby/trunk/test-macruby/cases/objc_test.rb 2009-01-15 16:33:16 UTC (rev 793)
@@ -155,6 +155,8 @@
@pure_objc_instance = PureObjCSubclass.alloc.init
end
+ include TempDirHelper
+
it "should be possible to use a Ruby String as dictionary key and pass the dictionary of into Objective-C land" do
key = String.new("foo")
value = Object.new
Added: MacRuby/trunk/test-macruby/test_helper/mini-test-spec.rb
===================================================================
--- MacRuby/trunk/test-macruby/test_helper/mini-test-spec.rb (rev 0)
+++ MacRuby/trunk/test-macruby/test_helper/mini-test-spec.rb 2009-01-15 16:33:16 UTC (rev 793)
@@ -0,0 +1,52 @@
+require "test/unit"
+
+# The following are just some simple hacks to be able to write tests with a
+# spec like description. This should ease the process of moving tests to run
+# with mspec for instance.
+
+module Test::Unit
+ class TestCase
+ class << self
+ # Runs before each test case.
+ def before(&block)
+ define_method("setup", &block)
+ end
+
+ # Runs after each test case.
+ def after(&block)
+ define_method("teardown", &block)
+ end
+
+ # Defines a test case.
+ def it(name, &block)
+ define_method("test_#{name}", &block)
+ end
+ end
+ end
+
+ class Failure
+ # Return the failure message in a more spec like way.
+ def long_display
+ file_location, method_name = @location.first.split(':in `')
+ "#{@test_name} `#{method_name.sub(/^test_/, '')} [#{file_location}]\n#{@message}"
+ end
+ end
+end
+
+module Kernel
+ private
+
+ # Defines a new test case with the given +description+ and optionally a test
+ # case superclass.
+ #
+ # describe "Foo in general" do
+ # it "should instantiate" do
+ # assert Foo.new.nil?
+ # end
+ # end
+ def describe(description, superclass = Test::Unit::TestCase, &definition)
+ klass = Class.new(superclass, &definition)
+ klass.class_eval "def name; '#{description}' end"
+ klass
+ end
+end
\ No newline at end of file
Modified: MacRuby/trunk/test-macruby/test_helper/temp_dir_helper.rb
===================================================================
--- MacRuby/trunk/test-macruby/test_helper/temp_dir_helper.rb 2009-01-15 15:28:56 UTC (rev 792)
+++ MacRuby/trunk/test-macruby/test_helper/temp_dir_helper.rb 2009-01-15 16:33:16 UTC (rev 793)
@@ -1,6 +1,13 @@
require "fileutils"
module TempDirHelper
+ def self.included(klass)
+ klass.class_eval do
+ alias_method :setup, :setup_temp_dir! unless instance_methods(false).include?(:setup)
+ alias_method :teardown, :teardown_temp_dir! unless instance_methods(false).include?(:teardown)
+ end
+ end
+
def ensure_dir!(path)
FileUtils.mkdir_p(path) unless File.exist?(path)
end
Modified: MacRuby/trunk/test-macruby/test_helper/test_unit_helper.rb
===================================================================
--- MacRuby/trunk/test-macruby/test_helper/test_unit_helper.rb 2009-01-15 15:28:56 UTC (rev 792)
+++ MacRuby/trunk/test-macruby/test_helper/test_unit_helper.rb 2009-01-15 16:33:16 UTC (rev 793)
@@ -1,25 +1,6 @@
-# The following is just a simple hack to be able to write tests with a spec description.
-# This should ease the process of moving tests to run with mspec for instance.
+require File.expand_path('../mini-test-spec', __FILE__)
+
class Test::Unit::TestCase
- class << self
- # Runs before each test case.
- def before(&block)
- define_method("setup", &block)
- end
-
- # Runs after each test case.
- def after(&block)
- define_method("teardown", &block)
- end
-
- # Defines a test case.
- def it(name, &block)
- define_method("test_#{name}", &block)
- end
- end
-
- private
-
# Returns the path to a file in +FIXTURE_PATH+.
def fixture(name)
File.join(FIXTURE_PATH, name)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090115/cefb7061/attachment.html>
More information about the macruby-changes
mailing list