gorillib 0.1.11 → 0.4.0pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rspec +1 -2
- data/.yardopts +9 -0
- data/{CHANGELOG.textile → CHANGELOG.md} +35 -9
- data/Gemfile +21 -14
- data/Guardfile +19 -0
- data/{LICENSE.textile → LICENSE.md} +43 -29
- data/README.md +47 -52
- data/Rakefile +31 -30
- data/TODO.md +32 -0
- data/VERSION +1 -1
- data/examples/builder/ironfan.rb +133 -0
- data/examples/model/simple.rb +17 -0
- data/gorillib.gemspec +106 -86
- data/lib/alt/kernel/call_stack.rb +56 -0
- data/lib/gorillib/array/wrap.rb +53 -0
- data/lib/gorillib/base.rb +3 -3
- data/lib/gorillib/builder/field.rb +5 -0
- data/lib/gorillib/builder.rb +260 -0
- data/lib/gorillib/collection/has_collection.rb +31 -0
- data/lib/gorillib/collection.rb +129 -0
- data/lib/gorillib/configurable.rb +28 -0
- data/lib/gorillib/datetime/{flat.rb → to_flat.rb} +0 -0
- data/lib/gorillib/exception/confidence.rb +17 -0
- data/lib/gorillib/exception/raisers.rb +78 -0
- data/lib/gorillib/hash/mash.rb +202 -0
- data/lib/gorillib/hashlike/slice.rb +53 -19
- data/lib/gorillib/hashlike.rb +5 -3
- data/lib/gorillib/io/system_helpers.rb +30 -0
- data/lib/gorillib/logger/log.rb +18 -0
- data/lib/gorillib/metaprogramming/concern.rb +124 -0
- data/lib/gorillib/model/active_model_conversion.rb +68 -0
- data/lib/gorillib/model/active_model_naming.rb +87 -0
- data/lib/gorillib/model/active_model_shim.rb +33 -0
- data/lib/gorillib/model/base.rb +341 -0
- data/lib/gorillib/model/defaults.rb +71 -0
- data/lib/gorillib/model/errors.rb +14 -0
- data/lib/gorillib/model/factories.rb +372 -0
- data/lib/gorillib/model/field.rb +146 -0
- data/lib/gorillib/model/named_schema.rb +53 -0
- data/lib/gorillib/{struct/hashlike_iteration.rb → model/overlay.rb} +0 -0
- data/lib/gorillib/model/record_schema.rb +9 -0
- data/lib/gorillib/model/serialization.rb +23 -0
- data/lib/gorillib/model/validate.rb +22 -0
- data/lib/gorillib/model.rb +23 -0
- data/lib/gorillib/pathname.rb +78 -0
- data/lib/gorillib/{serialization.rb → serialization/to_wire.rb} +0 -0
- data/lib/gorillib/some.rb +11 -9
- data/lib/gorillib/string/constantize.rb +21 -14
- data/lib/gorillib/string/inflections.rb +6 -76
- data/lib/gorillib/string/inflector.rb +192 -0
- data/lib/gorillib/string/simple_inflector.rb +267 -0
- data/lib/gorillib/type/extended.rb +52 -0
- data/lib/gorillib/utils/capture_output.rb +28 -0
- data/lib/gorillib/utils/console.rb +131 -0
- data/lib/gorillib/utils/nuke_constants.rb +9 -0
- data/lib/gorillib/utils/stub_module.rb +33 -0
- data/spec/examples/builder/ironfan_spec.rb +37 -0
- data/spec/extlib/hash_spec.rb +64 -0
- data/spec/extlib/mash_spec.rb +312 -0
- data/spec/{array → gorillib/array}/compact_blank_spec.rb +2 -2
- data/spec/{array → gorillib/array}/extract_options_spec.rb +2 -2
- data/spec/gorillib/builder_spec.rb +187 -0
- data/spec/gorillib/collection_spec.rb +20 -0
- data/spec/gorillib/configurable_spec.rb +62 -0
- data/spec/{datetime → gorillib/datetime}/parse_spec.rb +3 -3
- data/spec/{datetime/flat_spec.rb → gorillib/datetime/to_flat_spec.rb} +4 -4
- data/spec/{enumerable → gorillib/enumerable}/sum_spec.rb +5 -5
- data/spec/gorillib/exception/raisers_spec.rb +60 -0
- data/spec/{hash → gorillib/hash}/compact_spec.rb +2 -2
- data/spec/{hash → gorillib/hash}/deep_compact_spec.rb +3 -3
- data/spec/{hash → gorillib/hash}/deep_merge_spec.rb +2 -2
- data/spec/{hash → gorillib/hash}/keys_spec.rb +2 -2
- data/spec/{hash → gorillib/hash}/reverse_merge_spec.rb +2 -2
- data/spec/{hash → gorillib/hash}/slice_spec.rb +2 -2
- data/spec/{hash → gorillib/hash}/zip_spec.rb +2 -2
- data/spec/{hashlike → gorillib/hashlike}/behave_same_as_hash_spec.rb +6 -3
- data/spec/{hashlike → gorillib/hashlike}/deep_hash_spec.rb +2 -2
- data/spec/{hashlike → gorillib/hashlike}/hashlike_behavior_spec.rb +32 -30
- data/spec/{hashlike → gorillib/hashlike}/hashlike_via_accessors_spec.rb +3 -3
- data/spec/{hashlike_spec.rb → gorillib/hashlike_spec.rb} +3 -3
- data/spec/{logger → gorillib/logger}/log_spec.rb +2 -2
- data/spec/{metaprogramming → gorillib/metaprogramming}/aliasing_spec.rb +3 -3
- data/spec/{metaprogramming → gorillib/metaprogramming}/class_attribute_spec.rb +3 -3
- data/spec/{metaprogramming → gorillib/metaprogramming}/delegation_spec.rb +3 -3
- data/spec/{metaprogramming → gorillib/metaprogramming}/singleton_class_spec.rb +3 -3
- data/spec/gorillib/model/record/defaults_spec.rb +108 -0
- data/spec/gorillib/model/record/factories_spec.rb +321 -0
- data/spec/gorillib/model/record/overlay_spec.rb +46 -0
- data/spec/gorillib/model/serialization_spec.rb +48 -0
- data/spec/gorillib/model_spec.rb +281 -0
- data/spec/{numeric → gorillib/numeric}/clamp_spec.rb +2 -2
- data/spec/{object → gorillib/object}/blank_spec.rb +2 -2
- data/spec/{object → gorillib/object}/try_dup_spec.rb +2 -2
- data/spec/{object → gorillib/object}/try_spec.rb +3 -2
- data/spec/gorillib/pathname_spec.rb +114 -0
- data/spec/{string → gorillib/string}/constantize_spec.rb +2 -2
- data/spec/{string → gorillib/string}/human_spec.rb +2 -2
- data/spec/{string → gorillib/string}/inflections_spec.rb +4 -3
- data/spec/{string → gorillib/string}/inflector_test_cases.rb +0 -0
- data/spec/{string → gorillib/string}/truncate_spec.rb +4 -10
- data/spec/gorillib/type/extended_spec.rb +120 -0
- data/spec/gorillib/utils/capture_output_spec.rb +71 -0
- data/spec/spec_helper.rb +8 -11
- data/spec/support/gorillib_test_helpers.rb +66 -0
- data/spec/support/hashlike_fuzzing_helper.rb +31 -33
- data/spec/support/hashlike_helper.rb +3 -3
- data/spec/support/model_test_helpers.rb +81 -0
- data/spec/support/shared_examples/included_module.rb +20 -0
- metadata +177 -158
- data/lib/gorillib/array/average.rb +0 -13
- data/lib/gorillib/array/sorted_median.rb +0 -11
- data/lib/gorillib/array/sorted_percentile.rb +0 -11
- data/lib/gorillib/array/sorted_sample.rb +0 -12
- data/lib/gorillib/dsl_object.rb +0 -64
- data/lib/gorillib/hash/indifferent_access.rb +0 -207
- data/lib/gorillib/hash/tree_merge.rb +0 -4
- data/lib/gorillib/hashlike/tree_merge.rb +0 -49
- data/lib/gorillib/metaprogramming/cattr_accessor.rb +0 -79
- data/lib/gorillib/metaprogramming/mattr_accessor.rb +0 -61
- data/lib/gorillib/receiver/active_model_shim.rb +0 -32
- data/lib/gorillib/receiver/acts_as_hash.rb +0 -195
- data/lib/gorillib/receiver/acts_as_loadable.rb +0 -42
- data/lib/gorillib/receiver/locale/en.yml +0 -27
- data/lib/gorillib/receiver/tree_diff.rb +0 -74
- data/lib/gorillib/receiver/validations.rb +0 -30
- data/lib/gorillib/receiver.rb +0 -402
- data/lib/gorillib/receiver_model.rb +0 -21
- data/lib/gorillib/struct/acts_as_hash.rb +0 -108
- data/notes/fancy_hashes_and_receivers.textile +0 -120
- data/notes/hash_rdocs.textile +0 -97
- data/spec/array/average_spec.rb +0 -24
- data/spec/array/sorted_median_spec.rb +0 -18
- data/spec/array/sorted_percentile_spec.rb +0 -24
- data/spec/array/sorted_sample_spec.rb +0 -28
- data/spec/dsl_object_spec.rb +0 -99
- data/spec/hash/indifferent_access_spec.rb +0 -391
- data/spec/metaprogramming/cattr_accessor_spec.rb +0 -43
- data/spec/metaprogramming/mattr_accessor_spec.rb +0 -45
- data/spec/receiver/acts_as_hash_spec.rb +0 -295
- data/spec/receiver_spec.rb +0 -551
- data/spec/struct/acts_as_hash_fuzz_spec.rb +0 -71
- data/spec/struct/acts_as_hash_spec.rb +0 -422
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gorillib/exception/raisers'
|
3
|
+
|
4
|
+
describe 'raisers' do
|
5
|
+
def should_raise_my_error(msg=nil)
|
6
|
+
msg ||= error_message
|
7
|
+
expect{ yield }.to raise_error(described_class, msg)
|
8
|
+
end
|
9
|
+
def should_return_true
|
10
|
+
yield.should be_true
|
11
|
+
end
|
12
|
+
def capture_error
|
13
|
+
message = 'should have raised, did not'
|
14
|
+
begin
|
15
|
+
yield
|
16
|
+
rescue described_class => err
|
17
|
+
message = err.message
|
18
|
+
end
|
19
|
+
return message.gsub(/of arguments\(/, 'of arguments (')
|
20
|
+
end
|
21
|
+
|
22
|
+
describe ArgumentError do
|
23
|
+
|
24
|
+
context '.check_arity!' do
|
25
|
+
let(:error_message){ /wrong number of arguments/ }
|
26
|
+
it 'checks against a range' do
|
27
|
+
should_raise_my_error{ described_class.check_arity!(['a'], 2..5) }
|
28
|
+
should_raise_my_error{ described_class.check_arity!(['a'], 2..2) }
|
29
|
+
should_return_true{ described_class.check_arity!(['a'], 0..5) }
|
30
|
+
should_return_true{ described_class.check_arity!(['a'], 1..1) }
|
31
|
+
end
|
32
|
+
it 'checks against an array' do
|
33
|
+
should_raise_my_error{ described_class.check_arity!( ['a', 'b'], [1, 3, 5] ) }
|
34
|
+
should_return_true{ described_class.check_arity!( ['a', 'b'], [1, 2] ) }
|
35
|
+
end
|
36
|
+
it 'given a single number, requires exactly that many args' do
|
37
|
+
should_raise_my_error{ described_class.check_arity!( ['a', 'b'], 1 ) }
|
38
|
+
should_raise_my_error{ described_class.check_arity!( ['a', 'b'], 3 ) }
|
39
|
+
should_return_true{ described_class.check_arity!( ['a', 'b'], 2 ) }
|
40
|
+
end
|
41
|
+
it 'matches the message a native arity error would' do
|
42
|
+
should_raise_my_error(capture_error{ [].fill() }){ described_class.check_arity!([], 1..3) }
|
43
|
+
should_raise_my_error(capture_error{ [].to_s(1) }){ described_class.check_arity!([1], 0) }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context '.arity_at_least!' do
|
48
|
+
let(:error_message){ /wrong number of arguments/ }
|
49
|
+
it 'raises if there are fewer than that many args' do
|
50
|
+
should_raise_my_error{ described_class.arity_at_least!(['a'], 2) }
|
51
|
+
should_raise_my_error{ described_class.arity_at_least!([], 1) }
|
52
|
+
end
|
53
|
+
it ('returns true if there are that many args or more') do
|
54
|
+
should_return_true{ described_class.arity_at_least!([], 0) }
|
55
|
+
should_return_true{ described_class.arity_at_least!(['a'], 0) }
|
56
|
+
should_return_true{ described_class.arity_at_least!(['a'], 1) }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'gorillib/hash/deep_compact'
|
3
3
|
require 'gorillib/array/deep_compact'
|
4
4
|
|
5
|
-
describe Hash do
|
5
|
+
describe Hash, :hashlike_spec => true do
|
6
6
|
describe 'array/deep_compact and hash/deep_compact' do
|
7
7
|
it "should respond to the method deep_compact!" do
|
8
8
|
{ }.should respond_to :deep_compact!
|
@@ -19,7 +19,7 @@ describe Hash do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
describe Array do
|
22
|
+
describe Array, :hashlike_spec => true do
|
23
23
|
describe 'array/deep_compact and hash/deep_compact' do
|
24
24
|
it "should respond to the method deep_compact!" do
|
25
25
|
[ ].should respond_to :deep_compact!
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'gorillib/hash/slice'
|
3
3
|
|
4
4
|
class HashSubclass < Hash ; end
|
5
5
|
|
6
|
-
describe Hash do
|
6
|
+
describe Hash, :hashlike_spec => true do
|
7
7
|
describe '#slice' do
|
8
8
|
it 'should return a new hash with only the given keys' do
|
9
9
|
original = { :a => 'x', :b => 'y', :c => 10 }
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'gorillib/hash/zip'
|
3
3
|
|
4
|
-
describe Hash do
|
4
|
+
describe Hash, :hashlike_spec => true do
|
5
5
|
describe '#zip' do
|
6
6
|
it 'builds a hash from keys and values' do
|
7
7
|
Hash.zip([:a, :b, :c], [1, 2, 3]).should == { :a => 1, :b => 2, :c => 3 }
|
@@ -1,8 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'enumerator'
|
3
3
|
require 'gorillib/hashlike'
|
4
4
|
require 'gorillib/enumerable/sum'
|
5
5
|
|
6
|
+
require 'gorillib/utils/capture_output'
|
7
|
+
RSpec.configure{|c| c.include Gorillib::TestHelpers }
|
8
|
+
|
6
9
|
require GORILLIB_ROOT_DIR('spec/support/hashlike_helper')
|
7
10
|
require GORILLIB_ROOT_DIR('spec/support/hashlike_fuzzing_helper')
|
8
11
|
require GORILLIB_ROOT_DIR('spec/support/hashlike_via_delegation')
|
@@ -13,7 +16,7 @@ class InternalHashWithEquality < InternalHash
|
|
13
16
|
def ==(other_hash) @myhsh == other_hash ; end
|
14
17
|
end
|
15
18
|
|
16
|
-
describe Gorillib::Hashlike do
|
19
|
+
describe Gorillib::Hashlike, :hashlike_spec => true do
|
17
20
|
|
18
21
|
if ENV['FULL_SPECS']
|
19
22
|
|
@@ -100,6 +103,6 @@ describe Gorillib::Hashlike do
|
|
100
103
|
end
|
101
104
|
|
102
105
|
else
|
103
|
-
it 'skipping
|
106
|
+
it 'skipping lengthy example-based testing -- set environment variable FULL_SPECS=true to run all specs'
|
104
107
|
end
|
105
108
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'gorillib/hashlike/deep_hash'
|
3
3
|
|
4
4
|
class AwesomeHash < Hash
|
@@ -6,7 +6,7 @@ class AwesomeHash < Hash
|
|
6
6
|
end
|
7
7
|
class AwesomeHashSubclass < AwesomeHash ; end
|
8
8
|
|
9
|
-
describe Gorillib::Hashlike::DeepHash do
|
9
|
+
describe Gorillib::Hashlike::DeepHash, :hashlike_spec => true do
|
10
10
|
|
11
11
|
before(:each) do
|
12
12
|
@deep_hash = AwesomeHash.new({ :nested_1 => { :nested_2 => { :leaf_3 => "val3" }, :leaf_2 => ['arr'] }, :leaf_at_top => 'val1b' })
|
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'gorillib/utils/capture_output'
|
2
|
+
RSpec.configure{|c| c.include Gorillib::TestHelpers }
|
3
|
+
|
4
|
+
describe '', :hashlike_spec => true do
|
3
5
|
|
4
6
|
# ===========================================================================
|
5
7
|
#
|
@@ -14,7 +16,7 @@ describe '' do
|
|
14
16
|
|
15
17
|
it 'returns nil on a missing (but valid) key' do
|
16
18
|
@hshlike[:new_key].should == nil
|
17
|
-
end
|
19
|
+
end
|
18
20
|
end
|
19
21
|
|
20
22
|
shared_examples_for :references_string_and_symbol_keys_equivalently do
|
@@ -48,7 +50,7 @@ describe '' do
|
|
48
50
|
obj = Object.new
|
49
51
|
@hshlike[obj] = :i_haz_obj ; @hshlike[obj].should == :i_haz_obj; @hshlike.delete(obj).should == :i_haz_obj
|
50
52
|
@hshlike.should be_hash_eql(HashlikeHelper::BASE_HSH)
|
51
|
-
end
|
53
|
+
end
|
52
54
|
end
|
53
55
|
|
54
56
|
shared_examples_for :accepts_arbitrary_keys do
|
@@ -56,7 +58,7 @@ describe '' do
|
|
56
58
|
@hshlike[:fnord] = 69
|
57
59
|
@hshlike[:fnord].should == 69
|
58
60
|
@hshlike.delete(:fnord).should == 69
|
59
|
-
@hshlike[:boink].should be_nil
|
61
|
+
@hshlike[:boink].should be_nil
|
60
62
|
end
|
61
63
|
end
|
62
64
|
|
@@ -100,7 +102,7 @@ describe '' do
|
|
100
102
|
# ===========================================================================
|
101
103
|
#
|
102
104
|
# Iteration
|
103
|
-
|
105
|
+
|
104
106
|
shared_examples_for :with_no_block_returns_enumerator do |method_to_test|
|
105
107
|
it('returns an enumerator'){ @hshlike.send(method_to_test).should enumerate_method(@hshlike, method_to_test) }
|
106
108
|
end
|
@@ -163,7 +165,7 @@ describe '' do
|
|
163
165
|
end
|
164
166
|
end
|
165
167
|
|
166
|
-
shared_examples_for :each_key_on_stringlike_keys do
|
168
|
+
shared_examples_for :each_key_on_stringlike_keys do
|
167
169
|
it 'calls block once for each key in hsh' do
|
168
170
|
seen_keys = []
|
169
171
|
@hshlike.each_key{|k| seen_keys << k }
|
@@ -299,7 +301,7 @@ describe '' do
|
|
299
301
|
seen_args.should be_array_eql([[:a, nil, :aa], [:b, nil, nil], [:c, nil, :cc], [1, nil, 2]])
|
300
302
|
end
|
301
303
|
end
|
302
|
-
|
304
|
+
|
303
305
|
# ===========================================================================
|
304
306
|
#
|
305
307
|
# Retrieval and Membership
|
@@ -307,7 +309,7 @@ describe '' do
|
|
307
309
|
shared_examples_for :hashlike_values do
|
308
310
|
it 'returns a new array populated with the values from hsh' do
|
309
311
|
@hshlike.values.should be_array_eql([100, 200, 300, nil, false])
|
310
|
-
end
|
312
|
+
end
|
311
313
|
end
|
312
314
|
|
313
315
|
shared_examples_for :hashlike_values_at_or_of do |method_to_test|
|
@@ -330,7 +332,7 @@ describe '' do
|
|
330
332
|
end
|
331
333
|
it 'is zero for an empty hashlike' do
|
332
334
|
@empty_hshlike.send(method_to_test).should == 0
|
333
|
-
end
|
335
|
+
end
|
334
336
|
end
|
335
337
|
|
336
338
|
shared_examples_for :hashlike_has_key? do |method_to_test|
|
@@ -347,7 +349,7 @@ describe '' do
|
|
347
349
|
@hshlike.should evaluate_to_true(method_to_test, :nil_val)
|
348
350
|
@hshlike.should evaluate_to_true(method_to_test, :false_val)
|
349
351
|
end
|
350
|
-
it 'something something convert_key'
|
352
|
+
it 'something something convert_key' unless ENV['QUIET_RSPEC']
|
351
353
|
end
|
352
354
|
|
353
355
|
shared_examples_for :hashlike_has_key_predefined_always_present do |method_to_test|
|
@@ -364,7 +366,7 @@ describe '' do
|
|
364
366
|
@hshlike.should evaluate_to_true(method_to_test, :nil_val)
|
365
367
|
@hshlike.should evaluate_to_true(method_to_test, :false_val)
|
366
368
|
end
|
367
|
-
it 'something something convert_key'
|
369
|
+
it 'something something convert_key' unless ENV['QUIET_RSPEC']
|
368
370
|
end
|
369
371
|
|
370
372
|
shared_examples_for :hashlike_has_key_string_and_symbol_equivalent do |method_to_test|
|
@@ -405,7 +407,7 @@ describe '' do
|
|
405
407
|
@hshlike.send(method_to_test, false).should == true
|
406
408
|
@hshlike.send(method_to_test, nil).should == true
|
407
409
|
end
|
408
|
-
it 'something something convert_key'
|
410
|
+
it 'something something convert_key' unless ENV['QUIET_RSPEC']
|
409
411
|
end
|
410
412
|
|
411
413
|
shared_examples_for :hashlike_has_value_on_complex_keys do |method_to_test|
|
@@ -441,13 +443,15 @@ describe '' do
|
|
441
443
|
ret_val.should == :returned_as_default
|
442
444
|
end
|
443
445
|
it 'if block and default are both given, issues a warning and runs the block' do
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
446
|
+
quiet_output do
|
447
|
+
set_in_block = nil
|
448
|
+
ret_val = @hshlike.fetch(:new_key, :spurious_default){|k| set_in_block = "got: #{k}" ; "hello!" }
|
449
|
+
ret_val.should == "hello!"
|
450
|
+
set_in_block.should == "got: new_key"
|
451
|
+
end
|
448
452
|
end
|
449
453
|
end
|
450
|
-
it 'something something convert_key'
|
454
|
+
it 'something something convert_key' unless ENV['QUIET_RSPEC']
|
451
455
|
end
|
452
456
|
|
453
457
|
shared_examples_for :hashlike_key do
|
@@ -463,7 +467,7 @@ describe '' do
|
|
463
467
|
if (RUBY_VERSION >= '1.9')
|
464
468
|
@hshlike.key(999).should == :a
|
465
469
|
end
|
466
|
-
end
|
470
|
+
end
|
467
471
|
end
|
468
472
|
|
469
473
|
shared_examples_for :hashlike_assoc do
|
@@ -474,7 +478,7 @@ describe '' do
|
|
474
478
|
it 'returns nil if missing' do
|
475
479
|
@hshlike.assoc(:i_am_missing).should be_nil
|
476
480
|
end
|
477
|
-
it 'something something convert_key'
|
481
|
+
it 'something something convert_key' unless ENV['QUIET_RSPEC']
|
478
482
|
end
|
479
483
|
|
480
484
|
shared_examples_for :hashlike_rassoc do
|
@@ -485,7 +489,7 @@ describe '' do
|
|
485
489
|
end
|
486
490
|
it 'returns nil if missing' do
|
487
491
|
@hshlike.rassoc(:i_am_missing).should be_nil
|
488
|
-
end
|
492
|
+
end
|
489
493
|
end
|
490
494
|
|
491
495
|
shared_examples_for :hashlike_empty? do
|
@@ -496,7 +500,7 @@ describe '' do
|
|
496
500
|
@empty_hshlike.empty?.should == false
|
497
501
|
end
|
498
502
|
end
|
499
|
-
|
503
|
+
|
500
504
|
# ===========================================================================
|
501
505
|
#
|
502
506
|
# Update, merge!, merge
|
@@ -537,7 +541,7 @@ describe '' do
|
|
537
541
|
obj = Object.new
|
538
542
|
lambda{ @hshlike.send(method_to_test, obj) }.should raise_error(TypeError, "can't convert Object into Hash")
|
539
543
|
end
|
540
|
-
it 'something something convert_key'
|
544
|
+
it 'something something convert_key' unless ENV['QUIET_RSPEC']
|
541
545
|
end
|
542
546
|
|
543
547
|
shared_examples_for :merging_method_with_normal_keys do |method_to_test|
|
@@ -617,7 +621,7 @@ describe '' do
|
|
617
621
|
ret_val = @hshlike.send(method_to_test, {:a => "aaa", :b => 200, :nil_val => "here", :new_key => "zzz" })
|
618
622
|
ret_val.should equal(@hshlike)
|
619
623
|
@hshlike.should be_hash_eql({:a=>"aaa", :b=>200, :c=>300, :nil_val=>"here", :false_val=>false, :new_key=>"zzz"})
|
620
|
-
end
|
624
|
+
end
|
621
625
|
end
|
622
626
|
|
623
627
|
shared_examples_for :merging_method_returning_new do |method_to_test|
|
@@ -741,7 +745,7 @@ describe '' do
|
|
741
745
|
ret_val.should be_hash_eql(@empty_hshlike)
|
742
746
|
ret_val.should be_empty
|
743
747
|
@hshlike.should be_empty
|
744
|
-
end
|
748
|
+
end
|
745
749
|
end
|
746
750
|
|
747
751
|
# ===========================================================================
|
@@ -753,7 +757,7 @@ describe '' do
|
|
753
757
|
ret_val = @hshlike.to_hash
|
754
758
|
ret_val.should be_an_instance_of(Hash)
|
755
759
|
ret_val.should == HashlikeHelper::BASE_HSH
|
756
|
-
end
|
760
|
+
end
|
757
761
|
end
|
758
762
|
|
759
763
|
shared_examples_for :hashlike_invert do
|
@@ -818,7 +822,5 @@ describe '' do
|
|
818
822
|
end
|
819
823
|
end
|
820
824
|
|
821
|
-
|
822
|
-
|
823
|
-
end
|
824
|
-
end ; HASHLIKE_BEHAVIOR_SPEC = true
|
825
|
+
::HASHLIKE_BEHAVIOR_SPEC = true
|
826
|
+
end unless defined?(::HASHLIKE_BEHAVIOR_SPEC)
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'gorillib/hashlike'
|
3
3
|
require 'gorillib/hashlike/hashlike_via_accessors'
|
4
4
|
require GORILLIB_ROOT_DIR('spec/support/hashlike_via_delegation')
|
5
5
|
require GORILLIB_ROOT_DIR('spec/support/hashlike_helper')
|
6
|
-
require GORILLIB_ROOT_DIR('spec/hashlike/hashlike_behavior_spec')
|
6
|
+
require GORILLIB_ROOT_DIR('spec/gorillib/hashlike/hashlike_behavior_spec')
|
7
7
|
|
8
8
|
class SimpleHashlikeViaAccessors
|
9
9
|
attr_accessor :a, :b, :c, :nil_val, :false_val, :new_key
|
@@ -11,7 +11,7 @@ class SimpleHashlikeViaAccessors
|
|
11
11
|
include Gorillib::Hashlike
|
12
12
|
end
|
13
13
|
|
14
|
-
describe Gorillib::Hashlike::HashlikeViaAccessors do
|
14
|
+
describe Gorillib::Hashlike::HashlikeViaAccessors, :hashlike_spec => true do
|
15
15
|
|
16
16
|
before do
|
17
17
|
@hshlike = SimpleHashlikeViaAccessors.new.merge(HashlikeHelper::HASH_TO_TEST_HL_V_A.dup)
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'gorillib/hashlike'
|
3
3
|
require GORILLIB_ROOT_DIR('spec/support/hashlike_via_delegation')
|
4
4
|
require GORILLIB_ROOT_DIR('spec/support/hashlike_helper')
|
5
|
-
require GORILLIB_ROOT_DIR('spec/hashlike/hashlike_behavior_spec')
|
5
|
+
require GORILLIB_ROOT_DIR('spec/gorillib/hashlike/hashlike_behavior_spec')
|
6
6
|
|
7
7
|
|
8
8
|
|
@@ -10,7 +10,7 @@ require GORILLIB_ROOT_DIR('spec/hashlike/hashlike_behavior_spec')
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
describe Gorillib::Hashlike do
|
13
|
+
describe Gorillib::Hashlike, :hashlike_spec => true do
|
14
14
|
|
15
15
|
before do
|
16
16
|
@hshlike = InternalHash.new.merge(HashlikeHelper::BASE_HSH.dup)
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'gorillib/logger/log'
|
3
3
|
|
4
4
|
|
5
|
-
describe 'Logger' do
|
5
|
+
describe 'Logger', :simple_spec => true do
|
6
6
|
# so we can practice loading and unloading
|
7
7
|
def logger_code_file
|
8
8
|
GORILLIB_ROOT_DIR('lib/gorillib/logger/log.rb')
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'gorillib/metaprogramming/aliasing'
|
3
3
|
|
4
4
|
module BarMethodAliaser
|
@@ -32,7 +32,7 @@ module BarMethods
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
describe 'metaprogramming' do
|
35
|
+
describe 'metaprogramming', :metaprogramming_spec => true do
|
36
36
|
before do
|
37
37
|
Object.const_set :FooClassWithBarMethod, Class.new{ def bar() 'bar' end }
|
38
38
|
@instance = FooClassWithBarMethod.new
|
@@ -44,7 +44,7 @@ describe 'metaprogramming' do
|
|
44
44
|
|
45
45
|
describe 'alias_method_chain' do
|
46
46
|
|
47
|
-
it 'does not have an effect if already provided by another library.'
|
47
|
+
it 'does not have an effect if already provided by another library.' unless ENV['QUIET_RSPEC']
|
48
48
|
|
49
49
|
it 'creates a with_ and without_ method that chain' do
|
50
50
|
@instance.should respond_to(:bar)
|
@@ -1,14 +1,14 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'gorillib/metaprogramming/class_attribute'
|
3
3
|
|
4
|
-
describe 'metaprogramming' do
|
4
|
+
describe 'metaprogramming', :metaprogramming_spec => true do
|
5
5
|
describe 'class_attribute' do
|
6
6
|
before do
|
7
7
|
@klass = Class.new { class_attribute :setting }
|
8
8
|
@sub = Class.new(@klass)
|
9
9
|
end
|
10
10
|
|
11
|
-
it 'does not have an effect if already provided by another lib.'
|
11
|
+
it 'does not have an effect if already provided by another lib.' unless ENV['QUIET_RSPEC']
|
12
12
|
|
13
13
|
it 'defaults to nil' do
|
14
14
|
@klass.setting.should be_nil
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'gorillib/metaprogramming/delegation'
|
3
3
|
|
4
4
|
module One
|
@@ -63,13 +63,13 @@ end
|
|
63
63
|
#
|
64
64
|
# Tests start
|
65
65
|
|
66
|
-
describe 'metaprogramming' do
|
66
|
+
describe 'metaprogramming', :metaprogramming_spec => true do
|
67
67
|
describe 'delegation' do
|
68
68
|
before do
|
69
69
|
@david = Someone.new("David", Somewhere.new("Paulina", "Chicago"))
|
70
70
|
end
|
71
71
|
|
72
|
-
it 'does not have an effect if already provided by another library.'
|
72
|
+
it 'does not have an effect if already provided by another library.' unless ENV['QUIET_RSPEC']
|
73
73
|
|
74
74
|
it 'delegates to methods' do
|
75
75
|
@david.street.should == "Paulina"
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'gorillib/metaprogramming/singleton_class'
|
3
3
|
|
4
|
-
describe 'Singleton Class' do
|
4
|
+
describe 'Singleton Class', :metaprogramming_spec => true do
|
5
5
|
it 'returns the singleton class' do
|
6
6
|
o = Object.new
|
7
7
|
class << o; self end.should == o.singleton_class
|
8
8
|
end
|
9
9
|
|
10
|
-
it 'does not have an effect if already provided by another library.'
|
10
|
+
it 'does not have an effect if already provided by another library.' unless ENV['QUIET_RSPEC']
|
11
11
|
|
12
12
|
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'gorillib/model'
|
4
|
+
require 'gorillib/model/field'
|
5
|
+
require 'gorillib/model/defaults'
|
6
|
+
|
7
|
+
module Gorillib::Test ; end
|
8
|
+
module Meta::Gorillib::Test ; end
|
9
|
+
|
10
|
+
describe Gorillib::Model, :model_spec => true do
|
11
|
+
after(:each){ Gorillib::Test.nuke_constants ; Meta::Gorillib::Test.nuke_constants }
|
12
|
+
|
13
|
+
let(:car_class) do
|
14
|
+
class Gorillib::Test::Car
|
15
|
+
include Gorillib::Model
|
16
|
+
field :name, Symbol
|
17
|
+
field :make_model, String
|
18
|
+
field :year, Integer
|
19
|
+
field :style, Symbol, :default => :sedan
|
20
|
+
field :doors, Integer,
|
21
|
+
:default => ->{ [:coupe, :convertible].include?(style) ? 2 : 4 }
|
22
|
+
self
|
23
|
+
end
|
24
|
+
Gorillib::Test::Car
|
25
|
+
end
|
26
|
+
let(:wildcat) do
|
27
|
+
car_class.receive( :name => :wildcat, :make_model => 'Buick Wildcat', :year => 1968, :doors => 2 )
|
28
|
+
end
|
29
|
+
let(:ford_39) do
|
30
|
+
car_class.receive( :name => :ford_39 )
|
31
|
+
end
|
32
|
+
let(:year_field ){ car_class.fields[:year] }
|
33
|
+
let(:doors_field){ car_class.fields[:doors] }
|
34
|
+
let(:style_field){ car_class.fields[:style] }
|
35
|
+
|
36
|
+
describe 'Field#default' do
|
37
|
+
it 'is itself a field on Gorillib::Model::Field (boy that is confusing)' do
|
38
|
+
Gorillib::Model::Field.should have_field(:default)
|
39
|
+
end
|
40
|
+
context '#has_default?' do
|
41
|
+
it 'is true if the default is set' do
|
42
|
+
year_field.should_not have_default
|
43
|
+
year_field.default = '2012'
|
44
|
+
year_field.should have_default
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#attribute_default' do
|
50
|
+
before{ car_class.class_eval{ public :attribute_default } }
|
51
|
+
|
52
|
+
it "if the default does not exist, returns nil" do
|
53
|
+
ford_39.attribute_default(year_field).should be_nil
|
54
|
+
end
|
55
|
+
it "if the default is a value, returns it, dup'd if possible" do
|
56
|
+
ford_39.attribute_default(style_field).should == :sedan
|
57
|
+
year_val = mock ; dupd_year_val = mock
|
58
|
+
year_val.should_receive(:try_dup).and_return(dupd_year_val)
|
59
|
+
year_field.default = year_val
|
60
|
+
ford_39.attribute_default(year_field).should equal(dupd_year_val)
|
61
|
+
end
|
62
|
+
it "if the default is a proc with no args, instance_exec it" do
|
63
|
+
ford_39.style = :sedan
|
64
|
+
ford_39.attribute_default(doors_field).should == 4
|
65
|
+
ford_39.style = :coupe
|
66
|
+
ford_39.attribute_default(doors_field).should == 2
|
67
|
+
end
|
68
|
+
it "if the default is a proc with no args, instance_exec it" do
|
69
|
+
year_field.default = ->{ self }
|
70
|
+
ford_39.attribute_default(year_field).should equal(ford_39)
|
71
|
+
end
|
72
|
+
it "if the default responds_to #call, call it, passing the instance and field name" do
|
73
|
+
callable = mock ; expected = mock
|
74
|
+
year_field.default = callable
|
75
|
+
callable.should_receive(:respond_to?).with(:call).and_return(true)
|
76
|
+
callable.should_receive(:call).with(ford_39, :year).and_return(expected)
|
77
|
+
ford_39.stub(:read_unset_attribute).and_return('bob')
|
78
|
+
ford_39.attribute_default(year_field).should equal(expected)
|
79
|
+
end
|
80
|
+
it "if the default is a proc with args, call it in current context with the model and field name" do
|
81
|
+
this = self ; expected = mock
|
82
|
+
year_field.default = ->(inst, field_name){ [self, inst, field_name, expected] }
|
83
|
+
ford_39.attribute_default(year_field).should == [this, ford_39, :year, expected]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'reading an attribute with a default' do
|
88
|
+
it "sets the default value on the field and returns it" do
|
89
|
+
ford_39.attribute_set?(:doors).should be_false
|
90
|
+
ford_39.read_attribute(:doors).should == 4
|
91
|
+
end
|
92
|
+
it "only calls a block default if the attribute is unset" do
|
93
|
+
val = 0
|
94
|
+
year_field.default = ->{ val += 1 }
|
95
|
+
ford_39.read_attribute(:year).should == 1
|
96
|
+
year_field.default.call.should == 2 # the next call to the block will return 3
|
97
|
+
ford_39.read_attribute(:year).should == 1 # repeated calls give the same value
|
98
|
+
ford_39.unset_attribute(:year)
|
99
|
+
ford_39.read_attribute(:year).should == 3 # see! since it was unset, the block was called again.
|
100
|
+
end
|
101
|
+
it "is attribute_set? after" do
|
102
|
+
ford_39.attribute_set?(:doors).should be_false
|
103
|
+
ford_39.read_attribute(:doors)
|
104
|
+
ford_39.attribute_set?(:doors).should be_true
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|