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
@@ -1,120 +0,0 @@
|
|
1
|
-
|
2
|
-
* gorillib/hashlike
|
3
|
-
* gorillib/hashlike/slice
|
4
|
-
* gorillib/hashlike/deep_dup
|
5
|
-
* gorillib/hashlike/
|
6
|
-
* gorillib/hashlike/hashlike_via_accessors
|
7
|
-
* gorillib/struct/acts_as_hash
|
8
|
-
* gorillib/struct/iterates_as_hash
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
h4. acts_as_hash
|
13
|
-
|
14
|
-
* []= associates key with value
|
15
|
-
* [] retrieves value associated with given key
|
16
|
-
* delete removes that key and its association
|
17
|
-
* keys enumeration of all keys having associations.
|
18
|
-
|
19
|
-
|
20
|
-
* check for compatibility/semantics of Enumerable
|
21
|
-
* has_key? true if an association exists for the given key.
|
22
|
-
|
23
|
-
h4. hashlike
|
24
|
-
|
25
|
-
Want chokepoints:
|
26
|
-
|
27
|
-
keys
|
28
|
-
- each, each_pair
|
29
|
-
- each_value
|
30
|
-
- reject!
|
31
|
-
- delete_if
|
32
|
-
- reject
|
33
|
-
- select!
|
34
|
-
- keep_if
|
35
|
-
- each_key
|
36
|
-
- key
|
37
|
-
- has_key?
|
38
|
-
- values_at
|
39
|
-
- length, size
|
40
|
-
- empty?
|
41
|
-
|
42
|
-
|
43
|
-
* each keys.each{|k| yield [k, self[k]] } ; self
|
44
|
-
|
45
|
-
* has_key? keys.include?(k)
|
46
|
-
* length keys.length
|
47
|
-
* size alias for length
|
48
|
-
* empty? keys.empty?
|
49
|
-
|
50
|
-
* each_pair alias for each
|
51
|
-
* each_key keys.each{|k| yield k }
|
52
|
-
* each_value each{|k,v| yield v }
|
53
|
-
* key keys.find{|k| self[k] == val }
|
54
|
-
* values_at in_keys.each{|k| self[k] if has_key?(k) }
|
55
|
-
* values [].tap{|arr| each{|k,v| arr << v } }
|
56
|
-
* to_hash {}.tap{|hsh| each{|k,v| hsh[k] = v } }
|
57
|
-
|
58
|
-
* has_value? keys.any?{|k| self[k] == val }
|
59
|
-
* value? alias for has_value?
|
60
|
-
* include? alias for has_key?
|
61
|
-
* key? alias for has_key?
|
62
|
-
* member? alias for has_key?
|
63
|
-
|
64
|
-
* update other_hash.each{|k,v| self[k] = (block_given? && has_key?(k) ? yield(k,v,self[k]) : v) }
|
65
|
-
* merge! update
|
66
|
-
* merge dup.merge!
|
67
|
-
|
68
|
-
* reject! chgd = false ; each{|k,v| if yield(k,v) then delete(k); chgd = true ; end } chgd ? self : nil
|
69
|
-
* select! chgd = false ; each{|k,v| if !yield(k,v) then delete(k); chgd = true ; end } chgd ? self : nil
|
70
|
-
* delete_if: reject! ; return self
|
71
|
-
* keep_if: select! ; return self
|
72
|
-
* reject: self.dup.delete_if
|
73
|
-
|
74
|
-
* fetch [] if has_key? else default else yield else raise KeyError
|
75
|
-
* clear each_key{|k| delete(k) }
|
76
|
-
|
77
|
-
* invert to_hash.invert
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
#all?, #any?, #chunk, #collect, #collect_concat, #count, #cycle, #detect,
|
82
|
-
#drop, #drop_while, #each_cons, #each_entry, #each_slice,
|
83
|
-
#each_with_index, #each_with_object, #entries, #find, #find_all,
|
84
|
-
#find_index, #first, #flat_map, #grep, #group_by, #inject, #map, #max,
|
85
|
-
#max_by, #min, #min_by, #minmax, #minmax_by, #none?, #one?, #partition,
|
86
|
-
#reduce, #reverse_each, #slice_before, #sort, #sort_by, #take,
|
87
|
-
#take_while, #zip
|
88
|
-
|
89
|
-
As opposed to hash, does *not* define
|
90
|
-
|
91
|
-
default, default=, default_proc, default_proc=,
|
92
|
-
replace, rehash, compare_by_identity compare_by_identity?,
|
93
|
-
shift, flatten,
|
94
|
-
|
95
|
-
h4. Configliere::DeepHash -- a magic hash
|
96
|
-
|
97
|
-
- only allows handles as keys (only things that can be turned into symbols are interesting)
|
98
|
-
- indifferent access
|
99
|
-
- deep access, via the dotted hash
|
100
|
-
|
101
|
-
* FancyHash
|
102
|
-
|
103
|
-
* *gorillib/hash/compact* compact, compact!, compact_blank, compact_blank!
|
104
|
-
* *gorrilib/hash/deep_compact* deep_compact, deep_compact!
|
105
|
-
* *gorrilib/hash/deep_merge* deep_merge, deep_merge!
|
106
|
-
* *gorillib/hash/keys* stringify_keys, stringify_keys!, symbolize_keys, symbolize_keys!, assert_valid_keys
|
107
|
-
* *gorillib/hash/reverse_merge* reverse_merge, reverse_merge!
|
108
|
-
* *gorillib/hash/tree_merge* tree_merge, tree_merge!
|
109
|
-
* *gorillib/hash/slice* slice, slice!, extract!
|
110
|
-
* *gorillib/hash/zip* Hash.zip
|
111
|
-
|
112
|
-
* Receiver
|
113
|
-
|
114
|
-
|
115
|
-
===========================================================================
|
116
|
-
===========================================================================
|
117
|
-
|
118
|
-
|
119
|
-
?> [ :store, :delete, :keys, :each, :each_key, :each_value, :has_key?, :include?, :key?, :member?, :has_value?, :value?, :fetch, :length, :empty?, :to_hash, :values, :values_at, :merge, :update, :key, :invert, :reject!, :select!, :delete_if, :keep_if, :reject, :clear, :assoc, :rassoc].each{|m| puts `ri 'Hash##{m}'` }
|
120
|
-
|
data/notes/hash_rdocs.textile
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
|
2
|
-
# == Hashlike ==
|
3
|
-
#
|
4
|
-
# == ActsAsHash ==
|
5
|
-
#
|
6
|
-
# Uses accessors and instance variables to provide
|
7
|
-
# * :[key] calls the getter <tt>send(key)</tt>
|
8
|
-
# * :[key]= val calls the setter <tt>send("key=", val)</tt>
|
9
|
-
# * :delete removes the instance variable, calls unset!
|
10
|
-
# * :keys all instance variables
|
11
|
-
#
|
12
|
-
# == Hashlike::Slice ==
|
13
|
-
# == Hashlike::Keys ==
|
14
|
-
# == Hashlike::Compact ==
|
15
|
-
# == Hashlike::DeepCompact ==
|
16
|
-
# == Hashlike::DeepMerge ==
|
17
|
-
# == Hashlike::TreeMerge ==
|
18
|
-
# == Hashlike::ReverseMerge ==
|
19
|
-
# == Hashlike::Zip ==
|
20
|
-
# == Hashlike::DeepKeys ==
|
21
|
-
|
22
|
-
|
23
|
-
# Hashlike#each
|
24
|
-
|
25
|
-
|
26
|
-
# Hashlike#each_key
|
27
|
-
|
28
|
-
|
29
|
-
# Hashlike#each_value
|
30
|
-
|
31
|
-
|
32
|
-
# Hashlike#has_key?
|
33
|
-
|
34
|
-
|
35
|
-
# Hashlike#include?
|
36
|
-
# Hashlike#key?
|
37
|
-
# Hashlike#member?
|
38
|
-
|
39
|
-
# Hashlike#has_value?
|
40
|
-
# Hashlike#value?
|
41
|
-
|
42
|
-
|
43
|
-
# Hashlike#fetch
|
44
|
-
|
45
|
-
|
46
|
-
# Hashlike#length
|
47
|
-
|
48
|
-
|
49
|
-
# Hashlike#empty?
|
50
|
-
|
51
|
-
|
52
|
-
# Hashlike#to_hash
|
53
|
-
|
54
|
-
|
55
|
-
# Hashlike#values
|
56
|
-
|
57
|
-
|
58
|
-
# Hashlike#values_at
|
59
|
-
|
60
|
-
|
61
|
-
# Hashlike#key
|
62
|
-
|
63
|
-
|
64
|
-
# Hashlike#invert
|
65
|
-
|
66
|
-
|
67
|
-
# Hashlike#delete_if
|
68
|
-
|
69
|
-
|
70
|
-
# Hashlike#reject!
|
71
|
-
|
72
|
-
|
73
|
-
# Hashlike#reject
|
74
|
-
|
75
|
-
|
76
|
-
# Hashlike#keep_if
|
77
|
-
|
78
|
-
|
79
|
-
# Hashlike#select!
|
80
|
-
|
81
|
-
|
82
|
-
# Hashlike#clear
|
83
|
-
|
84
|
-
|
85
|
-
# Hashlike#assoc
|
86
|
-
|
87
|
-
|
88
|
-
# Hashlike#rassoc
|
89
|
-
|
90
|
-
|
91
|
-
# Hashlike#flatten
|
92
|
-
|
93
|
-
|
94
|
-
# Hashlike#update
|
95
|
-
|
96
|
-
|
97
|
-
# Hashlike#merge
|
data/spec/array/average_spec.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
2
|
-
require 'gorillib/array/average'
|
3
|
-
|
4
|
-
describe Array do
|
5
|
-
describe '#average' do
|
6
|
-
context 'on non-float array element' do
|
7
|
-
it 'raises error' do
|
8
|
-
expect { [0.0, :b, 1.0].average }.should raise_error(ArgumentError)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'with empty' do
|
13
|
-
it 'returns nil' do
|
14
|
-
[].average.should be_nil
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'given a numerical array' do
|
19
|
-
it 'returns the average of the elements' do
|
20
|
-
(1..10).to_a.average.should == 5.5
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
2
|
-
require 'gorillib/array/sorted_median'
|
3
|
-
|
4
|
-
describe Array do
|
5
|
-
describe '#sorted_median' do
|
6
|
-
context 'with empty' do
|
7
|
-
it 'returns nil' do
|
8
|
-
[].sorted_median.should be_nil
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'given any array' do
|
13
|
-
it 'returns the middle element of odd-sized arrays' do
|
14
|
-
("a".."y").to_a.sorted_median.should == "m"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
2
|
-
require 'gorillib/array/sorted_percentile'
|
3
|
-
|
4
|
-
describe Array do
|
5
|
-
describe '#sorted_percentile' do
|
6
|
-
context 'with empty' do
|
7
|
-
it 'returns nil' do
|
8
|
-
[].sorted_percentile(0.0).should be_nil
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'given any array' do
|
13
|
-
it 'returns the element closest to the given percentile' do
|
14
|
-
("a".."y").to_a.sorted_percentile( 0.0).should == "a"
|
15
|
-
("a".."y").to_a.sorted_percentile( 50.0).should == "m"
|
16
|
-
("a".."y").to_a.sorted_percentile(100.0).should == "y"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
# (Please do not define behavior for two elements equally close to
|
21
|
-
# a given percentile.)
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
2
|
-
require 'gorillib/array/sorted_sample'
|
3
|
-
|
4
|
-
describe Array do
|
5
|
-
describe '#sorted_median' do
|
6
|
-
context 'with empty' do
|
7
|
-
it 'returns an empty array' do
|
8
|
-
[].sorted_sample(1).should be_empty
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'given an undersized array' do
|
13
|
-
it 'does not return the same element more than once' do
|
14
|
-
("a".."z").to_a.sorted_sample(27).should == ("a".."z").to_a
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'given any array' do
|
19
|
-
it ('returns a sample of the given size as close to evenly ' \
|
20
|
-
'distributed over the array as possible') do
|
21
|
-
sample = (1..100).to_a.sorted_sample(26)
|
22
|
-
deltas = sample[0..-2].zip(sample[1..-1]).map{|a,b| b-a}
|
23
|
-
deltas.max.should <= 4
|
24
|
-
deltas.min.should >= 3
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/spec/dsl_object_spec.rb
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'gorillib/dsl_object'
|
3
|
-
|
4
|
-
|
5
|
-
describe DslObject do
|
6
|
-
let(:test_property) { :yo_momma }
|
7
|
-
let(:attrs) { { test_property => "is so fat" } }
|
8
|
-
|
9
|
-
after(:each) do
|
10
|
-
DslObject.send(:remove_method, test_property) if DslObject.method_defined? test_property
|
11
|
-
DslObject.properties = {}
|
12
|
-
end
|
13
|
-
|
14
|
-
context DslObject, ".new" do
|
15
|
-
subject { DslObject.new(attrs) }
|
16
|
-
|
17
|
-
it "transforms an attribute hash given as a constructor argument into properties" do
|
18
|
-
subject.to_hash.should include attrs
|
19
|
-
subject.should respond_to test_property
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context DslObject, ".property" do
|
24
|
-
subject { DslObject.new(attrs) }
|
25
|
-
|
26
|
-
it "defines a method on a DslObject instance" do
|
27
|
-
DslObject.property(test_property)
|
28
|
-
subject.should respond_to test_property
|
29
|
-
end
|
30
|
-
|
31
|
-
it "allows a default return value to be established for a property" do
|
32
|
-
DslObject.property(test_property, :default => "is so fat")
|
33
|
-
subject.send(test_property).should == "is so fat"
|
34
|
-
end
|
35
|
-
|
36
|
-
let(:existing_method) { :class }
|
37
|
-
it "does not allow a property to override an existing method" do
|
38
|
-
DslObject.property(existing_method, :default => "override")
|
39
|
-
subject.send(existing_method).should_not == "override"
|
40
|
-
subject.should_not be_instance_variable_defined("@" + existing_method.to_s)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context DslObject, "#configure" do
|
45
|
-
let(:dsl_object) { DslObject.new }
|
46
|
-
subject { double :context_obj, :delegate => dsl_object }
|
47
|
-
|
48
|
-
it "delegates the configure block to the DslObject instance" do
|
49
|
-
dsl_object.should_receive(test_property)
|
50
|
-
subject.should_not_receive(test_property)
|
51
|
-
subject.delegate.configure { yo_momma "is so fat" }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context DslObject, "#to_s" do
|
56
|
-
subject { DslObject.new(attrs) }
|
57
|
-
|
58
|
-
it "prints to the screen with its class name and properties" do
|
59
|
-
subject.to_s.should =~ /#{subject.class}.*#{attrs}/
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context DslObject, "#set" do
|
64
|
-
subject { DslObject.new(attrs) }
|
65
|
-
|
66
|
-
it "sets a property correctly" do
|
67
|
-
subject.set(test_property, "is so dumb")
|
68
|
-
subject.to_hash.should include(test_property => "is so dumb" )
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context DslObject, "#get" do
|
73
|
-
subject { DslObject.new(attrs) }
|
74
|
-
|
75
|
-
it "returns a property correctly" do
|
76
|
-
subject.get(test_property).should == "is so fat"
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context DslObject, "#set?" do
|
81
|
-
subject { DslObject.new(attrs) }
|
82
|
-
|
83
|
-
it "correctly determines if a property is set" do
|
84
|
-
subject.set?(test_property).should be_true
|
85
|
-
subject.set?(:not_set).should be_false
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context DslObject, "#unset!" do
|
90
|
-
subject { DslObject.new(attrs) }
|
91
|
-
|
92
|
-
it "unsets a property" do
|
93
|
-
subject.unset!(test_property)
|
94
|
-
subject.set?(test_property).should be_false
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
|