Class: EcomDev::ChefSpec::Configuration
- Inherits:
-
Object
- Object
- EcomDev::ChefSpec::Configuration
- Extended by:
- Forwardable
- Includes:
- Singleton
- Defined in:
- lib/ecomdev/chefspec/configuration.rb
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
Returns the value of attribute callbacks.
-
#cookbook_paths ⇒ Object
Returns the value of attribute cookbook_paths.
Class Method Summary collapse
Instance Method Summary collapse
- #after_example(example) ⇒ Object
- #before_example(example) ⇒ Object
- #callback(callback) ⇒ Object
- #cookbook_path(path) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #reset ⇒ Object
- #setup! ⇒ Object
- #teardown! ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
14 15 16 17 |
# File 'lib/ecomdev/chefspec/configuration.rb', line 14 def initialize @cookbook_paths = [] @callbacks = [] end |
Instance Attribute Details
#callbacks ⇒ Object
Returns the value of attribute callbacks.
12 13 14 |
# File 'lib/ecomdev/chefspec/configuration.rb', line 12 def callbacks @callbacks end |
#cookbook_paths ⇒ Object
Returns the value of attribute cookbook_paths.
11 12 13 |
# File 'lib/ecomdev/chefspec/configuration.rb', line 11 def cookbook_paths @cookbook_paths end |
Class Method Details
.register ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/ecomdev/chefspec/configuration.rb', line 63 def self.register if defined?(ChefSpec::Berkshelf) klass = ChefSpec::Berkshelf elsif defined?(ChefSpec::Librarian) klass = ChefSpec::Librarian else klass = false end if klass klass.class_exec do alias_method :old_setup!, :setup! alias_method :old_teardown!, :teardown! def setup! old_setup! EcomDev::ChefSpec::Configuration.setup! end def teardown! old_teardown! EcomDev::ChefSpec::Configuration.teardown! end end else RSpec.configure do |config| config.before(:suite) { EcomDev::ChefSpec::Configuration.setup! } config.after(:suite) { EcomDev::ChefSpec::Configuration.teardown! } end end RSpec.configure do |config| config.before(:each) { EcomDev::ChefSpec::Configuration.before_example(self) } config.after(:each) { EcomDev::ChefSpec::Configuration.after_example(self) } end end |
Instance Method Details
#after_example(example) ⇒ Object
46 47 48 |
# File 'lib/ecomdev/chefspec/configuration.rb', line 46 def after_example(example) invoke_callbacks(__method__, example) end |
#before_example(example) ⇒ Object
42 43 44 |
# File 'lib/ecomdev/chefspec/configuration.rb', line 42 def before_example(example) invoke_callbacks(__method__, example) end |
#callback(callback) ⇒ Object
59 60 61 |
# File 'lib/ecomdev/chefspec/configuration.rb', line 59 def callback(callback) @callbacks << callback unless callbacks.include?(callback) end |
#cookbook_path(path) ⇒ Object
55 56 57 |
# File 'lib/ecomdev/chefspec/configuration.rb', line 55 def cookbook_path(path) @cookbook_paths << path unless cookbook_paths.include?(path) end |
#reset ⇒ Object
50 51 52 53 |
# File 'lib/ecomdev/chefspec/configuration.rb', line 50 def reset @cookbook_paths = [] @callbacks = [] end |
#setup! ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ecomdev/chefspec/configuration.rb', line 19 def setup! unless cookbook_paths.empty? original_path = RSpec.configuration.cookbook_path if original_path.nil? original_path = [] elsif original_path.is_a?(String) original_path = [original_path] end cookbook_paths.each do |path| original_path << path unless original_path.include?(path) end RSpec.configuration.cookbook_path = original_path end invoke_callbacks(__method__) end |
#teardown! ⇒ Object
38 39 40 |
# File 'lib/ecomdev/chefspec/configuration.rb', line 38 def teardown! invoke_callbacks(__method__) end |