spec/empezar/runner_spec.rb in empezar-0.2.0 vs spec/empezar/runner_spec.rb in empezar-0.3.0

- old
+ new

@@ -1,54 +1,73 @@ require 'spec_helper' describe Empezar::Runner do describe '.run' do - it 'should call start_logger' do - Empezar::Runner.stub :start_configuration - Empezar::Runner.should_receive(:start_logger) - Empezar::Runner.run - end - - context 'without argument' do - it 'should call start_configuration with config/main.yaml' do - Empezar::Runner.stub :start_logger - Empezar::Runner.should_receive(:start_configuration).with('config/main.yaml') - Empezar::Runner.run + context 'with params for stdout and config_file' do + before do + @stdout = stub 'stdout' + @config_file = stub 'config file' + @log_file = stub 'log file' + @arguments = stub 'arguments' + @params = { + stdout: @stdout, + log_file: @log_file, + config_file: @config_file, + arguments: @arguments + } end - end - context 'with argument' do - it 'should call start_configuration with the argument' do + it 'should call start_logger' do + Empezar::Runner.stub :start_configuration + Empezar::Runner.should_receive(:start_logger) + .with @log_file, @stdout + Empezar::Runner.run @params + end + + it 'should call start_configuration' do Empezar::Runner.stub :start_logger - Empezar::Runner.should_receive(:start_configuration).with('hola') - Empezar::Runner.run 'hola' + Empezar::Runner.should_receive(:start_configuration) + .with @config_file, @arguments + Empezar::Runner.run @params end end end describe '.start_logger' do before do @demo_logger = stub 'demo logger' - Logger.should_receive(:new).with('log/main.log', 'daily').and_return @demo_logger + @stdout = stub 'stdout' + @log_file = 'log/main.log' + Logger.should_receive(:new) + .with(@log_file, 'daily').and_return @demo_logger end context 'normal conditions of pressure and temperature' do it 'should initialize the log as logger pointing to log/main.log, daily with the EchoingFormatter' do formatter = stub 'formatter' echoing_formatter = stub 'echoing formatter' - Dir.should_receive(:exist?).with('log').and_return true - Empezar::Configuration.instance.should_receive(:has_key?).with(:verbosity).and_return false + Dir.should_receive(:exist?).with('log') + .and_return true + Empezar::Configuration.instance + .should_receive(:has_key?).with(:verbosity) + .and_return false - Logger::Formatter.should_receive(:new).and_return formatter - Empezar::EchoingFormatter.should_receive(:new).with(formatter).and_return echoing_formatter - @demo_logger.should_receive(:formatter=).with echoing_formatter + Logger::Formatter.should_receive(:new) + .and_return formatter + Empezar::EchoingFormatter.should_receive(:new) + .with(formatter, @stdout) + .and_return echoing_formatter + @demo_logger.should_receive(:formatter=) + .with echoing_formatter - Empezar::Log.should_receive(:start).with @demo_logger - Empezar::Log.should_receive(:instance).and_return @demo_logger + Empezar::Log.should_receive(:start) + .with @demo_logger + Empezar::Log.should_receive(:instance) + .and_return @demo_logger - Empezar::Runner.start_logger + Empezar::Runner.start_logger @log_file, @stdout end end context 'the verbosity level is set to silent' do it 'should not set the formatter as an echoing formatter' do @@ -57,11 +76,11 @@ Empezar::Configuration.instance.should_receive(:has_key?).with(:verbosity).and_return true Empezar::Configuration.instance.should_receive(:verbosity).and_return 'silent' Empezar::Log.should_receive(:start).with @demo_logger - Empezar::Runner.start_logger + Empezar::Runner.start_logger @stdout, @log_file end end context 'the dir log does not exist' do it 'should create the dir log' do @@ -70,30 +89,65 @@ Dir.should_receive(:exist?).with('log').and_return false Dir.should_receive(:mkdir).with('log') Empezar::Log.should_receive(:start).with @demo_logger - Empezar::Runner.start_logger + Empezar::Runner.start_logger @stdout, @log_file end end end describe '.start_configuration' do + before do + @arguments = stub 'arguments' + end + context 'the configuration file exists' do - it 'should initialize the configuration with the argument' do + before do File.stub :exist? => true - config_stub = stub 'config' - SymbolMatrix.should_receive(:new).with('config/main.yaml').and_return config_stub - Empezar::Configuration.instance.should_receive(:merge!).with(config_stub) + @config_stub = stub 'config' + @joined_args = stub 'joined arguments' + @extra_data = stub 'extra data' + end + + it 'should initialize the configuration with the argument' do + SymbolMatrix.should_receive(:new).with('config/main.yaml') + .and_return @config_stub + Empezar::Configuration.instance.should_receive(:merge!) + .with @config_stub - Empezar::Runner.start_configuration 'config/main.yaml' + @arguments.stub :join => @joined_args + SymbolMatrix.should_receive(:new).with(@joined_args) + .and_return @extra_data + Empezar::Configuration.instance.stub :recursive_merge! + + Empezar::Runner + .start_configuration 'config/main.yaml', @arguments end + + it 'should parse the arguments joined and merge them recursively into Configuration' do + SymbolMatrix.should_receive(:new).with('config/main.yaml') + .and_return @config_stub + Empezar::Configuration.instance.should_receive(:merge!) + .with @config_stub + + @arguments.should_receive(:join).with(" ") + .and_return @joined_args + SymbolMatrix.should_receive(:new).with(@joined_args) + .and_return @extra_data + Empezar::Configuration.instance.should_receive(:recursive_merge!) + .with @extra_data + + Empezar::Runner + .start_configuration 'config/main.yaml', @arguments + end end context 'the configuration file is missing' do it 'should raise a relevant error' do File.should_receive(:exist?).with('config/main.yaml').and_return false - expect { Empezar::Runner.start_configuration 'config/main.yaml' + expect { Empezar::Runner + .start_configuration 'config/main.yaml', @arguments }.to raise_error Empezar::ConfigurationFileMissingException, "The configuration file is missing from 'config/main.yaml'" end end end \ No newline at end of file