diff options
| -rw-r--r-- | spec/models/faster_specs_spec.rb | 8 | ||||
| -rw-r--r-- | spec/support/faster/model_stubber.rb | 23 | ||||
| -rw-r--r-- | spec/support/faster/model_stubber/object_cache.rb | 4 |
3 files changed, 31 insertions, 4 deletions
diff --git a/spec/models/faster_specs_spec.rb b/spec/models/faster_specs_spec.rb index 31f31e0f8..edae5f485 100644 --- a/spec/models/faster_specs_spec.rb +++ b/spec/models/faster_specs_spec.rb @@ -1,6 +1,6 @@ RSpec.describe 'Faster Specs', type: :faster do - N = (ENV['N'] || 50).to_i + N = (ENV['N'] || 1).to_i shared_examples_for 'correct behavior' do @@ -28,7 +28,13 @@ RSpec.describe 'Faster Specs', type: :faster do let( :referential ){ stub_model( Referential, workbench: workbench ) } it_behaves_like 'correct behavior' + end + + context 'with FactoryGirl' do + let( :workbench ){ stub_model :workbench } + let( :referential ){ stub_model( :referential, workbench: workbench ) } + it_behaves_like 'correct behavior' end context 'meta' do diff --git a/spec/support/faster/model_stubber.rb b/spec/support/faster/model_stubber.rb index 789f5c2d2..3604c8ca4 100644 --- a/spec/support/faster/model_stubber.rb +++ b/spec/support/faster/model_stubber.rb @@ -1,15 +1,36 @@ require_relative 'model_stubber/implementation' module ModelStubber - def stub_model klass, **params + + def stub_model builder, **params + case builder + when Symbol + stub_model_with_fg builder, params + else + stub_model_with_ar builder, params + end + end + + private # symbolic as we are included + + def stub_model_with_ar klass, **params klass.new.tap do | model | Implementation.new(model, params).setup end end + + def stub_model_with_fg factory, **params + build(factory).tap do | model | + Implementation.new(model, params).setup + end + end end RSpec.configure do | conf | # Empty Helper's cache before each example or create a helper? conf.include ModelStubber, type: :faster + conf.before(:each, type: :faster) do + ModelStubber::ObjectCache.empty_cache! + end end diff --git a/spec/support/faster/model_stubber/object_cache.rb b/spec/support/faster/model_stubber/object_cache.rb index 5749be76f..8f24dcf71 100644 --- a/spec/support/faster/model_stubber/object_cache.rb +++ b/spec/support/faster/model_stubber/object_cache.rb @@ -7,13 +7,13 @@ module ModelStubber end def empty_cache! - @__cache__ = _cache + @__cache__ = _cache end private def cache - @__cache__ ||= _cache + @__cache__ ||= _cache end def _cache Hash.new { |h, k| h[k] = {} } |
