Module: GollyUtils::Testing::DynamicFixtures
- Extended by:
- ClassMethods
- Defined in:
- lib/golly-utils/testing/dynamic_fixtures.rb
Overview
Provides globally-shared, cached, lazily-loaded fixtures that are generated once on-demand, and copied when access is required.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#after_dynamic_fixture_creation(name, creation_time_in_sec) ⇒ void
Callback invoked just after creating a dynamic fixture for the first time.
-
#before_dynamic_fixture_creation(name) ⇒ void
Callback invoked just before creating a dynamic fixture for the first time.
-
#copy_dynamic_fixture(name, target_dir = '.') ⇒ void
Copies the contents of a dynamic fixture to a given directory.
-
#inside_dynamic_fixture(name, options = {}) { ... } ⇒ Object
Creates a clean copy of a predefined dynamic fixture, changes directory into it and yields.
Methods included from ClassMethods
def_fixture, run_all_in_dynamic_fixture, run_each_in_dynamic_fixture
Instance Method Details
#after_dynamic_fixture_creation(name, creation_time_in_sec) ⇒ void
This method returns an undefined value.
Callback invoked just after creating a dynamic fixture for the first time.
Override to customise.
138 139 |
# File 'lib/golly-utils/testing/dynamic_fixtures.rb', line 138 def after_dynamic_fixture_creation(name, creation_time_in_sec) end |
#before_dynamic_fixture_creation(name) ⇒ void
This method returns an undefined value.
Callback invoked just before creating a dynamic fixture for the first time.
Override to customise.
128 129 |
# File 'lib/golly-utils/testing/dynamic_fixtures.rb', line 128 def before_dynamic_fixture_creation(name) end |
#copy_dynamic_fixture(name, target_dir = '.') ⇒ void
This method returns an undefined value.
Copies the contents of a dynamic fixture to a given directory.
146 147 148 |
# File 'lib/golly-utils/testing/dynamic_fixtures.rb', line 146 def copy_dynamic_fixture(name, target_dir = '.') FileUtils.cp_r "#{dynamic_fixture_dir name}/.", target_dir end |
#inside_dynamic_fixture(name, options = {}) { ... } ⇒ Object
Creates a clean copy of a predefined dynamic fixture, changes directory into it and yields. The fixture copy is removed from the file system after the yield block returns.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/golly-utils/testing/dynamic_fixtures.rb', line 158 def inside_dynamic_fixture(name, ={}, &block) .validate_option_keys INSIDE_DYNAMIC_FIXTURE_OPTIONS Dir.mktmpdir {|dir| copy_dynamic_fixture name, dir df= get_dynamic_fixture_data(name) if cd_into= [:cd_into] || df[:cd_into] dir= File.join dir, cd_into end $gu_dynamic_fixture_chdir_lock.synchronize { return Dir.chdir dir, &block } } end |