simple_command 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/simple_command.rb +1 -13
- data/lib/simple_command/errors.rb +14 -0
- data/lib/simple_command/version.rb +1 -1
- data/spec/simple_command/errors_spec.rb +38 -0
- data/spec/simple_command_spec.rb +12 -44
- metadata +5 -5
- data/spec/factories/fail_command.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dabb8a7bf076158513db0079c22a32a62c9be279
|
4
|
+
data.tar.gz: bfe07f08f8a996b159774cbaa140068f1c345006
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ddb4a9d44224a97779d648d761cd4e9f45409fbd7c16964224535ee03160d12fc9e4b8222a1ff0473709ea6b51cbcbcfdbf7b2f354fe694a883e9967f42dfab
|
7
|
+
data.tar.gz: 9caa9600dbeda9e0de74f96e83fd541f6c28cd68ea48c24fc6b27ea9c7a7ad27019e1c908fca116dd99cd2c18b1c69afa1aeaabcf7dc634471cb5b6ecdac616f
|
data/README.md
CHANGED
data/lib/simple_command.rb
CHANGED
@@ -32,19 +32,7 @@ module SimpleCommand
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def errors
|
35
|
-
@errors ||=
|
36
|
-
end
|
37
|
-
|
38
|
-
def add_error(key, value)
|
39
|
-
errors[key] ||= []
|
40
|
-
errors[key] << value
|
41
|
-
errors[key].uniq!
|
42
|
-
end
|
43
|
-
|
44
|
-
def add_errors(errors_hash)
|
45
|
-
errors_hash.each do |key, values|
|
46
|
-
values.each { |value| add_error key, value }
|
47
|
-
end
|
35
|
+
@errors ||= Errors.new
|
48
36
|
end
|
49
37
|
|
50
38
|
private
|
@@ -1,3 +1,17 @@
|
|
1
1
|
module SimpleCommand
|
2
2
|
class NotImplementedError < ::StandardError; end
|
3
|
+
|
4
|
+
class Errors < Hash
|
5
|
+
def add_error(key, value)
|
6
|
+
self[key] ||= []
|
7
|
+
self[key] << value
|
8
|
+
self[key].uniq!
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_errors(errors_hash)
|
12
|
+
errors_hash.each do |key, values|
|
13
|
+
values.each { |value| add_error key, value }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
3
17
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SimpleCommand::Errors do
|
4
|
+
let(:errors) { SimpleCommand::Errors.new }
|
5
|
+
|
6
|
+
describe '#add_error' do
|
7
|
+
before do
|
8
|
+
errors.add_error :some_error, 'some error description'
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'adds the error' do
|
12
|
+
expect(errors[:some_error]).to eq(['some error description'])
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'adds the same error only once' do
|
16
|
+
errors.add_error :some_error, 'some error description'
|
17
|
+
expect(errors[:some_error]).to eq(['some error description'])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#add_errors' do
|
22
|
+
let(:errors_list) do
|
23
|
+
{
|
24
|
+
some_error: ['some error description'],
|
25
|
+
another_error: ['another error description']
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
before do
|
30
|
+
errors.add_errors errors_list
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'populates itself with the added errors' do
|
34
|
+
expect(errors[:some_error]).to eq(errors_list[:some_error])
|
35
|
+
expect(errors[:another_error]).to eq(errors_list[:another_error])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/spec/simple_command_spec.rb
CHANGED
@@ -2,7 +2,6 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe SimpleCommand do
|
4
4
|
let(:command) { SuccessCommand.new(2) }
|
5
|
-
let(:fail_command) { FailCommand.new(2) }
|
6
5
|
|
7
6
|
describe '.perform' do
|
8
7
|
before do
|
@@ -41,7 +40,8 @@ describe SimpleCommand do
|
|
41
40
|
end
|
42
41
|
|
43
42
|
it 'is false if something went wrong' do
|
44
|
-
|
43
|
+
command.errors.add_error(:some_error, 'some message')
|
44
|
+
expect(command.perform.success?).to be_falsy
|
45
45
|
end
|
46
46
|
|
47
47
|
context 'when perform is not called yet' do
|
@@ -69,7 +69,8 @@ describe SimpleCommand do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'is true if something went wrong' do
|
72
|
-
|
72
|
+
command.errors.add_error(:some_error, 'some message')
|
73
|
+
expect(command.perform.failure?).to be_truthy
|
73
74
|
end
|
74
75
|
|
75
76
|
context 'when perform is not called yet' do
|
@@ -79,57 +80,24 @@ describe SimpleCommand do
|
|
79
80
|
end
|
80
81
|
end
|
81
82
|
|
82
|
-
describe '#add_error' do
|
83
|
-
before do
|
84
|
-
command.add_error :some_error, 'some error description'
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'adds the error' do
|
88
|
-
expect(command.errors[:some_error]).to eq(['some error description'])
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'adds the same error only once' do
|
92
|
-
command.add_error :some_error, 'some error description'
|
93
|
-
expect(command.errors[:some_error]).to eq(['some error description'])
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
describe '#add_errors' do
|
98
|
-
let(:errors) do
|
99
|
-
{
|
100
|
-
some_error: ['some error description'],
|
101
|
-
another_error: ['another error description']
|
102
|
-
}
|
103
|
-
end
|
104
|
-
|
105
|
-
before do
|
106
|
-
command.add_errors errors
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'populates #errors with the added errors' do
|
110
|
-
expect(command.errors[:some_error]).to eq(errors[:some_error])
|
111
|
-
expect(command.errors[:another_error]).to eq(errors[:another_error])
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
83
|
describe '#errors' do
|
116
|
-
|
117
|
-
|
118
|
-
it 'returns an Hash' do
|
119
|
-
expect(errors).to be_a(Hash)
|
84
|
+
it 'returns an SimpleCommand::Errors' do
|
85
|
+
expect(command.errors).to be_a(SimpleCommand::Errors)
|
120
86
|
end
|
121
87
|
|
122
88
|
context 'with no errors' do
|
123
|
-
it '
|
124
|
-
expect(errors).to be_empty
|
89
|
+
it 'is empty' do
|
90
|
+
expect(command.errors).to be_empty
|
125
91
|
end
|
126
92
|
end
|
127
93
|
|
128
94
|
context 'with errors' do
|
129
|
-
|
95
|
+
before do
|
96
|
+
command.errors.add_error(:some_error, 'some message')
|
97
|
+
end
|
130
98
|
|
131
99
|
it 'has a key with error message' do
|
132
|
-
expect(errors[:
|
100
|
+
expect(command.errors[:some_error]).to eq(['some message'])
|
133
101
|
end
|
134
102
|
end
|
135
103
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_command
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrea Pavoni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -71,9 +71,9 @@ files:
|
|
71
71
|
- lib/simple_command/errors.rb
|
72
72
|
- lib/simple_command/version.rb
|
73
73
|
- simple_command.gemspec
|
74
|
-
- spec/factories/fail_command.rb
|
75
74
|
- spec/factories/missed_perform_command.rb
|
76
75
|
- spec/factories/success_command.rb
|
76
|
+
- spec/simple_command/errors_spec.rb
|
77
77
|
- spec/simple_command_spec.rb
|
78
78
|
- spec/spec_helper.rb
|
79
79
|
homepage: http://github.com/nebulab/simple_command
|
@@ -96,13 +96,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
96
|
version: '0'
|
97
97
|
requirements: []
|
98
98
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.
|
99
|
+
rubygems_version: 2.4.5
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
102
|
summary: Easy way to build and manage commands (service objects)
|
103
103
|
test_files:
|
104
|
-
- spec/factories/fail_command.rb
|
105
104
|
- spec/factories/missed_perform_command.rb
|
106
105
|
- spec/factories/success_command.rb
|
106
|
+
- spec/simple_command/errors_spec.rb
|
107
107
|
- spec/simple_command_spec.rb
|
108
108
|
- spec/spec_helper.rb
|