djsun-context 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +10 -0
- data/License.txt +20 -0
- data/Manifest.txt +29 -0
- data/PostInstall.txt +0 -0
- data/README.rdoc +158 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +73 -0
- data/config/requirements.rb +15 -0
- data/context.gemspec +44 -0
- data/lib/context/context.rb +64 -0
- data/lib/context/core_ext/rails_hacks.rb +10 -0
- data/lib/context/core_ext/string.rb +17 -0
- data/lib/context/lifecycle.rb +103 -0
- data/lib/context/shared_behavior.rb +97 -0
- data/lib/context/suite.rb +39 -0
- data/lib/context/test.rb +37 -0
- data/lib/context/version.rb +9 -0
- data/lib/context.rb +19 -0
- data/setup.rb +1585 -0
- data/test/test_context.rb +57 -0
- data/test/test_core_ext.rb +21 -0
- data/test/test_helper.rb +2 -0
- data/test/test_lifecycle.rb +224 -0
- data/test/test_test.rb +23 -0
- metadata +79 -0
@@ -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
|
data/lib/context/test.rb
ADDED
@@ -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
|
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
|