gorillib 0.1.11 → 0.4.0pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. data/.gitignore +1 -0
  2. data/.rspec +1 -2
  3. data/.yardopts +9 -0
  4. data/{CHANGELOG.textile → CHANGELOG.md} +35 -9
  5. data/Gemfile +21 -14
  6. data/Guardfile +19 -0
  7. data/{LICENSE.textile → LICENSE.md} +43 -29
  8. data/README.md +47 -52
  9. data/Rakefile +31 -30
  10. data/TODO.md +32 -0
  11. data/VERSION +1 -1
  12. data/examples/builder/ironfan.rb +133 -0
  13. data/examples/model/simple.rb +17 -0
  14. data/gorillib.gemspec +106 -86
  15. data/lib/alt/kernel/call_stack.rb +56 -0
  16. data/lib/gorillib/array/wrap.rb +53 -0
  17. data/lib/gorillib/base.rb +3 -3
  18. data/lib/gorillib/builder/field.rb +5 -0
  19. data/lib/gorillib/builder.rb +260 -0
  20. data/lib/gorillib/collection/has_collection.rb +31 -0
  21. data/lib/gorillib/collection.rb +129 -0
  22. data/lib/gorillib/configurable.rb +28 -0
  23. data/lib/gorillib/datetime/{flat.rb → to_flat.rb} +0 -0
  24. data/lib/gorillib/exception/confidence.rb +17 -0
  25. data/lib/gorillib/exception/raisers.rb +78 -0
  26. data/lib/gorillib/hash/mash.rb +202 -0
  27. data/lib/gorillib/hashlike/slice.rb +53 -19
  28. data/lib/gorillib/hashlike.rb +5 -3
  29. data/lib/gorillib/io/system_helpers.rb +30 -0
  30. data/lib/gorillib/logger/log.rb +18 -0
  31. data/lib/gorillib/metaprogramming/concern.rb +124 -0
  32. data/lib/gorillib/model/active_model_conversion.rb +68 -0
  33. data/lib/gorillib/model/active_model_naming.rb +87 -0
  34. data/lib/gorillib/model/active_model_shim.rb +33 -0
  35. data/lib/gorillib/model/base.rb +341 -0
  36. data/lib/gorillib/model/defaults.rb +71 -0
  37. data/lib/gorillib/model/errors.rb +14 -0
  38. data/lib/gorillib/model/factories.rb +372 -0
  39. data/lib/gorillib/model/field.rb +146 -0
  40. data/lib/gorillib/model/named_schema.rb +53 -0
  41. data/lib/gorillib/{struct/hashlike_iteration.rb → model/overlay.rb} +0 -0
  42. data/lib/gorillib/model/record_schema.rb +9 -0
  43. data/lib/gorillib/model/serialization.rb +23 -0
  44. data/lib/gorillib/model/validate.rb +22 -0
  45. data/lib/gorillib/model.rb +23 -0
  46. data/lib/gorillib/pathname.rb +78 -0
  47. data/lib/gorillib/{serialization.rb → serialization/to_wire.rb} +0 -0
  48. data/lib/gorillib/some.rb +11 -9
  49. data/lib/gorillib/string/constantize.rb +21 -14
  50. data/lib/gorillib/string/inflections.rb +6 -76
  51. data/lib/gorillib/string/inflector.rb +192 -0
  52. data/lib/gorillib/string/simple_inflector.rb +267 -0
  53. data/lib/gorillib/type/extended.rb +52 -0
  54. data/lib/gorillib/utils/capture_output.rb +28 -0
  55. data/lib/gorillib/utils/console.rb +131 -0
  56. data/lib/gorillib/utils/nuke_constants.rb +9 -0
  57. data/lib/gorillib/utils/stub_module.rb +33 -0
  58. data/spec/examples/builder/ironfan_spec.rb +37 -0
  59. data/spec/extlib/hash_spec.rb +64 -0
  60. data/spec/extlib/mash_spec.rb +312 -0
  61. data/spec/{array → gorillib/array}/compact_blank_spec.rb +2 -2
  62. data/spec/{array → gorillib/array}/extract_options_spec.rb +2 -2
  63. data/spec/gorillib/builder_spec.rb +187 -0
  64. data/spec/gorillib/collection_spec.rb +20 -0
  65. data/spec/gorillib/configurable_spec.rb +62 -0
  66. data/spec/{datetime → gorillib/datetime}/parse_spec.rb +3 -3
  67. data/spec/{datetime/flat_spec.rb → gorillib/datetime/to_flat_spec.rb} +4 -4
  68. data/spec/{enumerable → gorillib/enumerable}/sum_spec.rb +5 -5
  69. data/spec/gorillib/exception/raisers_spec.rb +60 -0
  70. data/spec/{hash → gorillib/hash}/compact_spec.rb +2 -2
  71. data/spec/{hash → gorillib/hash}/deep_compact_spec.rb +3 -3
  72. data/spec/{hash → gorillib/hash}/deep_merge_spec.rb +2 -2
  73. data/spec/{hash → gorillib/hash}/keys_spec.rb +2 -2
  74. data/spec/{hash → gorillib/hash}/reverse_merge_spec.rb +2 -2
  75. data/spec/{hash → gorillib/hash}/slice_spec.rb +2 -2
  76. data/spec/{hash → gorillib/hash}/zip_spec.rb +2 -2
  77. data/spec/{hashlike → gorillib/hashlike}/behave_same_as_hash_spec.rb +6 -3
  78. data/spec/{hashlike → gorillib/hashlike}/deep_hash_spec.rb +2 -2
  79. data/spec/{hashlike → gorillib/hashlike}/hashlike_behavior_spec.rb +32 -30
  80. data/spec/{hashlike → gorillib/hashlike}/hashlike_via_accessors_spec.rb +3 -3
  81. data/spec/{hashlike_spec.rb → gorillib/hashlike_spec.rb} +3 -3
  82. data/spec/{logger → gorillib/logger}/log_spec.rb +2 -2
  83. data/spec/{metaprogramming → gorillib/metaprogramming}/aliasing_spec.rb +3 -3
  84. data/spec/{metaprogramming → gorillib/metaprogramming}/class_attribute_spec.rb +3 -3
  85. data/spec/{metaprogramming → gorillib/metaprogramming}/delegation_spec.rb +3 -3
  86. data/spec/{metaprogramming → gorillib/metaprogramming}/singleton_class_spec.rb +3 -3
  87. data/spec/gorillib/model/record/defaults_spec.rb +108 -0
  88. data/spec/gorillib/model/record/factories_spec.rb +321 -0
  89. data/spec/gorillib/model/record/overlay_spec.rb +46 -0
  90. data/spec/gorillib/model/serialization_spec.rb +48 -0
  91. data/spec/gorillib/model_spec.rb +281 -0
  92. data/spec/{numeric → gorillib/numeric}/clamp_spec.rb +2 -2
  93. data/spec/{object → gorillib/object}/blank_spec.rb +2 -2
  94. data/spec/{object → gorillib/object}/try_dup_spec.rb +2 -2
  95. data/spec/{object → gorillib/object}/try_spec.rb +3 -2
  96. data/spec/gorillib/pathname_spec.rb +114 -0
  97. data/spec/{string → gorillib/string}/constantize_spec.rb +2 -2
  98. data/spec/{string → gorillib/string}/human_spec.rb +2 -2
  99. data/spec/{string → gorillib/string}/inflections_spec.rb +4 -3
  100. data/spec/{string → gorillib/string}/inflector_test_cases.rb +0 -0
  101. data/spec/{string → gorillib/string}/truncate_spec.rb +4 -10
  102. data/spec/gorillib/type/extended_spec.rb +120 -0
  103. data/spec/gorillib/utils/capture_output_spec.rb +71 -0
  104. data/spec/spec_helper.rb +8 -11
  105. data/spec/support/gorillib_test_helpers.rb +66 -0
  106. data/spec/support/hashlike_fuzzing_helper.rb +31 -33
  107. data/spec/support/hashlike_helper.rb +3 -3
  108. data/spec/support/model_test_helpers.rb +81 -0
  109. data/spec/support/shared_examples/included_module.rb +20 -0
  110. metadata +177 -158
  111. data/lib/gorillib/array/average.rb +0 -13
  112. data/lib/gorillib/array/sorted_median.rb +0 -11
  113. data/lib/gorillib/array/sorted_percentile.rb +0 -11
  114. data/lib/gorillib/array/sorted_sample.rb +0 -12
  115. data/lib/gorillib/dsl_object.rb +0 -64
  116. data/lib/gorillib/hash/indifferent_access.rb +0 -207
  117. data/lib/gorillib/hash/tree_merge.rb +0 -4
  118. data/lib/gorillib/hashlike/tree_merge.rb +0 -49
  119. data/lib/gorillib/metaprogramming/cattr_accessor.rb +0 -79
  120. data/lib/gorillib/metaprogramming/mattr_accessor.rb +0 -61
  121. data/lib/gorillib/receiver/active_model_shim.rb +0 -32
  122. data/lib/gorillib/receiver/acts_as_hash.rb +0 -195
  123. data/lib/gorillib/receiver/acts_as_loadable.rb +0 -42
  124. data/lib/gorillib/receiver/locale/en.yml +0 -27
  125. data/lib/gorillib/receiver/tree_diff.rb +0 -74
  126. data/lib/gorillib/receiver/validations.rb +0 -30
  127. data/lib/gorillib/receiver.rb +0 -402
  128. data/lib/gorillib/receiver_model.rb +0 -21
  129. data/lib/gorillib/struct/acts_as_hash.rb +0 -108
  130. data/notes/fancy_hashes_and_receivers.textile +0 -120
  131. data/notes/hash_rdocs.textile +0 -97
  132. data/spec/array/average_spec.rb +0 -24
  133. data/spec/array/sorted_median_spec.rb +0 -18
  134. data/spec/array/sorted_percentile_spec.rb +0 -24
  135. data/spec/array/sorted_sample_spec.rb +0 -28
  136. data/spec/dsl_object_spec.rb +0 -99
  137. data/spec/hash/indifferent_access_spec.rb +0 -391
  138. data/spec/metaprogramming/cattr_accessor_spec.rb +0 -43
  139. data/spec/metaprogramming/mattr_accessor_spec.rb +0 -45
  140. data/spec/receiver/acts_as_hash_spec.rb +0 -295
  141. data/spec/receiver_spec.rb +0 -551
  142. data/spec/struct/acts_as_hash_fuzz_spec.rb +0 -71
  143. 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
- Spork.prefork do # Must restart for changes to config / code from libraries loaded here
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
- RSpec.configure do |config|
16
- end
17
- end
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
- Spork.each_run do # This code will be run each time you run your specs.
20
- RSpec.configure do |config|
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
- old_stderr = $stderr
95
- $stderr = StringIO.new('', 'w')
96
- obj_1.should_receive(:warn){|str| stderr_output << str }.at_most(:once)
97
- begin
98
- expected = send_to(obj_1, method_to_test, input)
99
- rescue Exception => e
100
- expected = e
101
- end
102
- expected_stderr = $stderr.string
103
-
104
- $stderr = StringIO.new('', 'w')
105
- obj_1.should_receive(:warn){|str| stderr_output << str }.at_most(:once)
106
- case expected
107
- when Exception
108
- lambda{ send_to(obj_2, method_to_test, input) }.should raise_error(expected.class, err_regex(expected))
109
- when Enumerator
110
- actual = send_to(obj_2, method_to_test, input)
111
- actual.should be_a(Enumerator)
112
- actual.inspect.gsub(/[\"\:]/, '').gsub(/0x[a-f\d]+/,'').should == expected.inspect.gsub(/[\"\:]/, '').gsub(/0x[a-f\d]+/,'')
113
- else # run the method
114
- actual = send_to(obj_2, method_to_test, input)
115
- if expected.is_a?(Hash) && (RUBY_VERSION < '1.9')
116
- actual.should be_hash_eql(expected)
117
- elsif expected.is_a?(Array) && (RUBY_VERSION < '1.9')
118
- actual.should be_array_eql(expected)
119
- else
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
- # p Enumerable.public_instance_methods.map(&:to_sym) - ENUMERABLE_METHODS
73
- # p ENUMERABLE_METHODS - Enumerable.public_instance_methods.map(&:to_sym)
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