From c5e5e5bf1a7429dfa72bbd2f3d48eec7cac442a6 Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 23 Oct 2017 10:12:14 +0200 Subject: Faster Spex. By using FactoryGirls's build strategy :build in associations the time penalty of using FactoryGirl instead of ActiveRecord stubs is down to a factor < 2. --- spec/factories/referentials.rb | 21 ++++++++++++++++----- spec/factories/workbenches.rb | 9 +++++++++ spec/models/faster_specs_spec.rb | 11 ++++++++--- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/spec/factories/referentials.rb b/spec/factories/referentials.rb index 5348ad96b..249d5831f 100644 --- a/spec/factories/referentials.rb +++ b/spec/factories/referentials.rb @@ -1,13 +1,24 @@ FactoryGirl.define do - factory :referential do + factory :abstract_referential, class: Referential do sequence(:name) { |n| "Test #{n}" } sequence(:slug) { |n| "test_#{n}" } sequence(:prefix) { |n| "test_#{n}" } - association :organisation - association :workbench - association :line_referential - association :stop_area_referential + time_zone "Europe/Paris" ready { true } + + factory :referential do + association :organisation + association :workbench + association :line_referential + association :stop_area_referential + end + + factory :fast_referential do + association :organisation, strategy: :build + association :workbench, strategy: :build + association :line_referential, strategy: :build + association :stop_area_referential, strategy: :build + end end end diff --git a/spec/factories/workbenches.rb b/spec/factories/workbenches.rb index 57bef2203..2e80b2869 100644 --- a/spec/factories/workbenches.rb +++ b/spec/factories/workbenches.rb @@ -7,4 +7,13 @@ FactoryGirl.define do association :stop_area_referential association :output, factory: :referential_suite end + + factory :fast_workbench, class: Workbench do + name "Fast Workbench" + + association :organisation, strategy: :build + association :line_referential, strategy: :build + association :stop_area_referential, strategy: :build + association :output, factory: :referential_suite, strategy: :build + end end diff --git a/spec/models/faster_specs_spec.rb b/spec/models/faster_specs_spec.rb index 5581eb076..1037e4487 100644 --- a/spec/models/faster_specs_spec.rb +++ b/spec/models/faster_specs_spec.rb @@ -31,8 +31,8 @@ RSpec.describe 'Faster Specs', type: :faster do end context 'with FactoryGirl' do - let( :workbench ){ stub_model :workbench } - let( :referential ){ stub_model( :referential, workbench: workbench ) } + let( :workbench ){ stub_model :fast_workbench } + let( :referential ){ stub_model( :fast_referential, workbench: workbench ) } it_behaves_like 'correct behavior' end @@ -68,9 +68,14 @@ RSpec.describe 'Faster Specs', type: :faster do end context 'FactoryGirlMeta' do - let( :workbench ){ stub_model :workbench } + let( :workbench ){ stub_model :fast_workbench } it_behaves_like 'meta', :organisation + it 'check for associations in FactoryGirl' do + require 'pry'; binding.pry + + end + end end -- cgit v1.2.3