homeschool 0.0.1.34 → 0.0.1.38
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/form_buildr.rb +0 -1
- data/lib/homeschool.rb +3 -3
- data/lib/standardized_test.rb +35 -26
- data/test/homeschool_test.rb +107 -0
- data/test/module_tests.rb +23 -18
- metadata +3 -2
data/lib/form_buildr.rb
CHANGED
data/lib/homeschool.rb
CHANGED
@@ -86,8 +86,8 @@ class Module
|
|
86
86
|
alias_method :append_features, :append_features_with_pattern_methods
|
87
87
|
|
88
88
|
def add_extension(extension)
|
89
|
-
self.extend extension::ClassMethods
|
90
|
-
self.send(:include, extension::InstanceMethods)
|
89
|
+
self.extend extension::ClassMethods unless !defined?(extension::ClassMethods)
|
90
|
+
self.send(:include, extension::InstanceMethods) unless !defined?(extension::InstanceMethods)
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -153,5 +153,5 @@ class Hash
|
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
156
|
-
require 'standardized_test' if defined?(RAILS_ENV) && RAILS_ENV == 'test'
|
156
|
+
require 'standardized_test' if defined?(RAILS_ENV) && RAILS_ENV == 'test' || defined?(TEST_ENV)
|
157
157
|
require 'tame_rails' if defined?(RAILS_ENV)
|
data/lib/standardized_test.rb
CHANGED
@@ -1,41 +1,50 @@
|
|
1
1
|
require 'test/unit'
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
module Homeschool::StandardizedTest; end
|
3
|
+
module Homeschool::StandardizedTest::Assertions
|
4
|
+
module InstanceMethods
|
5
|
+
def assert_fails
|
6
|
+
yield
|
7
|
+
passed = true
|
8
|
+
rescue
|
9
|
+
ensure
|
10
|
+
assert !passed
|
11
|
+
end
|
12
|
+
|
13
|
+
def diff(one, two)
|
14
|
+
prefix = 0
|
15
|
+
(0...[one, two].min_by(&:length).length).each do |i|
|
16
|
+
if one[i] == two[i]
|
17
|
+
prefix = i + 1
|
18
|
+
else
|
19
|
+
break
|
20
|
+
end
|
21
|
+
end
|
22
|
+
"Expected <#{diff_format(one, prefix)}> but was <#{diff_format(two, prefix)}>"
|
23
|
+
end
|
24
|
+
|
25
|
+
def diff_format(string, prefix)
|
26
|
+
prefix > 0 ? "...#{string[prefix..-1]}" : string
|
27
|
+
end
|
28
|
+
|
29
|
+
def assert_equal_with_diffing(expected, actual, message=nil)
|
30
|
+
if message == :diff
|
31
|
+
assert_block(diff(expected, actual)) {expected == actual}
|
8
32
|
else
|
9
|
-
|
33
|
+
assert_equal_without_diffing(expected, actual, message)
|
10
34
|
end
|
11
35
|
end
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
prefix > 0 ? "...#{string[prefix..-1]}" : string
|
16
|
-
end
|
17
|
-
def assert_equal_with_diffing(expected, actual, message=nil)
|
18
|
-
if message == :diff
|
19
|
-
assert_block(diff(expected, actual)) {expected == actual}
|
20
|
-
else
|
21
|
-
assert_equal_without_diffing(expected, actual, message)
|
36
|
+
def self.included(klass)
|
37
|
+
klass.send :alias_method, :assert_equal_without_diffing, :assert_equal
|
38
|
+
klass.send :alias_method, :assert_equal, :assert_equal_with_diffing
|
22
39
|
end
|
23
40
|
end
|
24
|
-
alias_method :assert_equal_without_diffing, :assert_equal
|
25
|
-
alias_method :assert_equal, :assert_equal_with_diffing
|
26
41
|
end
|
42
|
+
Test::Unit::TestCase.add_extension(Homeschool::StandardizedTest::Assertions)
|
27
43
|
|
28
44
|
module HomeschoolTestHelper
|
29
45
|
def assert_json(expected, actual)
|
30
46
|
assert_equal JSON.parse(expected), JSON.parse(actual)
|
31
47
|
end
|
32
|
-
def assert_fails
|
33
|
-
yield
|
34
|
-
passed = true
|
35
|
-
rescue
|
36
|
-
ensure
|
37
|
-
assert !passed
|
38
|
-
end
|
39
48
|
|
40
49
|
def HomeschoolTestHelper.included(klass)
|
41
50
|
klass.rdef(/last_(.*)/) do |match|
|
@@ -0,0 +1,107 @@
|
|
1
|
+
TEST_ENV = true
|
2
|
+
#RAILS_ENV = ENV["RAILS_ENV"] = "test"
|
3
|
+
require 'test/unit'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'active_support'
|
6
|
+
require 'json'
|
7
|
+
require File.dirname(__FILE__) + "/../lib/homeschool"
|
8
|
+
|
9
|
+
class Chicken
|
10
|
+
attr_accessor :feet
|
11
|
+
def initialize(properties)
|
12
|
+
@feet = properties[:feet]
|
13
|
+
end
|
14
|
+
def self.find(*args)
|
15
|
+
[2]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module RdefHelper
|
20
|
+
rdef /mod_(.*)/ do |match|
|
21
|
+
match[1]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
class HomeschoolTest < Test::Unit::TestCase
|
25
|
+
include HomeschoolTestHelper
|
26
|
+
include RdefHelper
|
27
|
+
homeschool_fixtures :chickens
|
28
|
+
|
29
|
+
def test_fixtures
|
30
|
+
assert_equal red_chicken, red_chicken
|
31
|
+
assert_not_equal red_chicken, blue_chicken
|
32
|
+
assert_equal 3, chicken_experiment(:feet => 3).feet
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_last
|
36
|
+
assert_equal 2, last_chicken
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_dom_id
|
40
|
+
object = {:id => 3}.to_obj
|
41
|
+
assert_equal 'object_3', object.dom_id
|
42
|
+
assert_equal 'object_3_tr', object.dom_id(:tr)
|
43
|
+
assert_equal 'object_3_one_two', object.dom_id('one', 'two')
|
44
|
+
assert_json '{"element": "object_3", "tr": "object_3_tr", "one_two": "object_3_one_two"}', object.dom_ids.to_json
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_assert_json
|
48
|
+
assert_json '{"one": 1, "two": 2}', '{"two": 2, "one": 1}'
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_symbol_patterns
|
52
|
+
assert :lala!.bang?
|
53
|
+
assert_equal :lala!, :lala.bang
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_to_obj
|
57
|
+
obj = {:one => 1, :two => 2}.to_obj
|
58
|
+
assert_equal 1, obj.one
|
59
|
+
assert_equal 2, obj.two
|
60
|
+
assert_equal Object, obj.class
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_hash_list
|
64
|
+
obj = {:one => 1, :two => 2, :three => 3, :four => 4}
|
65
|
+
assert [4,2,3] == obj.list(:four, :two, :three)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_iv_cache
|
69
|
+
iv_cache(:one) {Object.new}
|
70
|
+
assert @one
|
71
|
+
assert_equal @one, iv_cache(:one) {Object.new}
|
72
|
+
assert_not_equal @one, iv_cache(:two) {Object.new}
|
73
|
+
end
|
74
|
+
|
75
|
+
rdef(/in_(.*)_between/) do |match|
|
76
|
+
return match[1]
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_rdef
|
80
|
+
assert_equal "expected", in_expected_between
|
81
|
+
assert_fails {in_expected_between_lala}
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_module_rdef
|
85
|
+
assert_equal 'worked', mod_worked
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_filter
|
89
|
+
assert_equal({:one => 1, :two => 2}, {:one => 1, :two => 2, :three => 3}.filter(:one, :two))
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_assert_fails
|
93
|
+
assert_fails {lala}
|
94
|
+
begin
|
95
|
+
assert_fails {one = 1}
|
96
|
+
passed = true
|
97
|
+
rescue
|
98
|
+
end
|
99
|
+
assert !passed
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_assert_equal
|
103
|
+
assert_equal 'this string is the same until you get here.', 'this string is the same until you get somewhere else.', :diff
|
104
|
+
rescue
|
105
|
+
assert_equal 'Expected <...here.> but was <...somewhere else.>', $!.message
|
106
|
+
end
|
107
|
+
end
|
data/test/module_tests.rb
CHANGED
@@ -1,26 +1,31 @@
|
|
1
|
+
TEST_ENV = true
|
1
2
|
require 'test/unit'
|
2
3
|
require File.dirname(__FILE__) + "/../lib/homeschool"
|
3
4
|
|
4
5
|
class ModuleTests < Test::Unit::TestCase
|
6
|
+
|
5
7
|
def test_add_extension
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
assert MyTestClass.methods.include?('my_class_method')
|
10
|
-
assert MyTestClass.new.respond_to?(:my_instance_method)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class MyTestClass
|
15
|
-
end
|
16
|
-
|
17
|
-
module MyTestModule
|
18
|
-
module ClassMethods
|
19
|
-
def my_class_method
|
8
|
+
new_class do |klass|
|
9
|
+
klass.add_extension(new_module(:class_methods, :instance_methods))
|
10
|
+
assert klass.methods.include?('c_method') && klass.new.respond_to?(:i_method)
|
20
11
|
end
|
21
|
-
|
22
|
-
|
23
|
-
|
12
|
+
new_class do |klass|
|
13
|
+
klass.add_extension(new_module(:class_methods))
|
14
|
+
assert klass.methods.include?('c_method') && !klass.new.respond_to?(:i_method)
|
15
|
+
klass.add_extension(new_module(:instance_methods))
|
16
|
+
assert klass.new.respond_to?(:i_method)
|
24
17
|
end
|
25
18
|
end
|
26
|
-
|
19
|
+
|
20
|
+
private
|
21
|
+
def new_class(&block)
|
22
|
+
yield Class.new
|
23
|
+
end
|
24
|
+
|
25
|
+
def new_module(*methods)
|
26
|
+
Module.new do |m|
|
27
|
+
m.module_eval("module ClassMethods; def c_method; end; end") if methods.include?(:class_methods)
|
28
|
+
m.module_eval("module InstanceMethods; def i_method; end; end") if methods.include?(:instance_methods)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: homeschool
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.1.
|
7
|
-
date: 2007-10-
|
6
|
+
version: 0.0.1.38
|
7
|
+
date: 2007-10-07 00:00:00 -04:00
|
8
8
|
summary: The homeschool gem
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- bin/gfight
|
37
37
|
- bin/homeschool
|
38
38
|
- bin/svm
|
39
|
+
- test/homeschool_test.rb
|
39
40
|
- test/module_tests.rb
|
40
41
|
- test/the_test.rb
|
41
42
|
- lib/fight.rb
|