# encoding: utf-8 # Rspecの内部でflextures関数を使える様にする module RSpec module Core module Hooks def flextures *_ before { Flextures::Loader::flextures *_ } end end end module Rails module FlextureSupport @@configs={ load_count: 0 } def self.included(m) # 一番外側のdescribeにだけ追加 #m.after { Flextures::init_tables } if @@configs[:load_count]==0 @@configs[:load_count] += 1 end end end RSpec.configure do |c| c.include RSpec::Rails::FlextureSupport end end # 既存のsetup_fixturesの機能を上書きする必要があったのでこちらを作成 module ActiveRecord module TestFixtures @@flextures_config = { count: 0 } alias :flextures_backup_setup_fixtures :setup_fixtures def setup_fixtures Flextures::init_load Flextures::init_tables if @@flextures_config[:count] == 0 @@flextures_config[:count] += 1 flextures_backup_setup_fixtures end alias :flextures_backup_teardown_fixtures :teardown_fixtures def teardown_fixtures Flextures::init_tables if Flextures::Config.init_all_tables flextures_backup_teardown_fixtures end end end