simple_command 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0354a2aa2db1b280b8f692540d1cc43bc8d5101
4
- data.tar.gz: 338efb5cc5dba3c0dc871f0b8c95303199bee39e
3
+ metadata.gz: 3544ff81fdeafe60042fd5a29e4a3c5fb26b6091
4
+ data.tar.gz: e7d4c7ab4d38ba73ce1ba4967b2ededf94b8b53c
5
5
  SHA512:
6
- metadata.gz: 93599a158af6881b4a0bff6d580ecc7f3324669bdef4a9a8781aa7772d7372e392fc4bfadb44e3688605c2c5ea0a792fe86e4ff0f1e0e2c4809895c17d9fe35e
7
- data.tar.gz: a0e8fa514b19948d4725f35f152aaa612ba359f30abe7108e5ab7afc0a1edbc556e4d513650213e2d875ead4215f27f764bd80faaf9662bf8b2426e40d8a5797
6
+ metadata.gz: 0a1087bc60e810ba53ea0554f762f78e4d4f2359d167a2788e92d9d6cd64b290b57228fba4b6f4c407bc8e682a4bc654b8652542de3798457a4310dbf921f0a2
7
+ data.tar.gz: ba370480e93a8578499231f5ac784f59820a6239089865d2a5bcd6b91dd22ea7767229608a86a08024321fff29dde495d2d0d172009869737779fa871b9defeb
@@ -35,14 +35,21 @@ module SimpleCommand
35
35
  @errors ||= {}
36
36
  end
37
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
48
+ end
49
+
38
50
  private
39
51
 
40
52
  def performed?
41
53
  @performed ||= false
42
54
  end
43
-
44
- def add_error(key, value)
45
- errors[key] ||= []
46
- errors[key] << value
47
- end
48
55
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleCommand
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -79,6 +79,39 @@ describe SimpleCommand do
79
79
  end
80
80
  end
81
81
 
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
+
82
115
  describe '#errors' do
83
116
  let(:errors) { command.perform.errors }
84
117
 
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
4
+ version: 0.0.5
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-09 00:00:00.000000000 Z
11
+ date: 2015-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler