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

Commit

Permalink
Create spec/support to hold custom spec modules
Browse files Browse the repository at this point in the history
  • Loading branch information
nbibler committed May 4, 2011
1 parent e1e7218 commit a535857
Show file tree
Hide file tree
Showing 2 changed files with 34 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
30 changes: 30 additions & 0 deletions spec/support/configuration.rb
@@ -0,0 +1,30 @@
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

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

0 comments on commit a535857

Please sign in to comment.