empezar 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +9 -1
- data/Guardfile +29 -0
- data/cucumber.yml +1 -0
- data/empezar.gemspec +2 -0
- data/features/starting_up.feature +38 -0
- data/features/step_definitions/starting_up_steps.rb +43 -0
- data/features/support/env.rb +20 -0
- data/features/support/hooks.rb +3 -0
- data/lib/empezar/echoing_formatter.rb +9 -8
- data/lib/empezar/run.rb +7 -0
- data/lib/empezar/runner.rb +10 -9
- data/lib/empezar/version.rb +1 -1
- data/lib/empezar.rb +1 -4
- data/spec/empezar/echoing_formatter_spec.rb +29 -14
- data/spec/empezar/run_spec.rb +15 -0
- data/spec/empezar/runner_spec.rb +90 -36
- metadata +48 -9
- data/lib/empezar/symbolmatrix.rb +0 -3
- data/lib/writer/symbolmatrix.rb +0 -21
- data/spec/symbolmatrix_spec.rb +0 -7
- data/spec/writer/symbolmatrix_spec.rb +0 -36
data/Gemfile
CHANGED
data/Guardfile
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# A sample Guardfile
|
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
|
3
|
+
|
|
4
|
+
guard 'rspec', cli: '--color --format doc' do
|
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
|
8
|
+
|
|
9
|
+
# Rails example
|
|
10
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
|
11
|
+
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
|
12
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
|
13
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
|
14
|
+
watch('config/routes.rb') { "spec/routing" }
|
|
15
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
|
16
|
+
|
|
17
|
+
# Capybara features specs
|
|
18
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
|
|
19
|
+
|
|
20
|
+
# Turnip features and steps
|
|
21
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
|
22
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
guard 'cucumber' do
|
|
26
|
+
watch(%r{^features/.+\.feature$})
|
|
27
|
+
watch(%r{^features/support/.+$}) { 'features' }
|
|
28
|
+
watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
|
|
29
|
+
end
|
data/cucumber.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
default: -ci
|
data/empezar.gemspec
CHANGED
|
@@ -17,6 +17,8 @@ Gem::Specification.new do |gem|
|
|
|
17
17
|
gem.add_dependency 'term-ansicolor'
|
|
18
18
|
|
|
19
19
|
gem.add_development_dependency 'rspec'
|
|
20
|
+
gem.add_development_dependency 'fast'
|
|
21
|
+
gem.add_development_dependency 'cucumber'
|
|
20
22
|
|
|
21
23
|
gem.files = `git ls-files`.split($/)
|
|
22
24
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Feature: Starting up an app with Empezar
|
|
2
|
+
In order to have all common needs covered for when
|
|
3
|
+
developing a new app
|
|
4
|
+
As a Ruby developer
|
|
5
|
+
I want to have Empezar dealing with log, configuration and
|
|
6
|
+
command line parameters setup for me
|
|
7
|
+
|
|
8
|
+
@clean
|
|
9
|
+
Scenario: Very simple setup, no args
|
|
10
|
+
Given the config file "config/main.yaml"
|
|
11
|
+
"""
|
|
12
|
+
data: 90
|
|
13
|
+
"""
|
|
14
|
+
When I start the runner
|
|
15
|
+
Then I should have 'data' with value 90 in Configuration
|
|
16
|
+
When I info "Hello World" in the Log
|
|
17
|
+
Then I should see "Hello World" in blue in command line
|
|
18
|
+
And I should see "Hello World" in the "log/main.log" file
|
|
19
|
+
|
|
20
|
+
@clean
|
|
21
|
+
Scenario: App with some arguments
|
|
22
|
+
Given the config file "config/main.yaml"
|
|
23
|
+
"""
|
|
24
|
+
data: 89
|
|
25
|
+
client:
|
|
26
|
+
host: localhost
|
|
27
|
+
path: /
|
|
28
|
+
"""
|
|
29
|
+
And the command line arguments
|
|
30
|
+
"""
|
|
31
|
+
client.port:8080 more:34
|
|
32
|
+
"""
|
|
33
|
+
When I start the runner
|
|
34
|
+
Then I should have 'data' with value 89 in Configuration
|
|
35
|
+
And I should have 'more' with value 34 in Configuration
|
|
36
|
+
And I should have 8080 in 'port' in 'client'
|
|
37
|
+
And I should have "localhost" in 'host' in 'client'
|
|
38
|
+
And I should have "/" in 'path' in 'client'
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Given /^the config file "(.+?)"$/ do |path, content|
|
|
2
|
+
Fast.file.write path, content
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
When /^I start the runner$/ do
|
|
6
|
+
@arguments ||= []
|
|
7
|
+
Runner.run(
|
|
8
|
+
stdout: fake_stdout,
|
|
9
|
+
config_file: 'config/main.yaml',
|
|
10
|
+
log_file: 'log/main.log',
|
|
11
|
+
arguments: @arguments
|
|
12
|
+
)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
Then /^I should have '(.+?)' with value (\d+) in Configuration$/ do |key, value|
|
|
16
|
+
Configuration.send(key.to_sym).should == value.to_i
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
When /^I info "(.+?)" in the Log$/ do |text|
|
|
20
|
+
Log.info text
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
Then /^I should see "(.+?)" in blue in command line$/ do |text|
|
|
24
|
+
fake_stdout.last.should == Term::ANSIColor.blue(text)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
And /^I should see "(.+?)" in the "(.+?)" file$/ do |text, file|
|
|
28
|
+
Fast.file.read(file).should include text
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
Given /^the command line arguments$/ do |argument_line|
|
|
32
|
+
@arguments = argument_line.split " "
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
Then /^I should have (\d+) in '(.+?)' in '(.+?)'$/ do |value, subkey, key|
|
|
36
|
+
Configuration.send(key.to_sym).send(subkey.to_sym)
|
|
37
|
+
.should == value.to_i
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
Then /^I should have "(.+?)" in '(.+?)' in '(.+?)'$/ do |value, subkey, key|
|
|
41
|
+
Configuration.send(key.to_sym).send(subkey.to_sym)
|
|
42
|
+
.should == value
|
|
43
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'fast/fast'
|
|
2
|
+
|
|
3
|
+
$LOAD_PATH << File.expand_path("../../../lib", __FILE__)
|
|
4
|
+
|
|
5
|
+
require 'empezar'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
module Helpers
|
|
9
|
+
class StdOut < Array
|
|
10
|
+
def puts element
|
|
11
|
+
self.push element
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def fake_stdout
|
|
16
|
+
@fake_stdout ||= StdOut.new
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
World Helpers
|
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
module Empezar
|
|
2
2
|
class EchoingFormatter
|
|
3
|
-
attr_accessor :wrapee
|
|
3
|
+
attr_accessor :wrapee, :stdout
|
|
4
4
|
|
|
5
|
-
def initialize wrapee
|
|
5
|
+
def initialize wrapee, stdout
|
|
6
6
|
@wrapee = wrapee
|
|
7
|
+
@stdout = stdout
|
|
7
8
|
end
|
|
8
9
|
|
|
9
10
|
def call severity, datetime, progname, message
|
|
10
11
|
case severity
|
|
11
12
|
when Logger::Severity::FATAL, "FATAL"
|
|
12
|
-
|
|
13
|
+
@stdout.puts Term::ANSIColor.bold Term::ANSIColor.red message
|
|
13
14
|
when Logger::Severity::ERROR, "ERROR"
|
|
14
|
-
|
|
15
|
+
@stdout.puts Term::ANSIColor.red message
|
|
15
16
|
when Logger::Severity::WARN, "WARN"
|
|
16
|
-
|
|
17
|
+
@stdout.puts Term::ANSIColor.yellow message
|
|
17
18
|
when Logger::Severity::INFO, "INFO"
|
|
18
|
-
|
|
19
|
+
@stdout.puts Term::ANSIColor.blue message
|
|
19
20
|
when Logger::Severity::DEBUG, "DEBUG"
|
|
20
|
-
|
|
21
|
+
@stdout.puts Term::ANSIColor.dark message
|
|
21
22
|
when Logger::Severity::UNKNOWN, "UNKNOWN"
|
|
22
|
-
|
|
23
|
+
@stdout.puts message
|
|
23
24
|
end
|
|
24
25
|
|
|
25
26
|
wrapee.call severity, datetime, progname, message
|
data/lib/empezar/run.rb
ADDED
data/lib/empezar/runner.rb
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
module Empezar
|
|
2
2
|
class Runner
|
|
3
|
-
def self.run
|
|
4
|
-
self.start_configuration
|
|
5
|
-
self.start_logger
|
|
3
|
+
def self.run params
|
|
4
|
+
self.start_configuration params[:config_file], params[:arguments]
|
|
5
|
+
self.start_logger params[:log_file], params[:stdout]
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
-
def self.start_configuration
|
|
9
|
-
unless File.exist?
|
|
10
|
-
raise ConfigurationFileMissingException, "The configuration file is missing from '#{
|
|
8
|
+
def self.start_configuration config_file, arguments
|
|
9
|
+
unless File.exist? config_file
|
|
10
|
+
raise ConfigurationFileMissingException, "The configuration file is missing from '#{config_file}'"
|
|
11
11
|
end
|
|
12
|
-
Empezar::Configuration.instance.merge! SymbolMatrix.new
|
|
12
|
+
Empezar::Configuration.instance.merge! SymbolMatrix.new config_file
|
|
13
|
+
Empezar::Configuration.instance.recursive_merge! SymbolMatrix.new arguments.join " "
|
|
13
14
|
end
|
|
14
15
|
|
|
15
|
-
def self.start_logger
|
|
16
|
+
def self.start_logger log_file, stdout
|
|
16
17
|
Dir.mkdir 'log' unless Dir.exist? 'log'
|
|
17
18
|
Empezar::Log.start Logger.new 'log/main.log', 'daily'
|
|
18
19
|
if Empezar::Configuration.instance.has_key? :verbosity and Empezar::Configuration.instance.verbosity == 'silent'
|
|
19
20
|
else
|
|
20
|
-
Empezar::Log.instance.formatter = EchoingFormatter.new Logger::Formatter.new
|
|
21
|
+
Empezar::Log.instance.formatter = EchoingFormatter.new Logger::Formatter.new, stdout
|
|
21
22
|
end
|
|
22
23
|
end
|
|
23
24
|
end
|
data/lib/empezar/version.rb
CHANGED
data/lib/empezar.rb
CHANGED
|
@@ -6,10 +6,7 @@ require 'logger'
|
|
|
6
6
|
|
|
7
7
|
require 'empezar/version'
|
|
8
8
|
require 'empezar/exceptions'
|
|
9
|
-
require 'empezar/symbolmatrix'
|
|
10
9
|
require 'empezar/configuration'
|
|
11
10
|
require 'empezar/runner'
|
|
12
11
|
require 'empezar/echoing_formatter'
|
|
13
|
-
require 'empezar/log'
|
|
14
|
-
|
|
15
|
-
require 'writer/symbolmatrix'
|
|
12
|
+
require 'empezar/log'
|
|
@@ -3,22 +3,31 @@ require 'spec_helper'
|
|
|
3
3
|
describe Empezar::EchoingFormatter do
|
|
4
4
|
before do
|
|
5
5
|
@formatter_stub = stub 'formatter'
|
|
6
|
+
@stdout = stub 'stdout'
|
|
6
7
|
end
|
|
7
8
|
|
|
8
9
|
describe '#initialize' do
|
|
9
10
|
it 'should receive a Formatter as an argument and store it as the wrapee' do
|
|
10
|
-
my_formatter = Empezar::EchoingFormatter
|
|
11
|
+
my_formatter = Empezar::EchoingFormatter
|
|
12
|
+
.new @formatter_stub, @stdout
|
|
11
13
|
my_formatter.wrapee.should == @formatter_stub
|
|
12
14
|
end
|
|
15
|
+
|
|
16
|
+
it 'should receive an io as an argument and store it as the stdout' do
|
|
17
|
+
my_formatter = Empezar::EchoingFormatter
|
|
18
|
+
.new @formatter_stub, @stdout
|
|
19
|
+
my_formatter.stdout.should == @stdout
|
|
20
|
+
end
|
|
13
21
|
end
|
|
14
22
|
|
|
15
23
|
describe '#call' do
|
|
16
24
|
context 'fatal error' do
|
|
17
25
|
it 'should puts to stdout with a bold red message' do
|
|
18
26
|
@formatter_stub.stub :call
|
|
19
|
-
|
|
27
|
+
@stdout.should_receive(:puts).with Term::ANSIColor.bold Term::ANSIColor.red "message"
|
|
20
28
|
|
|
21
|
-
formatter = Empezar::EchoingFormatter
|
|
29
|
+
formatter = Empezar::EchoingFormatter
|
|
30
|
+
.new @formatter_stub, @stdout
|
|
22
31
|
formatter.call "FATAL", nil, nil, "message"
|
|
23
32
|
end
|
|
24
33
|
end
|
|
@@ -26,9 +35,10 @@ describe Empezar::EchoingFormatter do
|
|
|
26
35
|
context 'error' do
|
|
27
36
|
it 'should puts to stdout with a red message' do
|
|
28
37
|
@formatter_stub.stub :call
|
|
29
|
-
|
|
38
|
+
@stdout.should_receive(:puts).with Term::ANSIColor.red "message"
|
|
30
39
|
|
|
31
|
-
formatter = Empezar::EchoingFormatter
|
|
40
|
+
formatter = Empezar::EchoingFormatter
|
|
41
|
+
.new @formatter_stub, @stdout
|
|
32
42
|
formatter.call "ERROR", nil, nil, "message"
|
|
33
43
|
end
|
|
34
44
|
end
|
|
@@ -36,9 +46,10 @@ describe Empezar::EchoingFormatter do
|
|
|
36
46
|
context 'warn' do
|
|
37
47
|
it 'should puts to stdout with a yellow message' do
|
|
38
48
|
@formatter_stub.stub :call
|
|
39
|
-
|
|
49
|
+
@stdout.should_receive(:puts).with Term::ANSIColor.yellow "message"
|
|
40
50
|
|
|
41
|
-
formatter = Empezar::EchoingFormatter
|
|
51
|
+
formatter = Empezar::EchoingFormatter
|
|
52
|
+
.new @formatter_stub, @stdout
|
|
42
53
|
formatter.call "WARN", nil, nil, "message"
|
|
43
54
|
end
|
|
44
55
|
end
|
|
@@ -46,9 +57,10 @@ describe Empezar::EchoingFormatter do
|
|
|
46
57
|
context 'info' do
|
|
47
58
|
it 'should puts to stdout with a blue message' do
|
|
48
59
|
@formatter_stub.stub :call
|
|
49
|
-
|
|
60
|
+
@stdout.should_receive(:puts).with Term::ANSIColor.blue "message"
|
|
50
61
|
|
|
51
|
-
formatter = Empezar::EchoingFormatter
|
|
62
|
+
formatter = Empezar::EchoingFormatter
|
|
63
|
+
.new @formatter_stub, @stdout
|
|
52
64
|
formatter.call "INFO", nil, nil, "message"
|
|
53
65
|
end
|
|
54
66
|
end
|
|
@@ -56,9 +68,10 @@ describe Empezar::EchoingFormatter do
|
|
|
56
68
|
context 'unknown' do
|
|
57
69
|
it 'should puts to stdout with the message' do
|
|
58
70
|
@formatter_stub.stub :call
|
|
59
|
-
|
|
71
|
+
@stdout.should_receive(:puts).with "message"
|
|
60
72
|
|
|
61
|
-
formatter = Empezar::EchoingFormatter
|
|
73
|
+
formatter = Empezar::EchoingFormatter
|
|
74
|
+
.new @formatter_stub, @stdout
|
|
62
75
|
formatter.call "UNKNOWN", nil, nil, "message"
|
|
63
76
|
end
|
|
64
77
|
end
|
|
@@ -66,9 +79,10 @@ describe Empezar::EchoingFormatter do
|
|
|
66
79
|
context 'debug' do
|
|
67
80
|
it 'should puts to stdout with a dark message' do
|
|
68
81
|
@formatter_stub.stub :call
|
|
69
|
-
|
|
82
|
+
@stdout.should_receive(:puts).with Term::ANSIColor.dark "message"
|
|
70
83
|
|
|
71
|
-
formatter = Empezar::EchoingFormatter
|
|
84
|
+
formatter = Empezar::EchoingFormatter
|
|
85
|
+
.new @formatter_stub, @stdout
|
|
72
86
|
formatter.call "DEBUG", nil, nil, "message"
|
|
73
87
|
end
|
|
74
88
|
end
|
|
@@ -77,7 +91,8 @@ describe Empezar::EchoingFormatter do
|
|
|
77
91
|
arg1 = stub; arg2 = stub; arg3 = stub; arg4 = stub
|
|
78
92
|
@formatter_stub.should_receive(:call).with arg1, arg2, arg3, arg4
|
|
79
93
|
|
|
80
|
-
formatter = Empezar::EchoingFormatter
|
|
94
|
+
formatter = Empezar::EchoingFormatter
|
|
95
|
+
.new @formatter_stub, @stdout
|
|
81
96
|
formatter.call arg1, arg2, arg3, arg4
|
|
82
97
|
end
|
|
83
98
|
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "running with defaults" do
|
|
4
|
+
it 'should use config/main.yaml, log/main.yaml, ARGV and $stdout' do
|
|
5
|
+
Empezar::Runner.should_receive(:run)
|
|
6
|
+
.with(
|
|
7
|
+
config_file: "config/main.yaml",
|
|
8
|
+
log_file: "log/main.yaml",
|
|
9
|
+
stdout: $stdout,
|
|
10
|
+
arguments: ARGV
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
require 'empezar/run'
|
|
14
|
+
end
|
|
15
|
+
end
|
data/spec/empezar/runner_spec.rb
CHANGED
|
@@ -2,25 +2,32 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe Empezar::Runner do
|
|
4
4
|
describe '.run' do
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
context 'with params for stdout and config_file' do
|
|
6
|
+
before do
|
|
7
|
+
@stdout = stub 'stdout'
|
|
8
|
+
@config_file = stub 'config file'
|
|
9
|
+
@log_file = stub 'log file'
|
|
10
|
+
@arguments = stub 'arguments'
|
|
11
|
+
@params = {
|
|
12
|
+
stdout: @stdout,
|
|
13
|
+
log_file: @log_file,
|
|
14
|
+
config_file: @config_file,
|
|
15
|
+
arguments: @arguments
|
|
16
|
+
}
|
|
16
17
|
end
|
|
17
|
-
end
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
it 'should call start_logger' do
|
|
20
|
+
Empezar::Runner.stub :start_configuration
|
|
21
|
+
Empezar::Runner.should_receive(:start_logger)
|
|
22
|
+
.with @log_file, @stdout
|
|
23
|
+
Empezar::Runner.run @params
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'should call start_configuration' do
|
|
21
27
|
Empezar::Runner.stub :start_logger
|
|
22
|
-
Empezar::Runner.should_receive(:start_configuration)
|
|
23
|
-
|
|
28
|
+
Empezar::Runner.should_receive(:start_configuration)
|
|
29
|
+
.with @config_file, @arguments
|
|
30
|
+
Empezar::Runner.run @params
|
|
24
31
|
end
|
|
25
32
|
end
|
|
26
33
|
end
|
|
@@ -28,7 +35,10 @@ describe Empezar::Runner do
|
|
|
28
35
|
describe '.start_logger' do
|
|
29
36
|
before do
|
|
30
37
|
@demo_logger = stub 'demo logger'
|
|
31
|
-
|
|
38
|
+
@stdout = stub 'stdout'
|
|
39
|
+
@log_file = 'log/main.log'
|
|
40
|
+
Logger.should_receive(:new)
|
|
41
|
+
.with(@log_file, 'daily').and_return @demo_logger
|
|
32
42
|
end
|
|
33
43
|
|
|
34
44
|
context 'normal conditions of pressure and temperature' do
|
|
@@ -36,17 +46,26 @@ describe Empezar::Runner do
|
|
|
36
46
|
formatter = stub 'formatter'
|
|
37
47
|
echoing_formatter = stub 'echoing formatter'
|
|
38
48
|
|
|
39
|
-
Dir.should_receive(:exist?).with('log')
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
Empezar::
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
Dir.should_receive(:exist?).with('log')
|
|
50
|
+
.and_return true
|
|
51
|
+
Empezar::Configuration.instance
|
|
52
|
+
.should_receive(:has_key?).with(:verbosity)
|
|
53
|
+
.and_return false
|
|
54
|
+
|
|
55
|
+
Logger::Formatter.should_receive(:new)
|
|
56
|
+
.and_return formatter
|
|
57
|
+
Empezar::EchoingFormatter.should_receive(:new)
|
|
58
|
+
.with(formatter, @stdout)
|
|
59
|
+
.and_return echoing_formatter
|
|
60
|
+
@demo_logger.should_receive(:formatter=)
|
|
61
|
+
.with echoing_formatter
|
|
62
|
+
|
|
63
|
+
Empezar::Log.should_receive(:start)
|
|
64
|
+
.with @demo_logger
|
|
65
|
+
Empezar::Log.should_receive(:instance)
|
|
66
|
+
.and_return @demo_logger
|
|
67
|
+
|
|
68
|
+
Empezar::Runner.start_logger @log_file, @stdout
|
|
50
69
|
end
|
|
51
70
|
end
|
|
52
71
|
|
|
@@ -59,7 +78,7 @@ describe Empezar::Runner do
|
|
|
59
78
|
|
|
60
79
|
Empezar::Log.should_receive(:start).with @demo_logger
|
|
61
80
|
|
|
62
|
-
Empezar::Runner.start_logger
|
|
81
|
+
Empezar::Runner.start_logger @stdout, @log_file
|
|
63
82
|
end
|
|
64
83
|
end
|
|
65
84
|
|
|
@@ -72,27 +91,62 @@ describe Empezar::Runner do
|
|
|
72
91
|
|
|
73
92
|
Empezar::Log.should_receive(:start).with @demo_logger
|
|
74
93
|
|
|
75
|
-
Empezar::Runner.start_logger
|
|
94
|
+
Empezar::Runner.start_logger @stdout, @log_file
|
|
76
95
|
end
|
|
77
96
|
end
|
|
78
97
|
end
|
|
79
98
|
|
|
80
99
|
describe '.start_configuration' do
|
|
100
|
+
before do
|
|
101
|
+
@arguments = stub 'arguments'
|
|
102
|
+
end
|
|
103
|
+
|
|
81
104
|
context 'the configuration file exists' do
|
|
82
|
-
|
|
105
|
+
before do
|
|
83
106
|
File.stub :exist? => true
|
|
84
|
-
config_stub = stub 'config'
|
|
85
|
-
|
|
86
|
-
|
|
107
|
+
@config_stub = stub 'config'
|
|
108
|
+
@joined_args = stub 'joined arguments'
|
|
109
|
+
@extra_data = stub 'extra data'
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it 'should initialize the configuration with the argument' do
|
|
113
|
+
SymbolMatrix.should_receive(:new).with('config/main.yaml')
|
|
114
|
+
.and_return @config_stub
|
|
115
|
+
Empezar::Configuration.instance.should_receive(:merge!)
|
|
116
|
+
.with @config_stub
|
|
117
|
+
|
|
118
|
+
@arguments.stub :join => @joined_args
|
|
119
|
+
SymbolMatrix.should_receive(:new).with(@joined_args)
|
|
120
|
+
.and_return @extra_data
|
|
121
|
+
Empezar::Configuration.instance.stub :recursive_merge!
|
|
122
|
+
|
|
123
|
+
Empezar::Runner
|
|
124
|
+
.start_configuration 'config/main.yaml', @arguments
|
|
125
|
+
end
|
|
87
126
|
|
|
88
|
-
|
|
127
|
+
it 'should parse the arguments joined and merge them recursively into Configuration' do
|
|
128
|
+
SymbolMatrix.should_receive(:new).with('config/main.yaml')
|
|
129
|
+
.and_return @config_stub
|
|
130
|
+
Empezar::Configuration.instance.should_receive(:merge!)
|
|
131
|
+
.with @config_stub
|
|
132
|
+
|
|
133
|
+
@arguments.should_receive(:join).with(" ")
|
|
134
|
+
.and_return @joined_args
|
|
135
|
+
SymbolMatrix.should_receive(:new).with(@joined_args)
|
|
136
|
+
.and_return @extra_data
|
|
137
|
+
Empezar::Configuration.instance.should_receive(:recursive_merge!)
|
|
138
|
+
.with @extra_data
|
|
139
|
+
|
|
140
|
+
Empezar::Runner
|
|
141
|
+
.start_configuration 'config/main.yaml', @arguments
|
|
89
142
|
end
|
|
90
143
|
end
|
|
91
144
|
|
|
92
145
|
context 'the configuration file is missing' do
|
|
93
146
|
it 'should raise a relevant error' do
|
|
94
147
|
File.should_receive(:exist?).with('config/main.yaml').and_return false
|
|
95
|
-
expect { Empezar::Runner
|
|
148
|
+
expect { Empezar::Runner
|
|
149
|
+
.start_configuration 'config/main.yaml', @arguments
|
|
96
150
|
}.to raise_error Empezar::ConfigurationFileMissingException,
|
|
97
151
|
"The configuration file is missing from 'config/main.yaml'"
|
|
98
152
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: empezar
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-12-
|
|
12
|
+
date: 2012-12-19 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: symbolmatrix
|
|
@@ -75,6 +75,38 @@ dependencies:
|
|
|
75
75
|
- - ! '>='
|
|
76
76
|
- !ruby/object:Gem::Version
|
|
77
77
|
version: '0'
|
|
78
|
+
- !ruby/object:Gem::Dependency
|
|
79
|
+
name: fast
|
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
|
81
|
+
none: false
|
|
82
|
+
requirements:
|
|
83
|
+
- - ! '>='
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: '0'
|
|
86
|
+
type: :development
|
|
87
|
+
prerelease: false
|
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
89
|
+
none: false
|
|
90
|
+
requirements:
|
|
91
|
+
- - ! '>='
|
|
92
|
+
- !ruby/object:Gem::Version
|
|
93
|
+
version: '0'
|
|
94
|
+
- !ruby/object:Gem::Dependency
|
|
95
|
+
name: cucumber
|
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
|
97
|
+
none: false
|
|
98
|
+
requirements:
|
|
99
|
+
- - ! '>='
|
|
100
|
+
- !ruby/object:Gem::Version
|
|
101
|
+
version: '0'
|
|
102
|
+
type: :development
|
|
103
|
+
prerelease: false
|
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
105
|
+
none: false
|
|
106
|
+
requirements:
|
|
107
|
+
- - ! '>='
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0'
|
|
78
110
|
description: A simple Ruby library to enforce a convention for configuration, logging
|
|
79
111
|
and execution
|
|
80
112
|
email:
|
|
@@ -85,31 +117,35 @@ extra_rdoc_files: []
|
|
|
85
117
|
files:
|
|
86
118
|
- .gitignore
|
|
87
119
|
- Gemfile
|
|
120
|
+
- Guardfile
|
|
88
121
|
- LICENSE.txt
|
|
89
122
|
- README.md
|
|
90
123
|
- Rakefile
|
|
124
|
+
- cucumber.yml
|
|
91
125
|
- empezar.gemspec
|
|
126
|
+
- features/starting_up.feature
|
|
127
|
+
- features/step_definitions/starting_up_steps.rb
|
|
128
|
+
- features/support/env.rb
|
|
129
|
+
- features/support/hooks.rb
|
|
92
130
|
- lib/empezar.rb
|
|
93
131
|
- lib/empezar/configuration.rb
|
|
94
132
|
- lib/empezar/echoing_formatter.rb
|
|
95
133
|
- lib/empezar/exceptions.rb
|
|
96
134
|
- lib/empezar/log.rb
|
|
135
|
+
- lib/empezar/run.rb
|
|
97
136
|
- lib/empezar/runner.rb
|
|
98
|
-
- lib/empezar/symbolmatrix.rb
|
|
99
137
|
- lib/empezar/version.rb
|
|
100
|
-
- lib/writer/symbolmatrix.rb
|
|
101
138
|
- sample/config/main.yaml
|
|
102
139
|
- sample/script.rb
|
|
103
140
|
- spec/configuration_spec.rb
|
|
104
141
|
- spec/empezar/configuration_spec.rb
|
|
105
142
|
- spec/empezar/echoing_formatter_spec.rb
|
|
106
143
|
- spec/empezar/log_spec.rb
|
|
144
|
+
- spec/empezar/run_spec.rb
|
|
107
145
|
- spec/empezar/runner_spec.rb
|
|
108
146
|
- spec/log_spec.rb
|
|
109
147
|
- spec/runner_spec.rb
|
|
110
148
|
- spec/spec_helper.rb
|
|
111
|
-
- spec/symbolmatrix_spec.rb
|
|
112
|
-
- spec/writer/symbolmatrix_spec.rb
|
|
113
149
|
homepage: http://github.com/Fetcher/empezar
|
|
114
150
|
licenses: []
|
|
115
151
|
post_install_message:
|
|
@@ -130,20 +166,23 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
130
166
|
version: '0'
|
|
131
167
|
requirements: []
|
|
132
168
|
rubyforge_project:
|
|
133
|
-
rubygems_version: 1.8.
|
|
169
|
+
rubygems_version: 1.8.21
|
|
134
170
|
signing_key:
|
|
135
171
|
specification_version: 3
|
|
136
172
|
summary: A simple Ruby library to enforce a convention for configuration, logging
|
|
137
173
|
and execution
|
|
138
174
|
test_files:
|
|
175
|
+
- features/starting_up.feature
|
|
176
|
+
- features/step_definitions/starting_up_steps.rb
|
|
177
|
+
- features/support/env.rb
|
|
178
|
+
- features/support/hooks.rb
|
|
139
179
|
- spec/configuration_spec.rb
|
|
140
180
|
- spec/empezar/configuration_spec.rb
|
|
141
181
|
- spec/empezar/echoing_formatter_spec.rb
|
|
142
182
|
- spec/empezar/log_spec.rb
|
|
183
|
+
- spec/empezar/run_spec.rb
|
|
143
184
|
- spec/empezar/runner_spec.rb
|
|
144
185
|
- spec/log_spec.rb
|
|
145
186
|
- spec/runner_spec.rb
|
|
146
187
|
- spec/spec_helper.rb
|
|
147
|
-
- spec/symbolmatrix_spec.rb
|
|
148
|
-
- spec/writer/symbolmatrix_spec.rb
|
|
149
188
|
has_rdoc:
|
data/lib/empezar/symbolmatrix.rb
DELETED
data/lib/writer/symbolmatrix.rb
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
module Writer
|
|
2
|
-
class SymbolMatrix
|
|
3
|
-
attr_accessor :source
|
|
4
|
-
|
|
5
|
-
def initialize source
|
|
6
|
-
@source = source
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def serialization prefix = ""
|
|
10
|
-
text = ""
|
|
11
|
-
@source.each do |key, value|
|
|
12
|
-
if value.is_a? Hash
|
|
13
|
-
text += value.to.serialization(prefix + key.to_s + ".") +" "
|
|
14
|
-
else
|
|
15
|
-
text += "#{prefix}#{key}:#{value} "
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
text[0..-2]
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
data/spec/symbolmatrix_spec.rb
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Writer::SymbolMatrix do
|
|
4
|
-
describe '#initialize' do
|
|
5
|
-
it 'should set the argument as the source' do
|
|
6
|
-
source = stub 'source'
|
|
7
|
-
writer = Writer::SymbolMatrix.new source
|
|
8
|
-
writer.source.should == source
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
describe '#serialization' do
|
|
13
|
-
it 'should transform the multidimentional hash into a simple dot and colons serialization' do
|
|
14
|
-
multidimentional = SymbolMatrix.new hola: {
|
|
15
|
-
the: "start",
|
|
16
|
-
asdfdf: 8989,
|
|
17
|
-
of: {
|
|
18
|
-
some: "multidimentional"
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
stuff: "oops"
|
|
22
|
-
|
|
23
|
-
writer = Writer::SymbolMatrix.new multidimentional
|
|
24
|
-
writer.serialization.should == "hola.the:start hola.asdfdf:8989 hola.of.some:multidimentional stuff:oops"
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
context 'with argument' do
|
|
28
|
-
it 'should do the transformation appending the argument to each key-value pair' do
|
|
29
|
-
simple = SymbolMatrix.new mykey: "myvalue", otherkey: "othervalue"
|
|
30
|
-
|
|
31
|
-
writer = Writer::SymbolMatrix.new simple
|
|
32
|
-
writer.serialization("inside.").should == "inside.mykey:myvalue inside.otherkey:othervalue"
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|