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,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gorillib/utils/capture_output'
|
3
|
+
|
4
|
+
describe Gorillib::TestHelpers, :simple_spec => true do
|
5
|
+
|
6
|
+
context '.capture_output' do
|
7
|
+
let(:mock_stdout){ StringIO.new('', 'w') }
|
8
|
+
let(:mock_stderr){ StringIO.new('', 'w') }
|
9
|
+
|
10
|
+
before do
|
11
|
+
mock_stderr ; mock_stdout
|
12
|
+
StringIO.should_receive(:new).and_return(mock_stdout)
|
13
|
+
StringIO.should_receive(:new).and_return(mock_stderr)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'gives me a new $stdout and $stderr' do
|
17
|
+
Gorillib::TestHelpers.capture_output do
|
18
|
+
$stdout.should equal(mock_stdout)
|
19
|
+
$stderr.should equal(mock_stderr)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'yields a wrapped block' do
|
24
|
+
i_wuz_here = nil
|
25
|
+
Gorillib::TestHelpers.capture_output do
|
26
|
+
i_wuz_here = true
|
27
|
+
end
|
28
|
+
i_wuz_here.should == true
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'restores the original values' do
|
32
|
+
old_stdout = $stdout ; old_stderr = $stderr
|
33
|
+
Gorillib::TestHelpers.capture_output do
|
34
|
+
$stdout.should equal(mock_stdout)
|
35
|
+
$stderr.should equal(mock_stderr)
|
36
|
+
end
|
37
|
+
$stdout.should equal(old_stdout)
|
38
|
+
$stderr.should equal(old_stderr)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'restores the original values even if there is an error' do
|
42
|
+
old_stdout = $stdout ; old_stderr = $stderr
|
43
|
+
Gorillib::TestHelpers.capture_output do
|
44
|
+
raise 'hell'
|
45
|
+
end rescue nil
|
46
|
+
$stdout.should equal(old_stdout)
|
47
|
+
$stderr.should equal(old_stderr)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'returns the captured streams' do
|
51
|
+
returned_stdout, returned_stderr = Gorillib::TestHelpers.capture_output do
|
52
|
+
$stdout.puts 'I was here'
|
53
|
+
$stderr.puts 'so was I'
|
54
|
+
end
|
55
|
+
returned_stdout.should equal(mock_stdout)
|
56
|
+
returned_stderr.should equal(mock_stderr)
|
57
|
+
mock_stdout.string.should == "I was here\n"
|
58
|
+
mock_stderr.string.should == "so was I\n"
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'raises an error if no block is given' do
|
62
|
+
lambda{ Gorillib::TestHelpers.capture_output }.should raise_error(LocalJumpError, "no block given (yield)")
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
context '.quiet_output' do
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'rubygems' unless defined?(Gem)
|
2
|
-
require 'spork'
|
3
2
|
require 'rspec'
|
4
3
|
|
5
4
|
GORILLIB_ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__),'..'))
|
@@ -7,16 +6,14 @@ def GORILLIB_ROOT_DIR *paths
|
|
7
6
|
File.join(::GORILLIB_ROOT_DIR, *paths)
|
8
7
|
end
|
9
8
|
|
10
|
-
|
11
|
-
$LOAD_PATH.unshift(GORILLIB_ROOT_DIR('lib'))
|
12
|
-
$LOAD_PATH.unshift(GORILLIB_ROOT_DIR('spec/support'))
|
13
|
-
Dir[GORILLIB_ROOT_DIR('spec/support/matchers/*.rb')].each {|f| require f}
|
9
|
+
ENV['QUIET_RSPEC'] = 'please'
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
$LOAD_PATH.unshift(GORILLIB_ROOT_DIR('lib'))
|
12
|
+
$LOAD_PATH.unshift(GORILLIB_ROOT_DIR('spec/support'))
|
13
|
+
require 'gorillib_test_helpers'
|
14
|
+
Dir[GORILLIB_ROOT_DIR('spec/support/matchers/*.rb')].each {|f| require f}
|
15
|
+
Dir[GORILLIB_ROOT_DIR('spec/support/shared_examples/*.rb')].each {|f| require f}
|
18
16
|
|
19
|
-
|
20
|
-
|
21
|
-
end
|
17
|
+
RSpec.configure do |config|
|
18
|
+
include Gorillib::TestHelpers
|
22
19
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'gorillib/utils/capture_output'
|
2
|
+
require 'gorillib/utils/nuke_constants'
|
3
|
+
|
4
|
+
shared_examples_for "a model field" do |field_name|
|
5
|
+
it('gives the model a field'){ subject.class.should have_field(field_name) }
|
6
|
+
|
7
|
+
context '#read_attribute' do
|
8
|
+
it "if set, returns the value" do
|
9
|
+
subject.write_attribute(field_name, sample_val)
|
10
|
+
subject.read_attribute(field_name).should == sample_val
|
11
|
+
end
|
12
|
+
it "if unset, calls #read_unset_attribute" do
|
13
|
+
mock_val = mock
|
14
|
+
subject.should_receive(:read_unset_attribute).with(field_name).and_return(mock_val)
|
15
|
+
subject.read_attribute(field_name).should == mock_val
|
16
|
+
end
|
17
|
+
it "raises an error if the field does not exist" do
|
18
|
+
->{ subject.read_attribute(:fnord) }.should raise_error(Gorillib::Model::UnknownFieldError, /unknown field: fnord/)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context '#write_attribute' do
|
23
|
+
it('sets the value') do
|
24
|
+
subject.write_attribute(field_name, sample_val)
|
25
|
+
subject.read_attribute(field_name).should == sample_val
|
26
|
+
end
|
27
|
+
it('returns the new value') do
|
28
|
+
subject.write_attribute(field_name, sample_val).should == sample_val
|
29
|
+
end
|
30
|
+
it "raises an error if the field does not exist" do
|
31
|
+
->{ subject.write_attribute(:fnord, 8) }.should raise_error(Gorillib::Model::UnknownFieldError, /unknown field: fnord/)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context '#attribute_set?' do
|
36
|
+
it('is true if the attribute has been set') do
|
37
|
+
subject.write_attribute(field_name, sample_val)
|
38
|
+
subject.attribute_set?(field_name).should be_true
|
39
|
+
end
|
40
|
+
it('is true if the attribute has been set, even to nil or false') do
|
41
|
+
subject.write_attribute(field_name, nil)
|
42
|
+
subject.attribute_set?(field_name).should be_true
|
43
|
+
end
|
44
|
+
it('is false if never written') do
|
45
|
+
subject.attribute_set?(field_name).should be_false
|
46
|
+
end
|
47
|
+
it "raises an error if the field does not exist" do
|
48
|
+
->{ subject.attribute_set?(:fnord) }.should raise_error(Gorillib::Model::UnknownFieldError, /unknown field: fnord/)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "#receive_XX" do
|
53
|
+
it('returns the model itself') do
|
54
|
+
subject.send("receive_#{field_name}", raw_val).should == subject
|
55
|
+
end
|
56
|
+
it('type-converts the object') do
|
57
|
+
subject.send("receive_#{field_name}", raw_val)
|
58
|
+
subject.read_attribute(field_name).should == sample_val
|
59
|
+
subject.read_attribute(field_name).should_not equal(sample_val)
|
60
|
+
end
|
61
|
+
it('uses a compatible object directly') do
|
62
|
+
subject.send("receive_#{field_name}", sample_val)
|
63
|
+
subject.read_attribute(field_name).should equal(sample_val)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -3,7 +3,7 @@ require 'stringio'
|
|
3
3
|
::Enumerator = Enumerable::Enumerator if (RUBY_VERSION < '1.9') && (not defined?(::Enumerator))
|
4
4
|
|
5
5
|
module HashlikeFuzzingHelper
|
6
|
-
|
6
|
+
|
7
7
|
#
|
8
8
|
# Fuzz testing for hashlike behavior. This throws a whole bunch of
|
9
9
|
#
|
@@ -51,9 +51,9 @@ module HashlikeFuzzingHelper
|
|
51
51
|
['a', 'b', 'z'], ['a', 'b', 'a', :c, 'a'],
|
52
52
|
[[1, 2, [3, 4]]], [[1, [2, 3, [4, 5, 6]]]]
|
53
53
|
]
|
54
|
-
|
54
|
+
|
55
55
|
INPUTS_WHEN_FULLY_HASHLIKE = INPUTS_FOR_ALL_HASHLIKES + INPUTS_WHEN_ARBITRARY_KEYS_ALLOWED + INPUTS_WHEN_INDIFFERENT_ACCESS
|
56
|
-
|
56
|
+
|
57
57
|
#
|
58
58
|
# Hacky methods to do comparison
|
59
59
|
#
|
@@ -90,38 +90,36 @@ module HashlikeFuzzingHelper
|
|
90
90
|
input.last.is_a?(Proc) && (input.last.arity == 1))
|
91
91
|
return
|
92
92
|
end
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
actual.should == expected
|
93
|
+
|
94
|
+
quiet_output do
|
95
|
+
obj_1.should_receive(:warn){|str| stderr_output << str }.at_most(:once)
|
96
|
+
begin
|
97
|
+
expected = send_to(obj_1, method_to_test, input)
|
98
|
+
rescue Exception => e
|
99
|
+
expected = e
|
100
|
+
end
|
101
|
+
expected_stderr = $stderr.string
|
102
|
+
|
103
|
+
obj_1.should_receive(:warn){|str| stderr_output << str }.at_most(:once)
|
104
|
+
case expected
|
105
|
+
when Exception
|
106
|
+
lambda{ send_to(obj_2, method_to_test, input) }.should raise_error(expected.class, err_regex(expected))
|
107
|
+
when Enumerator
|
108
|
+
actual = send_to(obj_2, method_to_test, input)
|
109
|
+
actual.should be_a(Enumerator)
|
110
|
+
actual.inspect.gsub(/[\"\:]/, '').gsub(/0x[a-f\d]+/,'').should == expected.inspect.gsub(/[\"\:]/, '').gsub(/0x[a-f\d]+/,'')
|
111
|
+
else # run the method
|
112
|
+
actual = send_to(obj_2, method_to_test, input)
|
113
|
+
if expected.is_a?(Hash) && (RUBY_VERSION < '1.9')
|
114
|
+
actual.should be_hash_eql(expected)
|
115
|
+
elsif expected.is_a?(Array) && (RUBY_VERSION < '1.9')
|
116
|
+
actual.should be_array_eql(expected)
|
117
|
+
else
|
118
|
+
actual.should == expected
|
119
|
+
end
|
121
120
|
end
|
121
|
+
$stderr.string.sub(/.*\.rb:\d+:(?:in `send\w*':)? /, '').should == expected_stderr.sub(/.*\.rb:\d+:(?:in `send\w*':)? /, '')
|
122
122
|
end
|
123
|
-
$stderr.string.sub(/.*\.rb:\d+:(?:in `send\w*':)? /, '').should == expected_stderr.sub(/.*\.rb:\d+:(?:in `send\w*':)? /, '')
|
124
|
-
$stderr = old_stderr
|
125
123
|
end
|
126
124
|
|
127
125
|
end
|
@@ -55,7 +55,7 @@ module HashlikeHelper
|
|
55
55
|
:nested_under_indifferent_access,
|
56
56
|
:stringify_keys, :stringify_keys!, :symbolize_keys, :symbolize_keys!,
|
57
57
|
:with_indifferent_access, :yaml_initialize,
|
58
|
-
:extractable_options?, :deep_dup, :reverse_merge, :reverse_merge!, :slice, :slice!, :extract!, :deep_merge, :deep_merge!, :deep_compact!, :compact, :compact!, :compact_blank, :compact_blank!
|
58
|
+
:extractable_options?, :deep_dup, :reverse_merge, :reverse_merge!, :slice, :slice!, :extract!, :except, :except!, :only, :only!, :deep_merge, :deep_merge!, :deep_compact!, :compact, :compact!, :compact_blank, :compact_blank!
|
59
59
|
]
|
60
60
|
FANCY_HASHLIKE_METHODS.each{|meth| OMITTED_METHODS_FROM_HASH << meth }
|
61
61
|
|
@@ -69,8 +69,8 @@ module HashlikeHelper
|
|
69
69
|
# :cycle, :partition,
|
70
70
|
# ]
|
71
71
|
#
|
72
|
-
#
|
73
|
-
#
|
72
|
+
# Enumerable.public_instance_methods.map(&:to_sym) - ENUMERABLE_METHODS
|
73
|
+
# ENUMERABLE_METHODS - Enumerable.public_instance_methods.map(&:to_sym)
|
74
74
|
# extra: [:member?, :enum_slice, :reject, :select, :include?, :enum_cons, :enum_with_index]
|
75
75
|
# missing: [:each_entry, :each_with_object, :collect_concat, :flat_map, :chunk, :slice_before]
|
76
76
|
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Gorillib ; module Test ; end ; end
|
2
|
+
module Meta ; module Gorillib ; module Test ; end ; end ; end
|
3
|
+
|
4
|
+
shared_context 'model', :model_spec => true do
|
5
|
+
after(:each){ Gorillib::Test.nuke_constants ; Meta::Gorillib::Test.nuke_constants }
|
6
|
+
|
7
|
+
let(:smurf_klass) do
|
8
|
+
class Gorillib::Test::Smurf
|
9
|
+
include Gorillib::Model
|
10
|
+
|
11
|
+
field :smurfiness, Integer
|
12
|
+
field :weapon, Symbol
|
13
|
+
end
|
14
|
+
Gorillib::Test::Smurf
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:smurfette_klass) do
|
18
|
+
class Gorillib::Test::Smurfette < smurf_klass
|
19
|
+
field :blondness, Boolean
|
20
|
+
end
|
21
|
+
Gorillib::Test::Smurfette
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:poppa_smurf ){ smurf_klass.receive(:name => 'Poppa Smurf', :smurfiness => 9, :weapon => 'staff') }
|
25
|
+
let(:smurfette ){ smurf_klass.receive(:name => 'Smurfette', :smurfiness => 11, :weapon => 'charm') }
|
26
|
+
let(:generic_smurf){ smurf_klass.receive(:name => 'Generic Smurf', :smurfiness => 2, :weapon => 'fists') }
|
27
|
+
|
28
|
+
let(:engine_class) do
|
29
|
+
class Gorillib::Test::Engine
|
30
|
+
include Gorillib::Builder
|
31
|
+
field :name, Symbol, :default => ->{ "#{owner? ? owner.name : ''} engine"}
|
32
|
+
field :carburetor, Symbol, :default => :stock
|
33
|
+
field :volume, Integer, :doc => 'displacement volume, in in^3'
|
34
|
+
field :cylinders, Integer
|
35
|
+
member :owner, Whatever
|
36
|
+
self
|
37
|
+
end
|
38
|
+
Gorillib::Test::Engine
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:car_class) do
|
42
|
+
engine_class
|
43
|
+
class Gorillib::Test::Car
|
44
|
+
include Gorillib::Builder
|
45
|
+
field :name, Symbol
|
46
|
+
field :make_model, String
|
47
|
+
field :year, Integer
|
48
|
+
field :doors, Integer
|
49
|
+
member :engine, Gorillib::Test::Engine
|
50
|
+
self
|
51
|
+
end
|
52
|
+
Gorillib::Test::Car
|
53
|
+
end
|
54
|
+
|
55
|
+
let(:garage_class) do
|
56
|
+
car_class
|
57
|
+
class Gorillib::Test::Garage
|
58
|
+
include Gorillib::Builder
|
59
|
+
collection :cars, Gorillib::Test::Car
|
60
|
+
self
|
61
|
+
end
|
62
|
+
Gorillib::Test::Garage
|
63
|
+
end
|
64
|
+
|
65
|
+
let(:wildcat) do
|
66
|
+
car_class.receive( :name => :wildcat,
|
67
|
+
:make_model => 'Buick Wildcat', :year => 1968, :doors => 2,
|
68
|
+
:engine => { :volume => 455, :cylinders => 8 } )
|
69
|
+
end
|
70
|
+
let(:ford_39) do
|
71
|
+
car_class.receive( :name => :ford_39,
|
72
|
+
:make_model => 'Ford Tudor Sedan', :year => 1939, :doors => 2, )
|
73
|
+
end
|
74
|
+
let(:garage) do
|
75
|
+
garage_class.new
|
76
|
+
end
|
77
|
+
let(:example_engine) do
|
78
|
+
engine_class.new( :name => 'Geo Metro 1.0L', :volume => 61, :cylinders => 3 )
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
shared_context 'included_module' do
|
2
|
+
|
3
|
+
let(:included_module) { described_class }
|
4
|
+
let(:klass_name) { 'FakeModel' }
|
5
|
+
|
6
|
+
def create_fake_model_klass name
|
7
|
+
klass = self.class.const_set(name.to_sym, Class.new)
|
8
|
+
mod = included_module
|
9
|
+
klass.class_eval{ include(mod) }
|
10
|
+
klass
|
11
|
+
end
|
12
|
+
|
13
|
+
def remove_fake_model_klass name
|
14
|
+
self.class.send(:remove_const, name.to_sym) if self.class.const_defined? name.to_sym
|
15
|
+
end
|
16
|
+
|
17
|
+
subject { create_fake_model_klass(klass_name) }
|
18
|
+
after(:each) { remove_fake_model_klass(klass_name) }
|
19
|
+
|
20
|
+
end
|