require_relative "../../helper" require_relative "../../../lib/fabriq/logging" require_relative "../../../lib/fabriq/config" describe Fabriq::Config do before do @config = Fabriq::Config @config.plugin_port = @plugin_port = mock('PluginPort') end describe "#load" do before do @plugin_port.stubs(:require_plugins) @config.stubs(:require) end it "fails if a configuration file cannot be found" do @config.expects(:fail_if_configuration_file_not_found) @config.load end it "let Fabrig::PluginPort require all plugins" do @plugin_port.expects(:require_plugins) @config.load end it "requires the configuration file" do @config.stubs(:configuration_file_path).returns("/path/to/config.rb") @config.expects(:require).with("/path/to/config.rb") @config.load end end describe '#fail_if_configuration_file_not_found' do it "throws a RuntimeError if a configuration file is not locatable" do @config.stubs(:configuration_file_available?).returns(false) -> { @config.fail_if_configuration_file_not_found }.must_raise(RuntimeError) end it "does not raise an Error if a config file is available" do @config.stubs(:configuration_file_available?).returns(true) @config.fail_if_configuration_file_not_found end end describe '#configuration_file_available?' do it "returns true if #configuration_file_path returns a string" do @config.stubs(:configuration_file_path).returns("/path/to/file") @config.configuration_file_available?.must_equal(true) end it "returns false if #configuration_file_path is nil" do @config.stubs(:configuration_file_path).returns(nil) @config.configuration_file_available?.must_equal(false) end end describe '#configuration_file_path' do before do File.stubs(:expand_path).returns("/home") end it "returns nil if a config file cannot be found in assumed locations" do File.stubs(:exist?).returns(false) @config.configuration_file_path.must_be_nil end it "returns a path if a config file is available in the current execution path (pwd)" do Dir.stubs(:pwd).returns("/path/to") File.stubs(:exist?).with("/home/.fabriq/config.rb") File.expects(:exist?).with("/path/to/config.rb").returns(true) @config.configuration_file_path.must_equal("/path/to/config.rb") end it "returns a path if a config file is available in the current home (~/.fabriq)" do File.expects(:exist?).with("/home/.fabriq/config.rb").returns(true) @config.configuration_file_path.must_equal("/home/.fabriq/config.rb") end end describe '#register_plugin' do it "sends #register_plugin to the PluginPort passing klass and config block" do config_block = -> {} @plugin_port.expects(:register_plugin).with() do |klass, block| klass.must_equal(self.class) block.must_equal(&config_block) end @config.register_plugin(self.class, &config_block) end end end