motion_blender-support 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.yardopts +1 -0
- data/Gemfile +4 -0
- data/HACKS.md +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +359 -0
- data/Rakefile +14 -0
- data/app/app_delegate.rb +5 -0
- data/examples/Inflector/.gitignore +16 -0
- data/examples/Inflector/Gemfile +5 -0
- data/examples/Inflector/Rakefile +13 -0
- data/examples/Inflector/app/app_delegate.rb +8 -0
- data/examples/Inflector/app/inflections.rb +5 -0
- data/examples/Inflector/app/inflector_view_controller.rb +109 -0
- data/examples/Inflector/app/words_view_controller.rb +101 -0
- data/examples/Inflector/resources/Default-568h@2x.png +0 -0
- data/examples/Inflector/spec/main_spec.rb +9 -0
- data/lib/motion-support/callbacks.rb +8 -0
- data/lib/motion-support/concern.rb +4 -0
- data/lib/motion-support/core_ext/array.rb +10 -0
- data/lib/motion-support/core_ext/class.rb +5 -0
- data/lib/motion-support/core_ext/hash.rb +13 -0
- data/lib/motion-support/core_ext/integer.rb +6 -0
- data/lib/motion-support/core_ext/module.rb +11 -0
- data/lib/motion-support/core_ext/numeric.rb +6 -0
- data/lib/motion-support/core_ext/object.rb +12 -0
- data/lib/motion-support/core_ext/range.rb +5 -0
- data/lib/motion-support/core_ext/string.rb +13 -0
- data/lib/motion-support/core_ext/time.rb +16 -0
- data/lib/motion-support/core_ext.rb +13 -0
- data/lib/motion-support/inflector.rb +8 -0
- data/lib/motion-support.rb +81 -0
- data/motion/_stdlib/array.rb +13 -0
- data/motion/_stdlib/cgi.rb +22 -0
- data/motion/_stdlib/date.rb +81 -0
- data/motion/_stdlib/enumerable.rb +9 -0
- data/motion/_stdlib/time.rb +19 -0
- data/motion/callbacks.rb +511 -0
- data/motion/concern.rb +122 -0
- data/motion/core_ext/array/access.rb +28 -0
- data/motion/core_ext/array/conversions.rb +86 -0
- data/motion/core_ext/array/extract_options.rb +11 -0
- data/motion/core_ext/array/grouping.rb +99 -0
- data/motion/core_ext/array/prepend_and_append.rb +7 -0
- data/motion/core_ext/array/wrap.rb +45 -0
- data/motion/core_ext/array.rb +19 -0
- data/motion/core_ext/class/attribute.rb +119 -0
- data/motion/core_ext/class/attribute_accessors.rb +168 -0
- data/motion/core_ext/date/acts_like.rb +8 -0
- data/motion/core_ext/date/calculations.rb +117 -0
- data/motion/core_ext/date/conversions.rb +56 -0
- data/motion/core_ext/date_and_time/calculations.rb +232 -0
- data/motion/core_ext/enumerable.rb +90 -0
- data/motion/core_ext/hash/deep_delete_if.rb +23 -0
- data/motion/core_ext/hash/deep_merge.rb +27 -0
- data/motion/core_ext/hash/except.rb +15 -0
- data/motion/core_ext/hash/indifferent_access.rb +19 -0
- data/motion/core_ext/hash/keys.rb +150 -0
- data/motion/core_ext/hash/reverse_merge.rb +22 -0
- data/motion/core_ext/hash/slice.rb +40 -0
- data/motion/core_ext/integer/inflections.rb +27 -0
- data/motion/core_ext/integer/multiple.rb +10 -0
- data/motion/core_ext/integer/time.rb +41 -0
- data/motion/core_ext/kernel/singleton_class.rb +6 -0
- data/motion/core_ext/metaclass.rb +8 -0
- data/motion/core_ext/module/aliasing.rb +69 -0
- data/motion/core_ext/module/anonymous.rb +19 -0
- data/motion/core_ext/module/attr_internal.rb +38 -0
- data/motion/core_ext/module/attribute_accessors.rb +64 -0
- data/motion/core_ext/module/delegation.rb +175 -0
- data/motion/core_ext/module/introspection.rb +60 -0
- data/motion/core_ext/module/reachable.rb +5 -0
- data/motion/core_ext/module/remove_method.rb +12 -0
- data/motion/core_ext/ns_dictionary.rb +14 -0
- data/motion/core_ext/ns_string.rb +14 -0
- data/motion/core_ext/numeric/bytes.rb +44 -0
- data/motion/core_ext/numeric/conversions.rb +49 -0
- data/motion/core_ext/numeric/time.rb +75 -0
- data/motion/core_ext/object/acts_like.rb +10 -0
- data/motion/core_ext/object/blank.rb +105 -0
- data/motion/core_ext/object/deep_dup.rb +44 -0
- data/motion/core_ext/object/duplicable.rb +87 -0
- data/motion/core_ext/object/inclusion.rb +15 -0
- data/motion/core_ext/object/instance_variables.rb +28 -0
- data/motion/core_ext/object/to_param.rb +58 -0
- data/motion/core_ext/object/to_query.rb +26 -0
- data/motion/core_ext/object/try.rb +78 -0
- data/motion/core_ext/range/include_range.rb +23 -0
- data/motion/core_ext/range/overlaps.rb +8 -0
- data/motion/core_ext/regexp.rb +5 -0
- data/motion/core_ext/string/access.rb +104 -0
- data/motion/core_ext/string/behavior.rb +6 -0
- data/motion/core_ext/string/exclude.rb +11 -0
- data/motion/core_ext/string/filters.rb +55 -0
- data/motion/core_ext/string/indent.rb +43 -0
- data/motion/core_ext/string/inflections.rb +178 -0
- data/motion/core_ext/string/starts_ends_with.rb +4 -0
- data/motion/core_ext/string/strip.rb +24 -0
- data/motion/core_ext/time/acts_like.rb +8 -0
- data/motion/core_ext/time/calculations.rb +215 -0
- data/motion/core_ext/time/conversions.rb +52 -0
- data/motion/descendants_tracker.rb +50 -0
- data/motion/duration.rb +104 -0
- data/motion/hash_with_indifferent_access.rb +253 -0
- data/motion/inflections.rb +67 -0
- data/motion/inflector/inflections.rb +203 -0
- data/motion/inflector/methods.rb +321 -0
- data/motion/logger.rb +47 -0
- data/motion/number_helper.rb +54 -0
- data/motion/version.rb +3 -0
- data/motion_blender-support.gemspec +21 -0
- data/spec/motion-support/_helpers/constantize_test_cases.rb +75 -0
- data/spec/motion-support/_helpers/inflector_test_cases.rb +270 -0
- data/spec/motion-support/callback_spec.rb +702 -0
- data/spec/motion-support/concern_spec.rb +93 -0
- data/spec/motion-support/core_ext/array/access_spec.rb +29 -0
- data/spec/motion-support/core_ext/array/conversion_spec.rb +60 -0
- data/spec/motion-support/core_ext/array/extract_options_spec.rb +15 -0
- data/spec/motion-support/core_ext/array/grouping_spec.rb +85 -0
- data/spec/motion-support/core_ext/array/prepend_and_append_spec.rb +25 -0
- data/spec/motion-support/core_ext/array/wrap_spec.rb +19 -0
- data/spec/motion-support/core_ext/array_spec.rb +16 -0
- data/spec/motion-support/core_ext/class/attribute_accessor_spec.rb +127 -0
- data/spec/motion-support/core_ext/class/attribute_spec.rb +92 -0
- data/spec/motion-support/core_ext/date/acts_like_spec.rb +11 -0
- data/spec/motion-support/core_ext/date/calculation_spec.rb +186 -0
- data/spec/motion-support/core_ext/date/conversion_spec.rb +18 -0
- data/spec/motion-support/core_ext/date_and_time/calculation_spec.rb +336 -0
- data/spec/motion-support/core_ext/enumerable_spec.rb +130 -0
- data/spec/motion-support/core_ext/hash/deep_delete_if_spec.rb +19 -0
- data/spec/motion-support/core_ext/hash/deep_merge_spec.rb +32 -0
- data/spec/motion-support/core_ext/hash/except_spec.rb +43 -0
- data/spec/motion-support/core_ext/hash/key_spec.rb +236 -0
- data/spec/motion-support/core_ext/hash/reverse_merge_spec.rb +26 -0
- data/spec/motion-support/core_ext/hash/slice_spec.rb +61 -0
- data/spec/motion-support/core_ext/integer/inflection_spec.rb +23 -0
- data/spec/motion-support/core_ext/integer/multiple_spec.rb +19 -0
- data/spec/motion-support/core_ext/kernel/singleton_class_spec.rb +9 -0
- data/spec/motion-support/core_ext/metaclass_spec.rb +9 -0
- data/spec/motion-support/core_ext/module/aliasing_spec.rb +143 -0
- data/spec/motion-support/core_ext/module/anonymous_spec.rb +29 -0
- data/spec/motion-support/core_ext/module/attr_internal_spec.rb +104 -0
- data/spec/motion-support/core_ext/module/attribute_accessor_spec.rb +86 -0
- data/spec/motion-support/core_ext/module/delegation_spec.rb +136 -0
- data/spec/motion-support/core_ext/module/introspection_spec.rb +70 -0
- data/spec/motion-support/core_ext/module/reachable_spec.rb +61 -0
- data/spec/motion-support/core_ext/module/remove_method_spec.rb +25 -0
- data/spec/motion-support/core_ext/numeric/bytes_spec.rb +43 -0
- data/spec/motion-support/core_ext/numeric/conversions_spec.rb +40 -0
- data/spec/motion-support/core_ext/object/acts_like_spec.rb +21 -0
- data/spec/motion-support/core_ext/object/blank_spec.rb +54 -0
- data/spec/motion-support/core_ext/object/deep_dup_spec.rb +54 -0
- data/spec/motion-support/core_ext/object/duplicable_spec.rb +31 -0
- data/spec/motion-support/core_ext/object/inclusion_spec.rb +34 -0
- data/spec/motion-support/core_ext/object/instance_variable_spec.rb +19 -0
- data/spec/motion-support/core_ext/object/to_param_spec.rb +75 -0
- data/spec/motion-support/core_ext/object/to_query_spec.rb +37 -0
- data/spec/motion-support/core_ext/object/try_spec.rb +92 -0
- data/spec/motion-support/core_ext/range/include_range_spec.rb +31 -0
- data/spec/motion-support/core_ext/range/overlap_spec.rb +43 -0
- data/spec/motion-support/core_ext/regexp_spec.rb +7 -0
- data/spec/motion-support/core_ext/string/access_spec.rb +53 -0
- data/spec/motion-support/core_ext/string/behavior_spec.rb +7 -0
- data/spec/motion-support/core_ext/string/exclude_spec.rb +8 -0
- data/spec/motion-support/core_ext/string/filter_spec.rb +49 -0
- data/spec/motion-support/core_ext/string/indent_spec.rb +56 -0
- data/spec/motion-support/core_ext/string/inflection_spec.rb +142 -0
- data/spec/motion-support/core_ext/string/starts_end_with_spec.rb +14 -0
- data/spec/motion-support/core_ext/string/strip_spec.rb +34 -0
- data/spec/motion-support/core_ext/string_spec.rb +88 -0
- data/spec/motion-support/core_ext/time/acts_like_spec.rb +11 -0
- data/spec/motion-support/core_ext/time/calculation_spec.rb +201 -0
- data/spec/motion-support/core_ext/time/conversion_spec.rb +53 -0
- data/spec/motion-support/descendants_tracker_spec.rb +58 -0
- data/spec/motion-support/duration_spec.rb +107 -0
- data/spec/motion-support/hash_with_indifferent_access_spec.rb +605 -0
- data/spec/motion-support/inflector_spec.rb +504 -0
- data/spec/motion-support/ns_dictionary_spec.rb +89 -0
- data/spec/motion-support/ns_string_spec.rb +182 -0
- data/spec/motion-support/number_helper_spec.rb +55 -0
- metadata +352 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
describe "hash" do
|
2
|
+
before do
|
3
|
+
@hash_1 = { :a => "a", :b => "b", :c => { :c1 => "c1", :c2 => "c2", :c3 => { :d1 => "d1" } } }
|
4
|
+
@hash_2 = { :a => 1, :c => { :c1 => 2, :c3 => { :d2 => "d2" } } }
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "deep_merge" do
|
8
|
+
it "should deep merge" do
|
9
|
+
expected = { :a => 1, :b => "b", :c => { :c1 => 2, :c2 => "c2", :c3 => { :d1 => "d1", :d2 => "d2" } } }
|
10
|
+
@hash_1.deep_merge(@hash_2).should == expected
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should deep merge with block" do
|
14
|
+
expected = { :a => [:a, "a", 1], :b => "b", :c => { :c1 => [:c1, "c1", 2], :c2 => "c2", :c3 => { :d1 => "d1", :d2 => "d2" } } }
|
15
|
+
(@hash_1.deep_merge(@hash_2) { |k,o,n| [k, o, n] }).should == expected
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "deep_merge!" do
|
20
|
+
it "should deep merge" do
|
21
|
+
expected = { :a => 1, :b => "b", :c => { :c1 => 2, :c2 => "c2", :c3 => { :d1 => "d1", :d2 => "d2" } } }
|
22
|
+
@hash_1.deep_merge!(@hash_2)
|
23
|
+
@hash_1.should == expected
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should deep merge with block" do
|
27
|
+
expected = { :a => [:a, "a", 1], :b => "b", :c => { :c1 => [:c1, "c1", 2], :c2 => "c2", :c3 => { :d1 => "d1", :d2 => "d2" } } }
|
28
|
+
@hash_1.deep_merge!(@hash_2) { |k,o,n| [k, o, n] }
|
29
|
+
@hash_1.should == expected
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
describe "hash" do
|
2
|
+
describe "except" do
|
3
|
+
it "should remove key" do
|
4
|
+
original = { :a => 'x', :b => 'y', :c => 10 }
|
5
|
+
expected = { :a => 'x', :b => 'y' }
|
6
|
+
|
7
|
+
original.except(:c).should == expected
|
8
|
+
original.should.not == expected
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should remove more than one key" do
|
12
|
+
original = { :a => 'x', :b => 'y', :c => 10 }
|
13
|
+
expected = { :a => 'x' }
|
14
|
+
original.except(:b, :c).should == expected
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should work on frozen hash" do
|
18
|
+
original = { :a => 'x', :b => 'y' }
|
19
|
+
original.freeze
|
20
|
+
lambda { original.except(:a) }.should.not.raise
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "except!" do
|
25
|
+
it "should remove key in place" do
|
26
|
+
original = { :a => 'x', :b => 'y', :c => 10 }
|
27
|
+
expected = { :a => 'x', :b => 'y' }
|
28
|
+
|
29
|
+
original.should.not == expected
|
30
|
+
original.except!(:c).should == expected
|
31
|
+
original.should == expected
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should remove more than one key in place" do
|
35
|
+
original = { :a => 'x', :b => 'y', :c => 10 }
|
36
|
+
expected = { :a => 'x' }
|
37
|
+
|
38
|
+
original.should.not == expected
|
39
|
+
original.except!(:b, :c).should == expected
|
40
|
+
original.should == expected
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,236 @@
|
|
1
|
+
describe "Hash" do
|
2
|
+
describe "keys" do
|
3
|
+
before do
|
4
|
+
@strings = { 'a' => 1, 'b' => 2 }
|
5
|
+
@nested_strings = { 'a' => { 'b' => { 'c' => 3 } } }
|
6
|
+
@symbols = { :a => 1, :b => 2 }
|
7
|
+
@nested_symbols = { :a => { :b => { :c => 3 } } }
|
8
|
+
@mixed = { :a => 1, 'b' => 2 }
|
9
|
+
@nested_mixed = { 'a' => { :b => { 'c' => 3 } } }
|
10
|
+
@fixnums = { 0 => 1, 1 => 2 }
|
11
|
+
@nested_fixnums = { 0 => { 1 => { 2 => 3} } }
|
12
|
+
@illegal_symbols = { [] => 3 }
|
13
|
+
@nested_illegal_symbols = { [] => { [] => 3} }
|
14
|
+
@upcase_strings = { 'A' => 1, 'B' => 2 }
|
15
|
+
@nested_upcase_strings = { 'A' => { 'B' => { 'C' => 3 } } }
|
16
|
+
@nested_array_symbols = { :a => [ { :a => 1 }, { :b => 2 } ] }
|
17
|
+
@nested_array_strings = { 'a' => [ { 'a' => 1 }, { 'b' => 2 } ] }
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have all key methods defined on literal hash" do
|
21
|
+
h = {}
|
22
|
+
h.should.respond_to :transform_keys
|
23
|
+
h.should.respond_to :transform_keys!
|
24
|
+
h.should.respond_to :deep_transform_keys
|
25
|
+
h.should.respond_to :deep_transform_keys!
|
26
|
+
h.should.respond_to :symbolize_keys
|
27
|
+
h.should.respond_to :symbolize_keys!
|
28
|
+
h.should.respond_to :deep_symbolize_keys
|
29
|
+
h.should.respond_to :deep_symbolize_keys!
|
30
|
+
h.should.respond_to :stringify_keys
|
31
|
+
h.should.respond_to :stringify_keys!
|
32
|
+
h.should.respond_to :deep_stringify_keys
|
33
|
+
h.should.respond_to :deep_stringify_keys!
|
34
|
+
h.should.respond_to :to_options
|
35
|
+
h.should.respond_to :to_options!
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "transform_keys" do
|
39
|
+
it "should transform keys" do
|
40
|
+
@strings.transform_keys{ |key| key.to_s.upcase }.should == @upcase_strings
|
41
|
+
@symbols.transform_keys{ |key| key.to_s.upcase }.should == @upcase_strings
|
42
|
+
@mixed.transform_keys{ |key| key.to_s.upcase }.should == @upcase_strings
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should not mutate" do
|
46
|
+
transformed_hash = @mixed.dup
|
47
|
+
transformed_hash.transform_keys{ |key| key.to_s.upcase }
|
48
|
+
transformed_hash.should == @mixed
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "deep_transform_keys" do
|
53
|
+
it "should deep transform keys" do
|
54
|
+
@nested_symbols.deep_transform_keys{ |key| key.to_s.upcase }.should == @nested_upcase_strings
|
55
|
+
@nested_strings.deep_transform_keys{ |key| key.to_s.upcase }.should == @nested_upcase_strings
|
56
|
+
@nested_mixed.deep_transform_keys{ |key| key.to_s.upcase }.should == @nested_upcase_strings
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should not mutate" do
|
60
|
+
transformed_hash = @nested_mixed.deep_dup
|
61
|
+
transformed_hash.deep_transform_keys{ |key| key.to_s.upcase }
|
62
|
+
transformed_hash.should == @nested_mixed
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "transform_keys!" do
|
67
|
+
it "should transform keys" do
|
68
|
+
@symbols.dup.transform_keys!{ |key| key.to_s.upcase }.should == @upcase_strings
|
69
|
+
@strings.dup.transform_keys!{ |key| key.to_s.upcase }.should == @upcase_strings
|
70
|
+
@mixed.dup.transform_keys!{ |key| key.to_s.upcase }.should == @upcase_strings
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should mutate" do
|
74
|
+
transformed_hash = @mixed.dup
|
75
|
+
transformed_hash.transform_keys!{ |key| key.to_s.upcase }
|
76
|
+
transformed_hash.should == @upcase_strings
|
77
|
+
{ :a => 1, "b" => 2 }.should == @mixed
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "deep_transform_keys!" do
|
82
|
+
it "should deep transform keys" do
|
83
|
+
@nested_symbols.deep_dup.deep_transform_keys!{ |key| key.to_s.upcase }.should == @nested_upcase_strings
|
84
|
+
@nested_strings.deep_dup.deep_transform_keys!{ |key| key.to_s.upcase }.should == @nested_upcase_strings
|
85
|
+
@nested_mixed.deep_dup.deep_transform_keys!{ |key| key.to_s.upcase }.should == @nested_upcase_strings
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should mutate" do
|
89
|
+
transformed_hash = @nested_mixed.deep_dup
|
90
|
+
transformed_hash.deep_transform_keys!{ |key| key.to_s.upcase }
|
91
|
+
transformed_hash.should == @nested_upcase_strings
|
92
|
+
{ 'a' => { :b => { 'c' => 3 } } }.should == @nested_mixed
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "symbolize_keys" do
|
97
|
+
it "should symbolize keys" do
|
98
|
+
@symbols.symbolize_keys.should == @symbols
|
99
|
+
@strings.symbolize_keys.should == @symbols
|
100
|
+
@mixed.symbolize_keys.should == @symbols
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should not mutate" do
|
104
|
+
transformed_hash = @mixed.dup
|
105
|
+
transformed_hash.symbolize_keys
|
106
|
+
transformed_hash.should == @mixed
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should preserve keys that can't be symbolized" do
|
110
|
+
@illegal_symbols.symbolize_keys.should == @illegal_symbols
|
111
|
+
@illegal_symbols.dup.symbolize_keys!.should == @illegal_symbols
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should preserve fixnum keys" do
|
115
|
+
@fixnums.symbolize_keys.should == @fixnums
|
116
|
+
@fixnums.dup.symbolize_keys!.should == @fixnums
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "deep_symbolize_keys" do
|
121
|
+
it "should deep symbolize keys" do
|
122
|
+
@nested_symbols.deep_symbolize_keys.should == @nested_symbols
|
123
|
+
@nested_strings.deep_symbolize_keys.should == @nested_symbols
|
124
|
+
@nested_mixed.deep_symbolize_keys.should == @nested_symbols
|
125
|
+
@nested_array_strings.deep_symbolize_keys.should == @nested_array_symbols
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should not mutate" do
|
129
|
+
transformed_hash = @nested_mixed.deep_dup
|
130
|
+
transformed_hash.deep_symbolize_keys
|
131
|
+
transformed_hash.should == @nested_mixed
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should preserve keys that can't be symbolized" do
|
135
|
+
@nested_illegal_symbols.deep_symbolize_keys.should == @nested_illegal_symbols
|
136
|
+
@nested_illegal_symbols.deep_dup.deep_symbolize_keys!.should == @nested_illegal_symbols
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should preserve fixnum keys" do
|
140
|
+
@nested_fixnums.deep_symbolize_keys.should == @nested_fixnums
|
141
|
+
@nested_fixnums.deep_dup.deep_symbolize_keys!.should == @nested_fixnums
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "symbolize_keys!" do
|
146
|
+
it "should symbolize keys" do
|
147
|
+
@symbols.dup.symbolize_keys!.should == @symbols
|
148
|
+
@strings.dup.symbolize_keys!.should == @symbols
|
149
|
+
@mixed.dup.symbolize_keys!.should == @symbols
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should mutate" do
|
153
|
+
transformed_hash = @mixed.dup
|
154
|
+
transformed_hash.deep_symbolize_keys!
|
155
|
+
transformed_hash.should == @symbols
|
156
|
+
{ :a => 1, "b" => 2 }.should == @mixed
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "deep_symbolize_keys!" do
|
161
|
+
it "should deep symbolize keys" do
|
162
|
+
@nested_symbols.deep_dup.deep_symbolize_keys!.should == @nested_symbols
|
163
|
+
@nested_strings.deep_dup.deep_symbolize_keys!.should == @nested_symbols
|
164
|
+
@nested_mixed.deep_dup.deep_symbolize_keys!.should == @nested_symbols
|
165
|
+
@nested_array_strings.deep_symbolize_keys!.should == @nested_array_symbols
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should mutate" do
|
169
|
+
transformed_hash = @nested_mixed.deep_dup
|
170
|
+
transformed_hash.deep_symbolize_keys!
|
171
|
+
transformed_hash.should == @nested_symbols
|
172
|
+
{ 'a' => { :b => { 'c' => 3 } } }.should == @nested_mixed
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
describe "stringify_keys" do
|
177
|
+
it "should stringify keys" do
|
178
|
+
@symbols.stringify_keys.should == @strings
|
179
|
+
@strings.stringify_keys.should == @strings
|
180
|
+
@mixed.stringify_keys.should == @strings
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should not mutate" do
|
184
|
+
transformed_hash = @mixed.dup
|
185
|
+
transformed_hash.stringify_keys
|
186
|
+
transformed_hash.should == @mixed
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "deep stringify_keys" do
|
191
|
+
it "should deep stringify keys" do
|
192
|
+
@nested_symbols.deep_stringify_keys.should == @nested_strings
|
193
|
+
@nested_strings.deep_stringify_keys.should == @nested_strings
|
194
|
+
@nested_mixed.deep_stringify_keys.should == @nested_strings
|
195
|
+
@nested_array_symbols.deep_stringify_keys.should == @nested_array_strings
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should not mutate" do
|
199
|
+
transformed_hash = @nested_mixed.deep_dup
|
200
|
+
transformed_hash.deep_stringify_keys
|
201
|
+
transformed_hash.should == @nested_mixed
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
describe "stringify_keys!" do
|
206
|
+
it "should stringify keys" do
|
207
|
+
@symbols.dup.stringify_keys!.should == @strings
|
208
|
+
@strings.dup.stringify_keys!.should == @strings
|
209
|
+
@mixed.dup.stringify_keys!.should == @strings
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should mutate" do
|
213
|
+
transformed_hash = @mixed.dup
|
214
|
+
transformed_hash.stringify_keys!
|
215
|
+
transformed_hash.should == @strings
|
216
|
+
{ :a => 1, "b" => 2 }.should == @mixed
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe "deep_stringify_keys!" do
|
221
|
+
it "should deep stringify keys" do
|
222
|
+
@nested_symbols.deep_dup.deep_stringify_keys!.should == @nested_strings
|
223
|
+
@nested_strings.deep_dup.deep_stringify_keys!.should == @nested_strings
|
224
|
+
@nested_mixed.deep_dup.deep_stringify_keys!.should == @nested_strings
|
225
|
+
@nested_array_symbols.deep_stringify_keys!.should == @nested_array_strings
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should mutate" do
|
229
|
+
transformed_hash = @nested_mixed.deep_dup
|
230
|
+
transformed_hash.deep_stringify_keys!
|
231
|
+
transformed_hash.should == @nested_strings
|
232
|
+
{ 'a' => { :b => { 'c' => 3 } } }.should == @nested_mixed
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
describe "hash" do
|
2
|
+
describe "reverse_merge" do
|
3
|
+
before do
|
4
|
+
@defaults = { :a => "x", :b => "y", :c => 10 }.freeze
|
5
|
+
@options = { :a => 1, :b => 2 }
|
6
|
+
@expected = { :a => 1, :b => 2, :c => 10 }
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should merge defaults into options, creating a new hash" do
|
10
|
+
@options.reverse_merge(@defaults).should == @expected
|
11
|
+
@options.should.not == @expected
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should merge! defaults into options, replacing options" do
|
15
|
+
merged = @options.dup
|
16
|
+
merged.reverse_merge!(@defaults).should == @expected
|
17
|
+
merged.should == @expected
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should be an alias for reverse_merge!" do
|
21
|
+
merged = @options.dup
|
22
|
+
merged.reverse_update(@defaults).should == @expected
|
23
|
+
merged.should == @expected
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
describe "hash" do
|
2
|
+
describe "slice" do
|
3
|
+
it "should return a new hash with only the given keys" do
|
4
|
+
original = { :a => 'x', :b => 'y', :c => 10 }
|
5
|
+
expected = { :a => 'x', :b => 'y' }
|
6
|
+
|
7
|
+
original.slice(:a, :b).should == expected
|
8
|
+
original.should.not == expected
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should replace the hash with only the given keys" do
|
12
|
+
original = { :a => 'x', :b => 'y', :c => 10 }
|
13
|
+
expected = { :c => 10 }
|
14
|
+
|
15
|
+
original.slice!(:a, :b).should == expected
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return a new hash with only the given keys when given an array key" do
|
19
|
+
original = { :a => 'x', :b => 'y', :c => 10, [:a, :b] => "an array key" }
|
20
|
+
expected = { [:a, :b] => "an array key", :c => 10 }
|
21
|
+
|
22
|
+
original.slice([:a, :b], :c).should == expected
|
23
|
+
original.should.not == expected
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should replace the hash with only the given keys when given an array key" do
|
27
|
+
original = { :a => 'x', :b => 'y', :c => 10, [:a, :b] => "an array key" }
|
28
|
+
expected = { :a => 'x', :b => 'y' }
|
29
|
+
|
30
|
+
original.slice!([:a, :b], :c).should == expected
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should grab each of the splatted keys" do
|
34
|
+
original = { :a => 'x', :b => 'y', :c => 10, [:a, :b] => "an array key" }
|
35
|
+
expected = { :a => 'x', :b => "y" }
|
36
|
+
|
37
|
+
original.slice(*[:a, :b]).should == expected
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "extract!" do
|
42
|
+
it "should extract subhash" do
|
43
|
+
original = {:a => 1, :b => 2, :c => 3, :d => 4}
|
44
|
+
expected = {:a => 1, :b => 2}
|
45
|
+
remaining = {:c => 3, :d => 4}
|
46
|
+
|
47
|
+
original.extract!(:a, :b, :x).should == expected
|
48
|
+
original.should == remaining
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should extract nils" do
|
52
|
+
original = {:a => nil, :b => nil}
|
53
|
+
expected = {:a => nil}
|
54
|
+
extracted = original.extract!(:a, :x)
|
55
|
+
|
56
|
+
extracted.should == expected
|
57
|
+
extracted[:a].should == nil
|
58
|
+
extracted[:x].should == nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# These tests are mostly just to ensure that the ordinalize method exists.
|
2
|
+
# Its results are tested comprehensively in the inflector test cases.
|
3
|
+
describe "Integer" do
|
4
|
+
describe "ordinalize" do
|
5
|
+
it "should ordinalize 1" do
|
6
|
+
1.ordinalize.should == '1st'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should ordinalize 8" do
|
10
|
+
8.ordinalize.should == '8th'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "ordinal" do
|
15
|
+
it "should get ordinal of 1" do
|
16
|
+
1.ordinal.should == 'st'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should get ordinal of 8" do
|
20
|
+
8.ordinal.should == 'th'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
PRIME = 22953686867719691230002707821868552601124472329079
|
2
|
+
|
3
|
+
describe "Integer" do
|
4
|
+
describe "multiple_of" do
|
5
|
+
it "should determine if an integer is a multiple of another" do
|
6
|
+
[ -7, 0, 7, 14 ].each { |i| i.should.be.multiple_of 7 }
|
7
|
+
[ -7, 7, 14 ].each { |i| i.should.not.be.multiple_of 6 }
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should work with edge cases" do
|
11
|
+
0.should.be.multiple_of 0
|
12
|
+
5.should.not.be.multiple_of 0
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should work with a prime" do
|
16
|
+
[2, 3, 5, 7].each { |i| PRIME.should.not.be.multiple_of i }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
module Aliasing
|
2
|
+
class File
|
3
|
+
public
|
4
|
+
def open(file)
|
5
|
+
end
|
6
|
+
def open_with_internet(url)
|
7
|
+
open_without_internet(url)
|
8
|
+
end
|
9
|
+
alias_method_chain :open, :internet
|
10
|
+
|
11
|
+
protected
|
12
|
+
def exist?(file)
|
13
|
+
end
|
14
|
+
def exist_with_internet?(url)
|
15
|
+
exist_without_internet?(url)
|
16
|
+
end
|
17
|
+
alias_method_chain :exist?, :internet
|
18
|
+
|
19
|
+
private
|
20
|
+
def remove!(file)
|
21
|
+
end
|
22
|
+
def remove_with_internet!(url)
|
23
|
+
remove_without_internet!(url)
|
24
|
+
end
|
25
|
+
alias_method_chain :remove!, :internet
|
26
|
+
end
|
27
|
+
|
28
|
+
class Content
|
29
|
+
attr_accessor :title, :Data
|
30
|
+
|
31
|
+
def initialize
|
32
|
+
@title, @Data = nil, nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def title?
|
36
|
+
!title.nil?
|
37
|
+
end
|
38
|
+
|
39
|
+
def Data?
|
40
|
+
!self.Data.nil?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class Email < Content
|
45
|
+
alias_attribute :subject, :title
|
46
|
+
alias_attribute :body, :Data
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "module" do
|
51
|
+
describe "alias_method_chain" do
|
52
|
+
it "should define 'without' method" do
|
53
|
+
Aliasing::File.new.should.respond_to :open_without_internet
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should respond to original method" do
|
57
|
+
Aliasing::File.new.should.respond_to :open
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should respond to 'with' method" do
|
61
|
+
Aliasing::File.new.should.respond_to :open_with_internet
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should preserve question punctuation" do
|
65
|
+
Aliasing::File.new.should.respond_to :exist_without_internet?
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should preserve bang punctuation" do
|
69
|
+
# Ruby objects don't respond to private methods
|
70
|
+
Aliasing::File.new.should.not.respond_to :remove_without_internet!
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should keep public methods public" do
|
74
|
+
Aliasing::File.new.public_methods.should.include :"open_without_internet:"
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should keep protected methods protected" do
|
78
|
+
Aliasing::File.new.protected_methods.should.include :"exist_without_internet?:"
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should keep private methods private" do
|
82
|
+
Aliasing::File.new.private_methods.should.include :"remove_without_internet!:"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "alias_attribute" do
|
87
|
+
before do
|
88
|
+
@email = Aliasing::Email.new
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "getter" do
|
92
|
+
it "should exist" do
|
93
|
+
lambda { @email.subject }.should.not.raise
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should read" do
|
97
|
+
@email.title = "hello"
|
98
|
+
@email.subject.should == "hello"
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should read from uppercase method" do
|
102
|
+
@email.body = "world"
|
103
|
+
@email.Data.should == "world"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "setter" do
|
108
|
+
it "should exist" do
|
109
|
+
lambda { @email.subject = "hello" }.should.not.raise
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should write" do
|
113
|
+
@email.subject = "hello"
|
114
|
+
@email.title.should == "hello"
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should write to uppercase method" do
|
118
|
+
@email.Data = "world"
|
119
|
+
@email.body.should == "world"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "question method" do
|
124
|
+
it "should exist" do
|
125
|
+
lambda { @email.subject? }.should.not.raise
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should return false for nil attribute" do
|
129
|
+
@email.subject?.should == false
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should return true for non-nil attribute" do
|
133
|
+
@email.title = "hello"
|
134
|
+
@email.subject?.should == true
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should return true for non-nil uppercase attribute" do
|
138
|
+
@email.body = "hello"
|
139
|
+
@email.Data?.should == true
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
describe "module" do
|
2
|
+
describe "anonymous?" do
|
3
|
+
it "should return true for an anonymous module" do
|
4
|
+
Module.new.anonymous?.should == true
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should return true for an anonymous class" do
|
8
|
+
Class.new.anonymous?.should == true
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return false for a named module" do
|
12
|
+
Kernel.anonymous?.should == false
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return false for a named class" do
|
16
|
+
Object.anonymous?.should == false
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return false for module that acquired a name" do
|
20
|
+
NamedModule = Module.new
|
21
|
+
NamedModule.anonymous?.should == false
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return false for module that acquired a name" do
|
25
|
+
NamedClass = Class.new
|
26
|
+
NamedClass.anonymous?.should == false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|