kalibro_client 0.0.1 → 0.0.2

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.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/features/kalibro_configuration/all.feature +6 -6
  4. data/features/kalibro_configuration/creation.feature +5 -5
  5. data/features/kalibro_configuration/destroy.feature +6 -6
  6. data/features/kalibro_configuration/metric_configurations.feature +4 -4
  7. data/features/{range → kalibro_range}/destroy.feature +2 -2
  8. data/features/{range → kalibro_range}/exists.feature +2 -2
  9. data/features/{range → kalibro_range}/find.feature +2 -2
  10. data/features/{range → kalibro_range}/ranges_of.feature +4 -4
  11. data/features/{range → kalibro_range}/save.feature +2 -2
  12. data/features/kalibro_range/update.feature +54 -0
  13. data/features/metric_configuration/creation.feature +2 -2
  14. data/features/metric_configuration/destroy.feature +2 -2
  15. data/features/metric_configuration/find.feature +2 -2
  16. data/features/metric_configuration/metric_configurations_of.feature +8 -8
  17. data/features/metric_result/descendant_values.feature +2 -2
  18. data/features/metric_result/history_of.feature +2 -2
  19. data/features/metric_result/metric_results_of.feature +2 -2
  20. data/features/module_result/children.feature +2 -2
  21. data/features/module_result/find.feature +2 -2
  22. data/features/module_result/history_of.feature +2 -2
  23. data/features/processing/first_processing_after.feature +2 -2
  24. data/features/processing/first_processing_of.feature +2 -2
  25. data/features/processing/has_processing.feature +2 -2
  26. data/features/processing/has_processing_after.feature +2 -2
  27. data/features/processing/has_processing_before.feature +2 -2
  28. data/features/processing/has_ready_processing.feature +2 -2
  29. data/features/processing/last_processing_before.feature +2 -2
  30. data/features/processing/last_processing_of.feature +2 -2
  31. data/features/processing/last_processing_state_of.feature +2 -2
  32. data/features/processing/last_ready_processing_of.feature +2 -2
  33. data/features/processing/processing_of.feature +4 -4
  34. data/features/processing/processing_with_date_of.feature +4 -4
  35. data/features/project/update.feature +13 -0
  36. data/features/repository/all.feature +1 -1
  37. data/features/repository/cancel_processing.feature +1 -1
  38. data/features/repository/destroy.feature +1 -1
  39. data/features/repository/exists.feature +1 -1
  40. data/features/repository/find.feature +1 -1
  41. data/features/repository/of.feature +1 -1
  42. data/features/repository/process.feature +2 -2
  43. data/features/step_definitions/kalibro_configuration_steps.rb +40 -0
  44. data/features/step_definitions/metric_configuration_steps.rb +9 -9
  45. data/features/step_definitions/module_result_steps.rb +1 -1
  46. data/features/step_definitions/project_steps.rb +12 -0
  47. data/features/step_definitions/range_steps.rb +25 -1
  48. data/features/step_definitions/reading_steps.rb +1 -1
  49. data/features/step_definitions/repository_steps.rb +1 -1
  50. data/lib/kalibro_client/entities/base.rb +53 -19
  51. data/lib/kalibro_client/entities/configurations/base.rb +4 -1
  52. data/lib/kalibro_client/entities/configurations/kalibro_configuration.rb +1 -1
  53. data/lib/kalibro_client/entities/configurations/kalibro_range.rb +8 -8
  54. data/lib/kalibro_client/entities/configurations/metric_configuration.rb +7 -5
  55. data/lib/kalibro_client/entities/configurations/reading.rb +4 -4
  56. data/lib/kalibro_client/entities/configurations/reading_group.rb +4 -0
  57. data/lib/kalibro_client/entities/processor/base.rb +2 -1
  58. data/lib/kalibro_client/entities/processor/kalibro_module.rb +1 -0
  59. data/lib/kalibro_client/entities/processor/metric_collector_details.rb +7 -2
  60. data/lib/kalibro_client/entities/processor/metric_result.rb +9 -10
  61. data/lib/kalibro_client/entities/processor/module_result.rb +10 -2
  62. data/lib/kalibro_client/entities/processor/processing.rb +26 -10
  63. data/lib/kalibro_client/entities/processor/project.rb +4 -0
  64. data/lib/kalibro_client/entities/processor/repository.rb +63 -4
  65. data/lib/kalibro_client/helpers/date_attributes.rb +11 -0
  66. data/lib/kalibro_client/helpers/request_methods.rb +9 -0
  67. data/lib/kalibro_client/version.rb +1 -1
  68. data/spec/entities/base_spec.rb +106 -24
  69. data/spec/entities/configurations/kalibro_configuration_spec.rb +8 -8
  70. data/spec/entities/configurations/kalibro_range_spec.rb +18 -24
  71. data/spec/entities/configurations/metric_configuration_spec.rb +22 -23
  72. data/spec/entities/configurations/reading_group_spec.rb +27 -0
  73. data/spec/entities/configurations/reading_spec.rb +15 -7
  74. data/spec/entities/processor/metric_collector_details_spec.rb +19 -7
  75. data/spec/entities/processor/metric_result_spec.rb +40 -54
  76. data/spec/entities/processor/module_result_spec.rb +52 -3
  77. data/spec/entities/processor/processing_spec.rb +35 -92
  78. data/spec/entities/processor/project_spec.rb +52 -5
  79. data/spec/entities/processor/repository_spec.rb +255 -5
  80. data/spec/factories/kalibro_configurations.rb +3 -3
  81. data/spec/factories/kalibro_ranges.rb +9 -3
  82. data/spec/factories/metrics.rb +1 -1
  83. data/spec/factories/readings.rb +1 -1
  84. data/spec/factories/repositories.rb +1 -1
  85. data/spec/helpers/date_attributes_spec.rb +30 -0
  86. metadata +21 -14
  87. data/features/step_definitions/configuration_steps.rb +0 -40
@@ -15,5 +15,5 @@
15
15
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
 
17
17
  module KalibroClient
18
- VERSION = "0.0.1"
18
+ VERSION = "0.0.2"
19
19
  end
@@ -104,37 +104,105 @@ describe KalibroClient::Entities::Base do
104
104
 
105
105
  describe 'to_objects_array' do
106
106
  it 'should convert [{}] to [Model]' do
107
- expect(KalibroClient::Entities::Base.to_objects_array({})).to eq([FactoryGirl.build(:model)])
107
+ expect(KalibroClient::Entities::Base.to_objects_array({})).to eq([FactoryGirl.build(:model)])
108
108
  end
109
109
 
110
110
  it 'should remain an array if it already is one' do
111
111
  object = Object.new
112
- expect(KalibroClient::Entities::Base.to_objects_array([object])).to eq([object])
112
+ expect(KalibroClient::Entities::Base.to_objects_array([object])).to eq([object])
113
113
  end
114
114
  end
115
115
 
116
116
  describe 'save' do
117
- before :each do
118
- KalibroClient::Entities::Base.
119
- expects(:request).
120
- with('', {base: {}}, :post, '').returns({"base" => {'id' => 42, 'kalibro_errors' => []}})
117
+ context "when it is not persisted" do
118
+ context "when it doesn't have the method id=" do
119
+ before :each do
120
+ KalibroClient::Entities::Base.
121
+ expects(:request).
122
+ with('', {base: {}}, :post, '').returns({"base" => {'id' => 42, 'kalibro_errors' => []}})
123
+ end
124
+
125
+ it 'should make a request to save model with id returning false and an error' do
126
+ expect(subject.save).to be(false)
127
+ expect(subject.kalibro_errors[0]).to be_a(NoMethodError)
128
+ end
129
+ end
130
+
131
+ context 'when it has the method id=' do
132
+ before :each do
133
+ KalibroClient::Entities::Base.
134
+ expects(:request).
135
+ with('', {base: {}}, :post, '').returns({"base" => {'id' => 42, 'kalibro_errors' => []}})
136
+ KalibroClient::Entities::Base.any_instance.expects(:id=).with(42).returns(42)
137
+ end
138
+
139
+ it 'should make a request to save model with id and return true without errors' do
140
+ expect(subject.save).to be(true)
141
+ expect(subject.kalibro_errors).to be_empty
142
+ end
143
+ end
144
+
145
+ context "when it returns with a kalibro processor error" do
146
+ before :each do
147
+ KalibroClient::Entities::Base.
148
+ expects(:request).
149
+ with('', {base: {}}, :post, '').returns({"errors" => ["Name has already been taken"]})
150
+ end
151
+
152
+ it 'should make a request to save model returning false and a kalibro error' do
153
+ expect(subject.save).to be(false)
154
+ expect(subject.kalibro_errors[0]).to eq("Name has already been taken")
155
+ end
156
+ end
121
157
  end
122
158
 
123
- context "when it doesn't have the method id=" do
124
- it 'should make a request to save model with id returning false and an error' do
125
- expect(subject.save).to be(false)
126
- expect(subject.kalibro_errors[0]).to be_a(NoMethodError)
159
+ context 'when it is persisted' do
160
+ before :each do
161
+ subject.persisted = true
162
+ end
163
+
164
+ it 'is expected to call the update method' do
165
+ subject.expects(:update)
166
+
167
+ subject.save
127
168
  end
128
169
  end
170
+ end
129
171
 
130
- context 'when it has the method id=' do
172
+ describe 'update' do
173
+ let!(:id) { 42 }
174
+
175
+ context 'with valid parameters' do
131
176
  before :each do
132
- KalibroClient::Entities::Base.any_instance.expects(:id=).with(42).returns(42)
177
+ KalibroClient::Entities::Base.
178
+ expects(:request).
179
+ with(':id', {base: {}, id: id}, :put, '').returns({"base" => {'id' => id, 'kalibro_errors' => []}})
180
+ subject.expects(:id).returns(id)
181
+ subject.expects(:to_hash).returns({})
133
182
  end
134
183
 
135
- it 'should make a request to save model with id and return true without errors' do
136
- expect(subject.save).to be(true)
137
- expect(subject.kalibro_errors).to be_empty
184
+ it 'is expect to return true' do
185
+ expect(subject.update).to be_truthy
186
+ end
187
+ end
188
+
189
+ context 'with invalid parameters' do
190
+ before :each do
191
+ KalibroClient::Entities::Base.
192
+ expects(:request).
193
+ with(':id', {base: {}, id: id}, :put, '').returns({"errors" => ["Error"]})
194
+ subject.expects(:id).returns(id)
195
+ subject.expects(:to_hash).returns({})
196
+ end
197
+
198
+ it 'is expect to return false' do
199
+ expect(subject.update).to be_falsey
200
+ end
201
+
202
+ it 'is expect fill the errors' do
203
+ subject.update
204
+
205
+ expect(subject.kalibro_errors).to_not be_empty
138
206
  end
139
207
  end
140
208
  end
@@ -175,7 +243,7 @@ describe KalibroClient::Entities::Base do
175
243
  subject.expects(:variable_names).returns(["answer"])
176
244
  subject.expects(:send).with("answer").returns(42)
177
245
  another_model.expects(:send).with("answer").returns(41)
178
- end
246
+ end
179
247
 
180
248
  it 'should return false' do
181
249
  expect(subject).not_to eq(another_model)
@@ -248,25 +316,39 @@ describe KalibroClient::Entities::Base do
248
316
  context 'when it gets successfully destroyed' do
249
317
  before :each do
250
318
  subject.expects(:id).at_least_once.returns(42)
251
- KalibroClient::Entities::Base.expects(:request).with(':id',{id: subject.id}, :delete, '')
319
+ KalibroClient::Entities::Base.expects(:request).with(':id',{id: subject.id}, :delete, '').returns({})
252
320
  end
253
321
 
254
- it 'should remain with the errors array empty' do
322
+ it 'should remain with the errors array empty and not persisted' do
255
323
  subject.destroy
256
324
  expect(subject.kalibro_errors).to be_empty
325
+ expect(subject.persisted?).to be_falsey
257
326
  end
258
327
  end
259
328
 
260
329
  context 'when the destruction fails' do
261
- before :each do
262
- subject.expects(:id).at_least_once.returns(42)
263
- KalibroClient::Entities::Base.expects(:request).with(':id',{id: subject.id}, :delete, '').raises(Exception.new)
330
+ context 'raising a exception' do
331
+ before :each do
332
+ subject.expects(:id).at_least_once.returns(42)
333
+ KalibroClient::Entities::Base.expects(:request).with(':id',{id: subject.id}, :delete, '').raises(Exception.new)
334
+ end
335
+
336
+ it "should have an exception inside it's errors" do
337
+ subject.destroy
338
+
339
+ expect(subject.kalibro_errors[0]).to be_an(Exception)
340
+ end
264
341
  end
265
342
 
266
- it "should have an exception inside it's errors" do
267
- subject.destroy
343
+ context 'returning kalibro_errors' do
344
+ before :each do
345
+ subject.expects(:id).at_least_once.returns(42)
346
+ KalibroClient::Entities::Base.expects(:request).with(':id',{id: subject.id}, :delete, '').returns({'errors' => ['Error']})
347
+ end
268
348
 
269
- expect(subject.kalibro_errors[0]).to be_an(Exception)
349
+ it 'is expected to return false' do
350
+ expect(subject.destroy).to be_falsey
351
+ end
270
352
  end
271
353
  end
272
354
  end
@@ -5,7 +5,7 @@
5
5
  # it under the terms of the GNU General Public License as published by
6
6
  # the Free Software Foundation, either version 3 of the License, or
7
7
  # (at your option) any later version.
8
- #
8
+ #
9
9
  # This program is distributed in the hope that it will be useful,
10
10
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
11
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -39,22 +39,22 @@ describe KalibroClient::Entities::Configurations::KalibroConfiguration do
39
39
  end
40
40
 
41
41
  context 'with many configurations' do
42
- let(:configuration) { FactoryGirl.build(:configuration_with_id) }
43
- let(:another_configuration) { FactoryGirl.build(:another_configuration) }
42
+ let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration_with_id) }
43
+ let(:another_kalibro_configuration) { FactoryGirl.build(:another_kalibro_configuration) }
44
44
 
45
45
  before :each do
46
46
  KalibroClient::Entities::Configurations::KalibroConfiguration.
47
47
  expects(:request).
48
48
  with('', {}, :get).
49
- returns({'kalibro_configurations' => [configuration.to_hash, another_configuration.to_hash]})
49
+ returns({'kalibro_configurations' => [kalibro_configuration.to_hash, another_kalibro_configuration.to_hash]})
50
50
  end
51
51
 
52
52
  it 'should return the two elements' do
53
- configurations = KalibroClient::Entities::Configurations::KalibroConfiguration.all
53
+ kalibro_configurations = KalibroClient::Entities::Configurations::KalibroConfiguration.all
54
54
 
55
- expect(configurations.size).to eq(2)
56
- expect(configurations.first.name).to eq(configuration.name)
57
- expect(configurations.last.name).to eq(another_configuration.name)
55
+ expect(kalibro_configurations.size).to eq(2)
56
+ expect(kalibro_configurations.first.name).to eq(kalibro_configuration.name)
57
+ expect(kalibro_configurations.last.name).to eq(another_kalibro_configuration.name)
58
58
  end
59
59
  end
60
60
  end
@@ -33,30 +33,6 @@ describe KalibroClient::Entities::Configurations::KalibroRange do
33
33
  end
34
34
  end
35
35
 
36
- describe 'beginning=' do
37
- it 'should set the value of the attribute as a float' do
38
- subject.beginning = "12.3"
39
- expect(subject.beginning).to eq(12.3)
40
- end
41
-
42
- it 'should set beginning to infinity' do
43
- subject.beginning = "-INF"
44
- expect(subject.beginning).to eq("-INF")
45
- end
46
- end
47
-
48
- describe 'end=' do
49
- it 'should set the value of the attribute as a float' do
50
- subject.end = "23.4"
51
- expect(subject.end).to eq(23.4)
52
- end
53
-
54
- it 'should set end to infinity' do
55
- subject.end = "INF"
56
- expect(subject.end).to eq("INF")
57
- end
58
- end
59
-
60
36
  describe 'getting reading attribute' do
61
37
  let(:reading) { FactoryGirl.build(:reading_with_id) }
62
38
 
@@ -171,4 +147,22 @@ describe KalibroClient::Entities::Configurations::KalibroRange do
171
147
  subject.destroy
172
148
  end
173
149
  end
150
+
151
+ # The only purpose of this test is to cover the overrided update_params method
152
+ describe 'update' do
153
+ subject {FactoryGirl.build(:range_with_id)}
154
+
155
+ before :each do
156
+ subject.end = "555"
157
+ KalibroClient::Entities::Configurations::KalibroRange.
158
+ expects(:request).
159
+ with(':id', {:kalibro_range => subject.to_hash, :id => subject.id}, :put, "metric_configurations/#{subject.metric_configuration_id}").
160
+ returns("errors" => nil)
161
+ end
162
+
163
+ it 'should make a request to updatethe model and return true without errors' do
164
+ expect(subject.update).to be(true)
165
+ expect(subject.kalibro_errors).to be_empty
166
+ end
167
+ end
174
168
  end
@@ -34,22 +34,6 @@ describe KalibroClient::Entities::Configurations::MetricConfiguration do
34
34
  describe 'metric=' do
35
35
 
36
36
  context 'with a Hash' do
37
- context 'Metric' do
38
- let!(:metric) { FactoryGirl.build(:metric) }
39
-
40
- before :each do
41
- KalibroClient::Entities::Miscellaneous::Metric.
42
- expects(:to_object).at_least_once.
43
- with(metric.to_hash).
44
- returns(metric)
45
- end
46
-
47
- it 'should convert the argument and set the metric' do
48
- subject.metric = metric.to_hash
49
- expect(subject.metric).to eq(metric)
50
- end
51
- end
52
-
53
37
  context 'NativeMetric' do
54
38
  let!(:metric) { FactoryGirl.build(:loc) }
55
39
 
@@ -130,23 +114,23 @@ describe KalibroClient::Entities::Configurations::MetricConfiguration do
130
114
  subject {FactoryGirl.build(:metric_configuration_with_id)}
131
115
 
132
116
  it 'should not include the configuration_id' do
133
- expect(subject.to_hash[:configuration_id]).to be_nil
117
+ expect(subject.to_hash[:kalibro_configuration_id]).to be_nil
134
118
  end
135
119
  end
136
120
 
137
121
  describe 'metric_configurations_of' do
138
122
  let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) }
139
- let(:configuration) { FactoryGirl.build(:configuration_with_id) }
123
+ let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration_with_id) }
140
124
 
141
125
  before :each do
142
126
  KalibroClient::Entities::Configurations::MetricConfiguration.
143
127
  expects(:request).
144
- with('', {}, :get, "kalibro_configurations/#{configuration.id}").
128
+ with('', {}, :get, "kalibro_configurations/#{kalibro_configuration.id}").
145
129
  returns({'metric_configurations' => [metric_configuration.to_hash]})
146
130
  end
147
131
 
148
132
  it 'should return a array with a metric configuration' do
149
- metric_configurations = KalibroClient::Entities::Configurations::MetricConfiguration.metric_configurations_of(configuration.id)
133
+ metric_configurations = KalibroClient::Entities::Configurations::MetricConfiguration.metric_configurations_of(kalibro_configuration.id)
150
134
 
151
135
  expect(metric_configurations).to be_an(Array)
152
136
  expect(metric_configurations.first.id).to eq(metric_configuration.id)
@@ -213,12 +197,10 @@ describe KalibroClient::Entities::Configurations::MetricConfiguration do
213
197
 
214
198
  context 'with an inexistant MetricConfiguration' do
215
199
  before :each do
216
- any_code = rand(Time.now.to_i)
217
- any_error_message = ""
218
200
  KalibroClient::Entities::Configurations::MetricConfiguration.
219
201
  expects(:request).
220
202
  with(':id', {id: metric_configuration.id}, :get).
221
- returns({'error' => 'RecordNotFound'})
203
+ returns({'errors' => 'RecordNotFound'})
222
204
  end
223
205
 
224
206
  it 'should raise the RecordNotFound error' do
@@ -227,4 +209,21 @@ describe KalibroClient::Entities::Configurations::MetricConfiguration do
227
209
  end
228
210
  end
229
211
  end
212
+
213
+ describe 'kalibro ranges' do
214
+ let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) }
215
+ let(:kalibro_range_1) { FactoryGirl.build(:range, metric_configuration_id: metric_configuration.id) }
216
+ let(:kalibro_range_2) { FactoryGirl.build(:range, metric_configuration_id: metric_configuration.id) }
217
+
218
+ before :each do
219
+ KalibroClient::Entities::Configurations::MetricConfiguration.
220
+ expects(:request).
221
+ with(':id/kalibro_ranges', {id: metric_configuration.id}, :get).
222
+ returns({'kalibro_ranges' => [kalibro_range_1.to_hash, kalibro_range_2.to_hash]})
223
+ end
224
+
225
+ it 'should return the kalibro ranges of a metric configuration' do
226
+ expect(metric_configuration.kalibro_ranges).to eq([kalibro_range_1, kalibro_range_2])
227
+ end
228
+ end
230
229
  end
@@ -57,4 +57,31 @@ describe KalibroClient::Entities::Configurations::ReadingGroup do
57
57
  end
58
58
  end
59
59
  end
60
+
61
+ describe 'readings' do
62
+ let(:reading_group) { FactoryGirl.build(:reading_group_with_id) }
63
+
64
+ context 'with readings' do
65
+ let(:reading_1) { FactoryGirl.build(:reading, reading_group_id: reading_group.id) }
66
+ let(:reading_2) { FactoryGirl.build(:reading, reading_group_id: reading_group.id) }
67
+
68
+ before :each do
69
+ KalibroClient::Entities::Configurations::ReadingGroup.expects(:request).with(":id/readings", {id: reading_group.id}, :get).returns({"readings" => [reading_1.to_hash, reading_2.to_hash]})
70
+ end
71
+
72
+ it 'should return an array of readings' do
73
+ expect(reading_group.readings).to eq([reading_1, reading_2])
74
+ end
75
+ end
76
+
77
+ context 'without readings' do
78
+ before :each do
79
+ KalibroClient::Entities::Configurations::ReadingGroup.expects(:request).with(":id/readings", {id: reading_group.id}, :get).returns({"readings" => []})
80
+ end
81
+
82
+ it 'should return an empty array' do
83
+ expect(reading_group.readings).to eq([])
84
+ end
85
+ end
86
+ end
60
87
  end
@@ -24,13 +24,6 @@ describe KalibroClient::Entities::Configurations::Reading do
24
24
  end
25
25
  end
26
26
 
27
- describe "grade=" do
28
- it 'should set the grade attribute as a float' do
29
- subject.grade = "44.7"
30
- expect(subject.grade).to eq(44.7)
31
- end
32
- end
33
-
34
27
  context 'static methods' do
35
28
  let(:reading) { FactoryGirl.build(:reading_with_id) }
36
29
  describe 'readings_of' do
@@ -84,4 +77,19 @@ describe KalibroClient::Entities::Configurations::Reading do
84
77
  subject.destroy
85
78
  end
86
79
  end
80
+
81
+ # The only purpose of this test is to cover the overridden update_prefix method
82
+ describe 'update' do
83
+ subject {FactoryGirl.build(:reading_with_id)}
84
+
85
+ before :each do
86
+ KalibroClient::Entities::Configurations::Reading.
87
+ expects(:request).
88
+ with(":id", {reading: subject.to_hash, id: subject.id}, :put, "reading_groups/#{subject.reading_group_id}").returns({})
89
+ end
90
+
91
+ it 'should make a request to update' do
92
+ subject.update
93
+ end
94
+ end
87
95
  end
@@ -119,11 +119,10 @@ describe KalibroClient::Entities::Processor::MetricCollectorDetails do
119
119
  end
120
120
 
121
121
  describe 'Supported Metrics' do
122
- let(:code_and_metric) { { "total_abstract_classes" => FactoryGirl.build(:metric) } }
123
- #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers
124
- let(:code_and_metric_parameter) { { "total_abstract_classes" => Hash[FactoryGirl.attributes_for(:metric)] } }
122
+ let(:code_and_metric) { { "total_abstract_classes" => FactoryGirl.build(:loc) } }
123
+ let(:code_and_metric_parameter) { { "total_abstract_classes" => FactoryGirl.build(:loc).to_hash } }
125
124
 
126
- context 'supported_metrics acessors' do
125
+ context 'supported_metrics accessors' do
127
126
  it 'should set the value of the array of supported metrics' do
128
127
  subject.supported_metrics = code_and_metric_parameter
129
128
  expect(subject.supported_metrics["total_abstract_classes"].to_hash).to eql(code_and_metric["total_abstract_classes"].to_hash)
@@ -131,16 +130,29 @@ describe KalibroClient::Entities::Processor::MetricCollectorDetails do
131
130
  end
132
131
  end
133
132
 
134
- describe 'metric' do
133
+ describe 'find_metric_by_name' do
135
134
  subject { FactoryGirl.build(:metric_collector_details) }
136
135
  let(:metric) { subject.supported_metrics["loc"] }
137
136
 
138
137
  it 'should return nil with an inexistent name' do
139
- expect(subject.metric("fake name")).to be_nil
138
+ expect(subject.find_metric_by_name("fake name")).to be_nil
140
139
  end
141
140
 
142
141
  it 'should return a metric with an existent name' do
143
- expect(subject.metric(metric.name).name).to eq(metric.name)
142
+ expect(subject.find_metric_by_name(metric.name)).to eq(metric)
143
+ end
144
+ end
145
+
146
+ describe 'find_metric_by_code' do
147
+ subject { FactoryGirl.build(:metric_collector_details) }
148
+ let(:metric) { subject.supported_metrics["loc"] }
149
+
150
+ it 'should return nil with an inexistent code' do
151
+ expect(subject.find_metric_by_code("fake code")).to be_nil
152
+ end
153
+
154
+ it 'should return a metric with an existent code' do
155
+ expect(subject.find_metric_by_code(metric.code)).to eq(metric)
144
156
  end
145
157
  end
146
158
  end