djsun-context 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,39 @@
1
+ module Test
2
+ module Unit
3
+ class TestCase
4
+ class << self
5
+ # Tweaks to standard method so we don't get superclass methods and we don't
6
+ # get weird default tests
7
+ def suite # :nodoc:
8
+ method_names = public_instance_methods - superclass.public_instance_methods
9
+
10
+ tests = method_names.delete_if {|method_name| method_name !~ /^test./}
11
+ suite = Test::Unit::TestSuite.new(name)
12
+
13
+ tests.sort.each do |test|
14
+ catch(:invalid_test) do
15
+ suite << new(test)
16
+ end
17
+ end
18
+
19
+ suite
20
+ end
21
+ end
22
+ end
23
+
24
+ class TestSuite
25
+ # Runs the tests and/or suites contained in this
26
+ # TestSuite.
27
+ def run(result, &progress_block) # :nodoc:
28
+ yield(STARTED, name)
29
+ ivars_from_callback = @tests.first.run_all_callbacks(:before) if @tests.first.is_a?(Test::Unit::TestCase)
30
+ @tests.each do |test|
31
+ test.set_values_from_callbacks(ivars_from_callback) if ivars_from_callback
32
+ test.run(result, &progress_block)
33
+ end
34
+ ivars_from_callback = @tests.first.run_all_callbacks(:after) if ivars_from_callback
35
+ yield(FINISHED, name)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,37 @@
1
+ class Test::Unit::TestCase
2
+ class << self
3
+ # Create a test method. +name+ is a native-language string to describe the test
4
+ # (e.g., no more +test_this_crazy_thing_with_underscores+).
5
+ #
6
+ # test "A user should not be able to delete another user" do
7
+ # assert_false @user.can?(:delete, @other_user)
8
+ # end
9
+ #
10
+ def test(name, opts={}, &block)
11
+ test_name = ["test:", context_name, name].reject { |n| n == "" }.join(' ')
12
+ # puts "running test #{test_name}"
13
+ defined = instance_method(test_name) rescue false
14
+ raise "#{test_name} is already defined in #{self}" if defined
15
+
16
+ unless opts[:before].nil?
17
+ before_should_callbacks[test_name] = opts[:before]
18
+ end
19
+
20
+ if block_given?
21
+ define_method(test_name, &block)
22
+ else
23
+ define_method(test_name) do
24
+ flunk "No implementation provided for #{name}"
25
+ end
26
+ end
27
+ end
28
+
29
+ %w(it should tests).each {|m| alias_method m, :test}
30
+
31
+ def before_test(name, &block)
32
+ test(name, :before => block) {}
33
+ end
34
+
35
+ %w(before_it before_should before_tests).each {|m| alias_method m, :before_test}
36
+ end
37
+ end
@@ -0,0 +1,9 @@
1
+ module Context
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 5
5
+ TINY = 5
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
data/lib/context.rb ADDED
@@ -0,0 +1,19 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'rubygems'
5
+ require 'test/unit'
6
+
7
+ require 'context/core_ext/string'
8
+ require 'context/core_ext/rails_hacks'
9
+
10
+ require 'context/version'
11
+ require 'context/suite'
12
+ require 'context/test'
13
+ require 'context/lifecycle'
14
+ require 'context/context'
15
+ require 'context/shared_behavior'
16
+
17
+ class Test::Unit::TestCase
18
+ extend Context::Context
19
+ end