kalibro_client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +27 -0
- data/AUTHORS +4 -0
- data/COPYING +674 -0
- data/COPYING.LESSER +165 -0
- data/Gemfile +4 -0
- data/README.md +77 -0
- data/Rakefile +6 -0
- data/cucumber.yml +1 -0
- data/features/kalibro_configuration/all.feature +10 -0
- data/features/kalibro_configuration/creation.feature +9 -0
- data/features/kalibro_configuration/destroy.feature +10 -0
- data/features/kalibro_configuration/metric_configurations.feature +12 -0
- data/features/metric_collector_details/all_names.feature +8 -0
- data/features/metric_collector_details/find_by_name.feature +12 -0
- data/features/metric_configuration/creation.feature +11 -0
- data/features/metric_configuration/destroy.feature +12 -0
- data/features/metric_configuration/find.feature +18 -0
- data/features/metric_configuration/metric_configurations_of.feature +18 -0
- data/features/metric_result/descendant_values.feature +19 -0
- data/features/metric_result/history_of.feature +20 -0
- data/features/metric_result/metric_results_of.feature +20 -0
- data/features/module_result/children.feature +19 -0
- data/features/module_result/find.feature +22 -0
- data/features/module_result/history_of.feature +19 -0
- data/features/processing/first_processing_after.feature +18 -0
- data/features/processing/first_processing_of.feature +18 -0
- data/features/processing/has_processing.feature +18 -0
- data/features/processing/has_processing_after.feature +18 -0
- data/features/processing/has_processing_before.feature +18 -0
- data/features/processing/has_ready_processing.feature +18 -0
- data/features/processing/last_processing_before.feature +18 -0
- data/features/processing/last_processing_of.feature +18 -0
- data/features/processing/last_processing_state_of.feature +18 -0
- data/features/processing/last_ready_processing_of.feature +19 -0
- data/features/processing/processing_of.feature +32 -0
- data/features/processing/processing_with_date_of.feature +32 -0
- data/features/project/all.feature +10 -0
- data/features/project/creation.feature +9 -0
- data/features/project/destroy.feature +10 -0
- data/features/project/exists.feature +9 -0
- data/features/project/find.feature +10 -0
- data/features/range/destroy.feature +14 -0
- data/features/range/exists.feature +13 -0
- data/features/range/find.feature +14 -0
- data/features/range/ranges_of.feature +22 -0
- data/features/range/save.feature +14 -0
- data/features/reading/destroy.feature +13 -0
- data/features/reading/exists.feature +13 -0
- data/features/reading/find.feature +11 -0
- data/features/reading/readings_of.feature +11 -0
- data/features/reading_group/all.feature +10 -0
- data/features/reading_group/creation.feature +9 -0
- data/features/reading_group/destroy.feature +11 -0
- data/features/repository/all.feature +14 -0
- data/features/repository/cancel_processing.feature +14 -0
- data/features/repository/destroy.feature +14 -0
- data/features/repository/exists.feature +14 -0
- data/features/repository/find.feature +14 -0
- data/features/repository/of.feature +15 -0
- data/features/repository/process.feature +16 -0
- data/features/repository/types.feature +8 -0
- data/features/step_definitions/configuration_steps.rb +40 -0
- data/features/step_definitions/metric_collector_details_steps.rb +28 -0
- data/features/step_definitions/metric_configuration_steps.rb +61 -0
- data/features/step_definitions/metric_result_steps.rb +33 -0
- data/features/step_definitions/metric_steps.rb +3 -0
- data/features/step_definitions/module_result_steps.rb +46 -0
- data/features/step_definitions/processing_steps.rb +95 -0
- data/features/step_definitions/project_steps.rb +48 -0
- data/features/step_definitions/range_steps.rb +72 -0
- data/features/step_definitions/reading_group_steps.rb +36 -0
- data/features/step_definitions/reading_steps.rb +47 -0
- data/features/step_definitions/repository_steps.rb +71 -0
- data/features/support/env.rb +25 -0
- data/features/support/kalibro_cucumber_helpers.yml.sample +3 -0
- data/kalibro_client.gemspec +49 -0
- data/lib/kalibro_client.rb +62 -0
- data/lib/kalibro_client/entities.rb +40 -0
- data/lib/kalibro_client/entities/base.rb +196 -0
- data/lib/kalibro_client/entities/configurations/base.rb +13 -0
- data/lib/kalibro_client/entities/configurations/kalibro_configuration.rb +37 -0
- data/lib/kalibro_client/entities/configurations/kalibro_range.rb +77 -0
- data/lib/kalibro_client/entities/configurations/metric_configuration.rb +93 -0
- data/lib/kalibro_client/entities/configurations/range_snapshot.rb +37 -0
- data/lib/kalibro_client/entities/configurations/reading.rb +56 -0
- data/lib/kalibro_client/entities/configurations/reading_group.rb +34 -0
- data/lib/kalibro_client/entities/miscellaneous/base.rb +57 -0
- data/lib/kalibro_client/entities/miscellaneous/compound_metric.rb +21 -0
- data/lib/kalibro_client/entities/miscellaneous/date_metric_result.rb +14 -0
- data/lib/kalibro_client/entities/miscellaneous/date_module_result.rb +18 -0
- data/lib/kalibro_client/entities/miscellaneous/granularity.rb +54 -0
- data/lib/kalibro_client/entities/miscellaneous/metric.rb +19 -0
- data/lib/kalibro_client/entities/miscellaneous/native_metric.rb +24 -0
- data/lib/kalibro_client/entities/processor/base.rb +16 -0
- data/lib/kalibro_client/entities/processor/kalibro_module.rb +27 -0
- data/lib/kalibro_client/entities/processor/metric_collector_details.rb +53 -0
- data/lib/kalibro_client/entities/processor/metric_result.rb +79 -0
- data/lib/kalibro_client/entities/processor/module_result.rb +82 -0
- data/lib/kalibro_client/entities/processor/process_time.rb +31 -0
- data/lib/kalibro_client/entities/processor/processing.rb +109 -0
- data/lib/kalibro_client/entities/processor/project.rb +34 -0
- data/lib/kalibro_client/entities/processor/repository.rb +75 -0
- data/lib/kalibro_client/errors.rb +18 -0
- data/lib/kalibro_client/errors/record_not_found.rb +22 -0
- data/lib/kalibro_client/errors/standard.rb +24 -0
- data/lib/kalibro_client/helpers/aggregation_options.rb +25 -0
- data/lib/kalibro_client/helpers/hash_converters.rb +48 -0
- data/lib/kalibro_client/helpers/request_methods.rb +55 -0
- data/lib/kalibro_client/helpers/xml_converters.rb +20 -0
- data/lib/kalibro_client/kalibro_cucumber_helpers.rb +60 -0
- data/lib/kalibro_client/kalibro_cucumber_helpers/configuration.rb +30 -0
- data/lib/kalibro_client/kalibro_cucumber_helpers/hooks.rb +25 -0
- data/lib/kalibro_client/version.rb +19 -0
- data/lib/rake/test_task.rb +57 -0
- data/spec/entities/base_spec.rb +313 -0
- data/spec/entities/configurations/base_spec.rb +26 -0
- data/spec/entities/configurations/kalibro_configuration_spec.rb +91 -0
- data/spec/entities/configurations/kalibro_range_spec.rb +174 -0
- data/spec/entities/configurations/metric_configuration_spec.rb +230 -0
- data/spec/entities/configurations/range_snapshot_spec.rb +50 -0
- data/spec/entities/configurations/reading_group_spec.rb +60 -0
- data/spec/entities/configurations/reading_spec.rb +87 -0
- data/spec/entities/miscellaneous/base_spec.rb +49 -0
- data/spec/entities/miscellaneous/compound_metric_spec.rb +36 -0
- data/spec/entities/miscellaneous/date_metric_result_spec.rb +4 -0
- data/spec/entities/miscellaneous/date_module_result_spec.rb +0 -0
- data/spec/entities/miscellaneous/granularity_spec.rb +96 -0
- data/spec/entities/miscellaneous/metric_spec.rb +15 -0
- data/spec/entities/miscellaneous/native_metric_spec.rb +37 -0
- data/spec/entities/processor/base_spec.rb +26 -0
- data/spec/entities/processor/metric_collector_details_spec.rb +146 -0
- data/spec/entities/processor/metric_result_spec.rb +209 -0
- data/spec/entities/processor/module_result_spec.rb +178 -0
- data/spec/entities/processor/process_time_spec.rb +33 -0
- data/spec/entities/processor/processing_spec.rb +333 -0
- data/spec/entities/processor/project_spec.rb +68 -0
- data/spec/entities/processor/repository_spec.rb +140 -0
- data/spec/factories/date_metric_results.rb +30 -0
- data/spec/factories/date_module_results.rb +24 -0
- data/spec/factories/granularities.rb +23 -0
- data/spec/factories/kalibro_configurations.rb +34 -0
- data/spec/factories/kalibro_module.rb +28 -0
- data/spec/factories/kalibro_ranges.rb +40 -0
- data/spec/factories/metric_collector_details.rb +30 -0
- data/spec/factories/metric_configurations.rb +31 -0
- data/spec/factories/metric_results.rb +24 -0
- data/spec/factories/metrics.rb +48 -0
- data/spec/factories/models.rb +23 -0
- data/spec/factories/module_results.rb +43 -0
- data/spec/factories/process_times.rb +27 -0
- data/spec/factories/processings.rb +24 -0
- data/spec/factories/projects.rb +35 -0
- data/spec/factories/ranges_snapshot.rb +26 -0
- data/spec/factories/reading_groups.rb +28 -0
- data/spec/factories/readings.rb +30 -0
- data/spec/factories/repositories.rb +39 -0
- data/spec/helpers/aggregation_options_spec.rb +31 -0
- data/spec/helpers/hash_converters_spec.rb +111 -0
- data/spec/helpers/xml_converters_spec.rb +64 -0
- data/spec/kalibro_entities_spec.rb +112 -0
- data/spec/savon/fixtures/config.yml +2 -0
- data/spec/savon/fixtures/invalid_config.yml +2 -0
- data/spec/savon/fixtures/project/does_not_exists.xml +1 -0
- data/spec/savon/savon_test_helper.rb +14 -0
- data/spec/spec_helper.rb +111 -0
- metadata +479 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
# This file is part of KalibroClient
|
2
|
+
# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
require 'spec_helper'
|
18
|
+
|
19
|
+
describe KalibroClient::Entities::Processor::Base do
|
20
|
+
|
21
|
+
describe 'client' do
|
22
|
+
it 'returns a Faraday::Connection' do
|
23
|
+
expect(KalibroClient::Entities::Processor::Base.client).to be_a(Faraday::Connection)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
# This file is part of KalibroClient
|
2
|
+
# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
require 'spec_helper'
|
18
|
+
|
19
|
+
describe KalibroClient::Entities::Processor::MetricCollectorDetails do
|
20
|
+
describe 'all_names' do
|
21
|
+
context 'with no metric collector details' do
|
22
|
+
before :each do
|
23
|
+
KalibroClient::Entities::Processor::MetricCollectorDetails.
|
24
|
+
expects(:request).
|
25
|
+
with(:names, {}, :get).
|
26
|
+
returns({'names' => nil}.to_json)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should return empty array' do
|
30
|
+
expect(KalibroClient::Entities::Processor::MetricCollectorDetails.all_names).to be_empty
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'with many metric collector details' do
|
35
|
+
let(:metric_collector_details_hash) { FactoryGirl.build(:metric_collector_details).to_hash }
|
36
|
+
let(:another_metric_collector_details_hash) { FactoryGirl.build(:another_metric_collector_details).to_hash }
|
37
|
+
|
38
|
+
before :each do
|
39
|
+
KalibroClient::Entities::Processor::MetricCollectorDetails.
|
40
|
+
expects(:request).
|
41
|
+
with(:names, {}, :get).
|
42
|
+
returns({'metric_collector_names' => [metric_collector_details_hash[:name], another_metric_collector_details_hash[:name]]})
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should return the two elements' do
|
46
|
+
names = KalibroClient::Entities::Processor::MetricCollectorDetails.all_names
|
47
|
+
|
48
|
+
expect(names.size).to eq(2)
|
49
|
+
expect(names.first).to eq(metric_collector_details_hash[:name])
|
50
|
+
expect(names.last).to eq(another_metric_collector_details_hash[:name])
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe 'all' do
|
56
|
+
context 'with no metric collector details' do
|
57
|
+
before :each do
|
58
|
+
KalibroClient::Entities::Processor::MetricCollectorDetails.
|
59
|
+
expects(:request).
|
60
|
+
with('', {}, :get).
|
61
|
+
returns({"metric_collector_details" => nil})
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should return empty array' do
|
65
|
+
expect(KalibroClient::Entities::Processor::MetricCollectorDetails.all).to be_empty
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'with many metric collector details' do
|
70
|
+
let!(:metric_collector_details_hash) { FactoryGirl.attributes_for(:metric_collector_details) }
|
71
|
+
let!(:another_metric_collector_details_hash) { FactoryGirl.attributes_for(:another_metric_collector_details) }
|
72
|
+
|
73
|
+
before :each do
|
74
|
+
KalibroClient::Entities::Processor::MetricCollectorDetails.
|
75
|
+
expects(:request).
|
76
|
+
with('', {}, :get).
|
77
|
+
returns({"metric_collector_details" => [metric_collector_details_hash, another_metric_collector_details_hash]})
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should return the two elements' do
|
81
|
+
metric_collector_details = KalibroClient::Entities::Processor::MetricCollectorDetails.all
|
82
|
+
|
83
|
+
expect(metric_collector_details.size).to eq(2)
|
84
|
+
expect(metric_collector_details.first.name).to eq(metric_collector_details_hash[:name])
|
85
|
+
expect(metric_collector_details.last.name).to eq(another_metric_collector_details_hash[:name])
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe 'find_by_name' do
|
91
|
+
subject { FactoryGirl.build(:metric_collector_details) }
|
92
|
+
|
93
|
+
context 'with an inexistent name' do
|
94
|
+
before :each do
|
95
|
+
KalibroClient::Entities::Processor::MetricCollectorDetails.
|
96
|
+
expects(:request).
|
97
|
+
with(:find, {name: subject.name}).
|
98
|
+
returns(nil)
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should raise a RecordNotFound error' do
|
102
|
+
expect { KalibroClient::Entities::Processor::MetricCollectorDetails.find_by_name(subject.name)}.
|
103
|
+
to raise_error(KalibroClient::Errors::RecordNotFound)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'with an existent name' do
|
108
|
+
before :each do
|
109
|
+
KalibroClient::Entities::Processor::MetricCollectorDetails.
|
110
|
+
expects(:request).
|
111
|
+
with(:find,{name: subject.name}).
|
112
|
+
returns({"metric_collector_details" => subject.to_hash({except: ["supported_metrics"]})})
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should return a metric_collector_details' do
|
116
|
+
expect(KalibroClient::Entities::Processor::MetricCollectorDetails.find_by_name(subject.name).name).to eq(subject.name)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
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)] } }
|
125
|
+
|
126
|
+
context 'supported_metrics acessors' do
|
127
|
+
it 'should set the value of the array of supported metrics' do
|
128
|
+
subject.supported_metrics = code_and_metric_parameter
|
129
|
+
expect(subject.supported_metrics["total_abstract_classes"].to_hash).to eql(code_and_metric["total_abstract_classes"].to_hash)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe 'metric' do
|
135
|
+
subject { FactoryGirl.build(:metric_collector_details) }
|
136
|
+
let(:metric) { subject.supported_metrics["loc"] }
|
137
|
+
|
138
|
+
it 'should return nil with an inexistent name' do
|
139
|
+
expect(subject.metric("fake name")).to be_nil
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should return a metric with an existent name' do
|
143
|
+
expect(subject.metric(metric.name).name).to eq(metric.name)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,209 @@
|
|
1
|
+
# This file is part of KalibroClient
|
2
|
+
# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
require 'spec_helper'
|
18
|
+
|
19
|
+
describe KalibroClient::Entities::Processor::MetricResult do
|
20
|
+
let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) }
|
21
|
+
subject { FactoryGirl.build(:metric_result, metric_configuration_id: metric_configuration.id) }
|
22
|
+
|
23
|
+
describe 'new' do
|
24
|
+
context 'with value NaN' do
|
25
|
+
it 'should set the value with aggregated_value' do
|
26
|
+
attributes_hash = FactoryGirl.build(:metric_result, {"aggregated_value" => 1.6}).to_hash
|
27
|
+
attributes_hash["value"] = "NaN"
|
28
|
+
metric_result = KalibroClient::Entities::Processor::MetricResult.new(attributes_hash)
|
29
|
+
expect(metric_result.value).to eq(1.6)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'id=' do
|
35
|
+
it 'should set the value of the attribute id' do
|
36
|
+
subject.id = 42
|
37
|
+
expect(subject.id).to eq(42)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'metric_configuration=' do
|
42
|
+
it 'should set the metric configuration' do
|
43
|
+
subject.metric_configuration = metric_configuration
|
44
|
+
expect(subject.metric_configuration.weight).to eq(metric_configuration.weight)
|
45
|
+
expect(subject.metric_configuration.aggregation_form).to eq(metric_configuration.aggregation_form)
|
46
|
+
expect(subject.metric_configuration.reading_group_id).to eq(metric_configuration.reading_group_id)
|
47
|
+
expect(subject.metric_configuration.kalibro_configuration_id).to eq(metric_configuration.kalibro_configuration_id)
|
48
|
+
expect(subject.metric_configuration_id).to eq(metric_configuration.id)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'metric_configuration' do
|
53
|
+
|
54
|
+
context 'without a set metric configuration' do
|
55
|
+
it 'should fetch and return the metric configuration' do
|
56
|
+
KalibroClient::Entities::Configurations::MetricConfiguration.expects(:find).with(metric_configuration.id).returns(metric_configuration)
|
57
|
+
expect(subject.metric_configuration).to eq(metric_configuration)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'with a set metric configuration' do
|
62
|
+
before :each do
|
63
|
+
subject.metric_configuration = metric_configuration
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should only return the metric configuration' do
|
67
|
+
expect(subject.metric_configuration).to eq(metric_configuration)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should set the metric configuration id' do
|
71
|
+
expect(subject.metric_configuration_id).to eq(metric_configuration.id)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'value=' do
|
77
|
+
it 'should set the value of the attribute value' do
|
78
|
+
subject.value = 42
|
79
|
+
expect(subject.value).to eq(42)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe 'aggregated_value=' do
|
84
|
+
it 'should set the value of the attribute aggregated_value' do
|
85
|
+
subject.aggregated_value = 42
|
86
|
+
expect(subject.aggregated_value).to eq(42)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe 'descendant_values' do
|
91
|
+
context 'when there is one descendant value for the given metric_result' do
|
92
|
+
before :each do
|
93
|
+
KalibroClient::Entities::Processor::MetricResult.
|
94
|
+
expects(:request).
|
95
|
+
with(':id/descendant_values', { id: subject.id }, :get).
|
96
|
+
returns({'descendant_values' => [13.3]})
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'should return an unitary list with the descendant value' do
|
100
|
+
expect(subject.descendant_values).to eq([13.3])
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'when there is no descendant value for the given metric_result' do
|
105
|
+
before :each do
|
106
|
+
KalibroClient::Entities::Processor::MetricResult.
|
107
|
+
expects(:request).
|
108
|
+
with(':id/descendant_values', { id: subject.id }, :get).
|
109
|
+
returns({'descendant_values' => []})
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should return an empty list' do
|
113
|
+
expect(subject.descendant_values).to eq([])
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe 'metric_results_of' do
|
119
|
+
context 'when there is one metric result for the given module_result' do
|
120
|
+
before :each do
|
121
|
+
KalibroClient::Entities::Processor::ModuleResult.
|
122
|
+
expects(:request).
|
123
|
+
with(':id/metric_results', { id: 123 }, :get).
|
124
|
+
returns({'metric_results' => [subject.to_hash]})
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should return an unitary list with the metric result' do
|
128
|
+
expect(KalibroClient::Entities::Processor::MetricResult.metric_results_of(123).first.value).to eq(subject.value)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'when there is no metric result for the given module_result' do
|
133
|
+
before :each do
|
134
|
+
KalibroClient::Entities::Processor::ModuleResult.
|
135
|
+
expects(:request).
|
136
|
+
with(':id/metric_results', { :id => 42 }, :get).
|
137
|
+
returns({'metric_results' => []})
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'should return an empty list' do
|
141
|
+
expect(KalibroClient::Entities::Processor::MetricResult.metric_results_of(42)).to eq([])
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'when there are many metric results for the given module_result' do
|
146
|
+
before :each do
|
147
|
+
KalibroClient::Entities::Processor::ModuleResult.
|
148
|
+
expects(:request).
|
149
|
+
with(':id/metric_results', { :id => 28 }, :get).
|
150
|
+
returns({'metric_results' => [subject.to_hash, subject.to_hash]})
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'should return a list with the descendant results' do
|
154
|
+
expect(KalibroClient::Entities::Processor::MetricResult.metric_results_of(28).first.value).to eq(subject.value)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe 'history_of' do
|
160
|
+
let(:kalibro_module) { FactoryGirl.build(:kalibro_module_with_id) }
|
161
|
+
let(:metric) { FactoryGirl.build(:metric) }
|
162
|
+
let(:repository) { FactoryGirl.build(:repository_with_id) }
|
163
|
+
|
164
|
+
context 'when there is not a date metric result' do
|
165
|
+
before :each do
|
166
|
+
KalibroClient::Entities::Processor::Repository.
|
167
|
+
expects(:request).
|
168
|
+
with(':id/metric_result_history_of', {:metric_name => metric.name, :kalibro_module_id => kalibro_module.id, id: repository.id}).
|
169
|
+
returns({'metric_result_history_of' => []})
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should return an empty list' do
|
173
|
+
expect(KalibroClient::Entities::Processor::MetricResult.history_of(metric.name, kalibro_module.id, repository.id)).to eq([])
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context 'when there is only one date metric result' do
|
178
|
+
let!(:date_metric_result) { FactoryGirl.build(:date_metric_result, metric_result: subject.to_hash) }
|
179
|
+
|
180
|
+
before :each do
|
181
|
+
KalibroClient::Entities::Processor::Repository.
|
182
|
+
expects(:request).with(':id/metric_result_history_of', {:metric_name => metric.name, :kalibro_module_id => kalibro_module.id, id: repository.id})
|
183
|
+
.returns({'metric_result_history_of' => [date_metric_result.to_hash]})
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'should return the date metric result as an object into a list' do
|
187
|
+
expect(KalibroClient::Entities::Processor::MetricResult.history_of(metric.name, kalibro_module.id, repository.id).first.metric_result.id).to eq(subject.id)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
context 'when there are many date metric results' do
|
192
|
+
let(:date_metric_result) { FactoryGirl.build(:date_metric_result, {metric_result: subject.to_hash}) }
|
193
|
+
let(:another_date_metric_result) { FactoryGirl.build(:another_date_metric_result, {metric_result: subject.to_hash}) }
|
194
|
+
|
195
|
+
before :each do
|
196
|
+
KalibroClient::Entities::Processor::Repository.
|
197
|
+
expects(:request).
|
198
|
+
with(':id/metric_result_history_of', {:metric_name => metric.name, :kalibro_module_id => kalibro_module.id, id: repository.id}).
|
199
|
+
returns({'metric_result_history_of' => [date_metric_result.to_hash, another_date_metric_result.to_hash]})
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'should return a list of date metric results as objects' do
|
203
|
+
response = KalibroClient::Entities::Processor::MetricResult.history_of(metric.name, kalibro_module.id, repository.id)
|
204
|
+
expect(response.first.metric_result.id).to eq(date_metric_result.metric_result.id)
|
205
|
+
expect(response.last.metric_result.id).to eq(another_date_metric_result.metric_result.id)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
# This file is part of KalibroClient
|
2
|
+
# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
require 'spec_helper'
|
18
|
+
|
19
|
+
describe KalibroClient::Entities::Processor::ModuleResult do
|
20
|
+
subject { FactoryGirl.build(:module_result, id: rand(Time.now.to_i)) }
|
21
|
+
|
22
|
+
describe 'find' do
|
23
|
+
context 'when there is a module result for the given id' do
|
24
|
+
before :each do
|
25
|
+
KalibroClient::Entities::Processor::ModuleResult.
|
26
|
+
expects(:request).
|
27
|
+
with(':id/exists', { id: subject.id }, :get).
|
28
|
+
returns("exists" => true)
|
29
|
+
KalibroClient::Entities::Processor::ModuleResult.
|
30
|
+
expects(:request).
|
31
|
+
with(':id', { id: subject.id }, :get).
|
32
|
+
returns("module_result" => subject.to_hash)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should return a hash with module result' do
|
36
|
+
expect(KalibroClient::Entities::Processor::ModuleResult.
|
37
|
+
find(subject.id).id).to eq(subject.id)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "when there isn't a module result for the given id" do
|
42
|
+
before :each do
|
43
|
+
KalibroClient::Entities::Processor::ModuleResult.
|
44
|
+
expects(:request).
|
45
|
+
with(':id/exists', { id: subject.id }, :get).
|
46
|
+
returns("exists" => false)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should raise an error' do
|
50
|
+
expect {KalibroClient::Entities::Processor::ModuleResult.find(subject.id)}.
|
51
|
+
to raise_error KalibroClient::Errors::RecordNotFound
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'children' do
|
57
|
+
before :each do
|
58
|
+
KalibroClient::Entities::Processor::ModuleResult.
|
59
|
+
expects(:request).
|
60
|
+
with(':id/children', {id: subject.id}, :get).
|
61
|
+
returns({'module_results' => subject.to_hash})
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should return a list of objects' do
|
65
|
+
expect(subject.children).to eq [subject]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe 'parents' do
|
70
|
+
let(:root_module_result) { FactoryGirl.build(:root_module_result) }
|
71
|
+
|
72
|
+
context 'when module result has a parent' do
|
73
|
+
before :each do
|
74
|
+
KalibroClient::Entities::Processor::ModuleResult.
|
75
|
+
expects(:request).
|
76
|
+
with(':id/exists', { id: subject.parent_id }, :get).
|
77
|
+
returns("exists" => true)
|
78
|
+
KalibroClient::Entities::Processor::ModuleResult.
|
79
|
+
expects(:request).at_least_once.
|
80
|
+
with(':id', { id: subject.parent_id }, :get).
|
81
|
+
returns("module_result" => root_module_result.to_hash)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should return its parent' do
|
85
|
+
expect(subject.parents).to eq [root_module_result]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'when module result does not have a parent' do
|
90
|
+
it 'should return an empty list' do
|
91
|
+
expect(root_module_result.parents).to eq []
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe 'id=' do
|
97
|
+
it 'should set the id attribute as integer' do
|
98
|
+
subject.id = 23
|
99
|
+
expect(subject.id).to eq 23
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe 'kalibro_module' do
|
104
|
+
let(:kalibro_module) { FactoryGirl.build(:kalibro_module) }
|
105
|
+
|
106
|
+
before :each do
|
107
|
+
KalibroClient::Entities::Processor::ModuleResult.
|
108
|
+
expects(:request).once.
|
109
|
+
with(':id/kalibro_module', { id: subject.id }, :get).
|
110
|
+
returns("kalibro_module" => kalibro_module.to_hash)
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should return the kalibro_module' do
|
114
|
+
expect(subject.kalibro_module).to eq(kalibro_module)
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should not request the kalibro_module in cache' do
|
118
|
+
expect(subject.kalibro_module).to eq(kalibro_module)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe 'grade=' do
|
123
|
+
it 'should set the grade attribute as float' do
|
124
|
+
subject.grade = 12.5
|
125
|
+
expect(subject.grade).to eq 12.5
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe 'parent_id=' do
|
130
|
+
it 'should set the parent_id attribute as integer' do
|
131
|
+
subject.parent_id = 73
|
132
|
+
expect(subject.parent_id).to eq 73
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe 'history_of' do
|
137
|
+
let(:date_module_result) { FactoryGirl.build(:date_module_result) }
|
138
|
+
before :each do
|
139
|
+
KalibroClient::Entities::Processor::ModuleResult.
|
140
|
+
expects(:request).
|
141
|
+
with('history_of', {id: subject.id}).
|
142
|
+
returns({'date_module_results' => [[date_module_result.date, date_module_result.module_result.to_hash]]})
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'should return a list of date_module_results' do
|
146
|
+
date_module_results = KalibroClient::Entities::Processor::ModuleResult.history_of subject.id
|
147
|
+
expect(date_module_results.first.result).to eq date_module_result.result
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe 'folder? & file?' do
|
152
|
+
context 'when the module result has childrens' do
|
153
|
+
subject { FactoryGirl.build(:root_module_result) }
|
154
|
+
|
155
|
+
before :each do
|
156
|
+
subject.expects(:children).twice.returns([FactoryGirl.build(:module_result)])
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'should return true for folder? and false for file?' do
|
160
|
+
expect(subject.folder?).to be_truthy
|
161
|
+
expect(subject.file?).to be_falsey
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'when the module result has no childrens' do
|
166
|
+
subject { FactoryGirl.build(:module_result) }
|
167
|
+
|
168
|
+
before :each do
|
169
|
+
subject.expects(:children).twice.returns([])
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should return true for folder? and false for file?' do
|
173
|
+
expect(subject.folder?).to be_falsey
|
174
|
+
expect(subject.file?).to be_truthy
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|