Module: GollyUtils::Testing::Helpers::ClassMethods
- Defined in:
- lib/golly-utils/testing/helpers_base.rb,
lib/golly-utils/testing/rspec/files.rb
Instance Method Summary collapse
-
#run_all_in_empty_dir(dir_name = nil) { ... } ⇒ void
Runs all RSpec examples (in the current context) in a new, empty directory.
-
#run_each_in_empty_dir(dir_name = nil) ⇒ void
Runs each RSpec example in a new, empty directory.
-
#run_each_in_empty_dir_unless_in_one_already(dir_name = nil) ⇒ void
Runs each RSpec example in a new, empty directory unless the context has already put it in one (for example, via #run_all_in_empty_dir).
Instance Method Details
#run_all_in_empty_dir(dir_name = nil) { ... } ⇒ void
This method returns an undefined value.
Runs all RSpec examples (in the current context) in a new, empty directory.
The directory is deleted after all examples have run, and the original current-directory restored.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/golly-utils/testing/rspec/files.rb', line 43 def run_all_in_empty_dir(dir_name=nil, &block) block ||= Proc.new{} @@around_all_in_empty_dir_count ||= 0 @@around_all_in_empty_dir_count += 1 block_name= :"@@around_all_in_empty_dir_#@@around_all_in_empty_dir_count" SELF.class_variable_set block_name, block eval <<-EOB before(:all){ inside_empty_dir(#{dir_name.inspect}) block= ::#{SELF}.class_variable_get(:"#{block_name}") instance_exec &block } after(:all){ step_out_of_tmp_dir } EOB end |
#run_each_in_empty_dir(dir_name = nil) ⇒ void
This method returns an undefined value.
Runs each RSpec example in a new, empty directory.
Old directories are deleted at the end of each example, and the original current-directory restored.
12 13 14 15 16 17 18 |
# File 'lib/golly-utils/testing/rspec/files.rb', line 12 def run_each_in_empty_dir(dir_name=nil) eval <<-EOB around :each do |ex| inside_empty_dir(#{dir_name.inspect}){ ex.run } end EOB end |
#run_each_in_empty_dir_unless_in_one_already(dir_name = nil) ⇒ void
This method returns an undefined value.
Runs each RSpec example in a new, empty directory unless the context has already put it in one (for example, via #run_all_in_empty_dir).
26 27 28 29 30 31 32 |
# File 'lib/golly-utils/testing/rspec/files.rb', line 26 def run_each_in_empty_dir_unless_in_one_already(dir_name=nil) eval <<-EOB around :each do |ex| in_tmp_dir? ? ex.run : inside_empty_dir(#{dir_name.inspect}){ ex.run } end EOB end |