Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Merge pull request hirefire#17 from nbibler/test_cleanup.
Browse files Browse the repository at this point in the history
Spec support file organization
  • Loading branch information
Michael van Rooijen committed May 4, 2011
2 parents e1e7218 + a562f87 commit be42d42
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
33 changes: 4 additions & 29 deletions spec/spec_helper.rb
Expand Up @@ -8,37 +8,12 @@
# Load the HireFire Ruby library
require File.join(LIB_PATH, 'hirefire')

module ConfigurationHelper

def configure(&block)
HireFire.configure(&block)
end

def with_configuration(&block)
old_configuration = HireFire.configuration
HireFire.configuration = HireFire::Configuration.new
yield(HireFire.configuration)
HireFire.configuration = old_configuration
end

def with_max_workers(workers, &block)
with_configuration do |config|
config.max_workers = workers
yield
end
end

def with_min_workers(workers, &block)
with_configuration do |config|
config.min_workers = workers
yield
end
end
end
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[File.join(File.expand_path('../support', __FILE__), '**/*.rb')].each {|f| require f}

##
# Use Mocha to mock with RSpec
RSpec.configure do |config|
config.mock_with :mocha
config.include ConfigurationHelper
end
end
31 changes: 31 additions & 0 deletions spec/support/configuration_helper.rb
@@ -0,0 +1,31 @@
module ConfigurationHelper
def configure(&block)
HireFire.configure(&block)
end

def with_configuration(&block)
old_configuration = HireFire.configuration
HireFire.configuration = HireFire::Configuration.new
yield(HireFire.configuration)
ensure
HireFire.configuration = old_configuration
end

def with_max_workers(workers, &block)
with_configuration do |config|
config.max_workers = workers
yield
end
end

def with_min_workers(workers, &block)
with_configuration do |config|
config.min_workers = workers
yield
end
end
end

RSpec.configure do |config|
config.include ConfigurationHelper
end

0 comments on commit be42d42

Please sign in to comment.