kalibro_client 0.0.1

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 (171) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rspec +2 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +27 -0
  7. data/AUTHORS +4 -0
  8. data/COPYING +674 -0
  9. data/COPYING.LESSER +165 -0
  10. data/Gemfile +4 -0
  11. data/README.md +77 -0
  12. data/Rakefile +6 -0
  13. data/cucumber.yml +1 -0
  14. data/features/kalibro_configuration/all.feature +10 -0
  15. data/features/kalibro_configuration/creation.feature +9 -0
  16. data/features/kalibro_configuration/destroy.feature +10 -0
  17. data/features/kalibro_configuration/metric_configurations.feature +12 -0
  18. data/features/metric_collector_details/all_names.feature +8 -0
  19. data/features/metric_collector_details/find_by_name.feature +12 -0
  20. data/features/metric_configuration/creation.feature +11 -0
  21. data/features/metric_configuration/destroy.feature +12 -0
  22. data/features/metric_configuration/find.feature +18 -0
  23. data/features/metric_configuration/metric_configurations_of.feature +18 -0
  24. data/features/metric_result/descendant_values.feature +19 -0
  25. data/features/metric_result/history_of.feature +20 -0
  26. data/features/metric_result/metric_results_of.feature +20 -0
  27. data/features/module_result/children.feature +19 -0
  28. data/features/module_result/find.feature +22 -0
  29. data/features/module_result/history_of.feature +19 -0
  30. data/features/processing/first_processing_after.feature +18 -0
  31. data/features/processing/first_processing_of.feature +18 -0
  32. data/features/processing/has_processing.feature +18 -0
  33. data/features/processing/has_processing_after.feature +18 -0
  34. data/features/processing/has_processing_before.feature +18 -0
  35. data/features/processing/has_ready_processing.feature +18 -0
  36. data/features/processing/last_processing_before.feature +18 -0
  37. data/features/processing/last_processing_of.feature +18 -0
  38. data/features/processing/last_processing_state_of.feature +18 -0
  39. data/features/processing/last_ready_processing_of.feature +19 -0
  40. data/features/processing/processing_of.feature +32 -0
  41. data/features/processing/processing_with_date_of.feature +32 -0
  42. data/features/project/all.feature +10 -0
  43. data/features/project/creation.feature +9 -0
  44. data/features/project/destroy.feature +10 -0
  45. data/features/project/exists.feature +9 -0
  46. data/features/project/find.feature +10 -0
  47. data/features/range/destroy.feature +14 -0
  48. data/features/range/exists.feature +13 -0
  49. data/features/range/find.feature +14 -0
  50. data/features/range/ranges_of.feature +22 -0
  51. data/features/range/save.feature +14 -0
  52. data/features/reading/destroy.feature +13 -0
  53. data/features/reading/exists.feature +13 -0
  54. data/features/reading/find.feature +11 -0
  55. data/features/reading/readings_of.feature +11 -0
  56. data/features/reading_group/all.feature +10 -0
  57. data/features/reading_group/creation.feature +9 -0
  58. data/features/reading_group/destroy.feature +11 -0
  59. data/features/repository/all.feature +14 -0
  60. data/features/repository/cancel_processing.feature +14 -0
  61. data/features/repository/destroy.feature +14 -0
  62. data/features/repository/exists.feature +14 -0
  63. data/features/repository/find.feature +14 -0
  64. data/features/repository/of.feature +15 -0
  65. data/features/repository/process.feature +16 -0
  66. data/features/repository/types.feature +8 -0
  67. data/features/step_definitions/configuration_steps.rb +40 -0
  68. data/features/step_definitions/metric_collector_details_steps.rb +28 -0
  69. data/features/step_definitions/metric_configuration_steps.rb +61 -0
  70. data/features/step_definitions/metric_result_steps.rb +33 -0
  71. data/features/step_definitions/metric_steps.rb +3 -0
  72. data/features/step_definitions/module_result_steps.rb +46 -0
  73. data/features/step_definitions/processing_steps.rb +95 -0
  74. data/features/step_definitions/project_steps.rb +48 -0
  75. data/features/step_definitions/range_steps.rb +72 -0
  76. data/features/step_definitions/reading_group_steps.rb +36 -0
  77. data/features/step_definitions/reading_steps.rb +47 -0
  78. data/features/step_definitions/repository_steps.rb +71 -0
  79. data/features/support/env.rb +25 -0
  80. data/features/support/kalibro_cucumber_helpers.yml.sample +3 -0
  81. data/kalibro_client.gemspec +49 -0
  82. data/lib/kalibro_client.rb +62 -0
  83. data/lib/kalibro_client/entities.rb +40 -0
  84. data/lib/kalibro_client/entities/base.rb +196 -0
  85. data/lib/kalibro_client/entities/configurations/base.rb +13 -0
  86. data/lib/kalibro_client/entities/configurations/kalibro_configuration.rb +37 -0
  87. data/lib/kalibro_client/entities/configurations/kalibro_range.rb +77 -0
  88. data/lib/kalibro_client/entities/configurations/metric_configuration.rb +93 -0
  89. data/lib/kalibro_client/entities/configurations/range_snapshot.rb +37 -0
  90. data/lib/kalibro_client/entities/configurations/reading.rb +56 -0
  91. data/lib/kalibro_client/entities/configurations/reading_group.rb +34 -0
  92. data/lib/kalibro_client/entities/miscellaneous/base.rb +57 -0
  93. data/lib/kalibro_client/entities/miscellaneous/compound_metric.rb +21 -0
  94. data/lib/kalibro_client/entities/miscellaneous/date_metric_result.rb +14 -0
  95. data/lib/kalibro_client/entities/miscellaneous/date_module_result.rb +18 -0
  96. data/lib/kalibro_client/entities/miscellaneous/granularity.rb +54 -0
  97. data/lib/kalibro_client/entities/miscellaneous/metric.rb +19 -0
  98. data/lib/kalibro_client/entities/miscellaneous/native_metric.rb +24 -0
  99. data/lib/kalibro_client/entities/processor/base.rb +16 -0
  100. data/lib/kalibro_client/entities/processor/kalibro_module.rb +27 -0
  101. data/lib/kalibro_client/entities/processor/metric_collector_details.rb +53 -0
  102. data/lib/kalibro_client/entities/processor/metric_result.rb +79 -0
  103. data/lib/kalibro_client/entities/processor/module_result.rb +82 -0
  104. data/lib/kalibro_client/entities/processor/process_time.rb +31 -0
  105. data/lib/kalibro_client/entities/processor/processing.rb +109 -0
  106. data/lib/kalibro_client/entities/processor/project.rb +34 -0
  107. data/lib/kalibro_client/entities/processor/repository.rb +75 -0
  108. data/lib/kalibro_client/errors.rb +18 -0
  109. data/lib/kalibro_client/errors/record_not_found.rb +22 -0
  110. data/lib/kalibro_client/errors/standard.rb +24 -0
  111. data/lib/kalibro_client/helpers/aggregation_options.rb +25 -0
  112. data/lib/kalibro_client/helpers/hash_converters.rb +48 -0
  113. data/lib/kalibro_client/helpers/request_methods.rb +55 -0
  114. data/lib/kalibro_client/helpers/xml_converters.rb +20 -0
  115. data/lib/kalibro_client/kalibro_cucumber_helpers.rb +60 -0
  116. data/lib/kalibro_client/kalibro_cucumber_helpers/configuration.rb +30 -0
  117. data/lib/kalibro_client/kalibro_cucumber_helpers/hooks.rb +25 -0
  118. data/lib/kalibro_client/version.rb +19 -0
  119. data/lib/rake/test_task.rb +57 -0
  120. data/spec/entities/base_spec.rb +313 -0
  121. data/spec/entities/configurations/base_spec.rb +26 -0
  122. data/spec/entities/configurations/kalibro_configuration_spec.rb +91 -0
  123. data/spec/entities/configurations/kalibro_range_spec.rb +174 -0
  124. data/spec/entities/configurations/metric_configuration_spec.rb +230 -0
  125. data/spec/entities/configurations/range_snapshot_spec.rb +50 -0
  126. data/spec/entities/configurations/reading_group_spec.rb +60 -0
  127. data/spec/entities/configurations/reading_spec.rb +87 -0
  128. data/spec/entities/miscellaneous/base_spec.rb +49 -0
  129. data/spec/entities/miscellaneous/compound_metric_spec.rb +36 -0
  130. data/spec/entities/miscellaneous/date_metric_result_spec.rb +4 -0
  131. data/spec/entities/miscellaneous/date_module_result_spec.rb +0 -0
  132. data/spec/entities/miscellaneous/granularity_spec.rb +96 -0
  133. data/spec/entities/miscellaneous/metric_spec.rb +15 -0
  134. data/spec/entities/miscellaneous/native_metric_spec.rb +37 -0
  135. data/spec/entities/processor/base_spec.rb +26 -0
  136. data/spec/entities/processor/metric_collector_details_spec.rb +146 -0
  137. data/spec/entities/processor/metric_result_spec.rb +209 -0
  138. data/spec/entities/processor/module_result_spec.rb +178 -0
  139. data/spec/entities/processor/process_time_spec.rb +33 -0
  140. data/spec/entities/processor/processing_spec.rb +333 -0
  141. data/spec/entities/processor/project_spec.rb +68 -0
  142. data/spec/entities/processor/repository_spec.rb +140 -0
  143. data/spec/factories/date_metric_results.rb +30 -0
  144. data/spec/factories/date_module_results.rb +24 -0
  145. data/spec/factories/granularities.rb +23 -0
  146. data/spec/factories/kalibro_configurations.rb +34 -0
  147. data/spec/factories/kalibro_module.rb +28 -0
  148. data/spec/factories/kalibro_ranges.rb +40 -0
  149. data/spec/factories/metric_collector_details.rb +30 -0
  150. data/spec/factories/metric_configurations.rb +31 -0
  151. data/spec/factories/metric_results.rb +24 -0
  152. data/spec/factories/metrics.rb +48 -0
  153. data/spec/factories/models.rb +23 -0
  154. data/spec/factories/module_results.rb +43 -0
  155. data/spec/factories/process_times.rb +27 -0
  156. data/spec/factories/processings.rb +24 -0
  157. data/spec/factories/projects.rb +35 -0
  158. data/spec/factories/ranges_snapshot.rb +26 -0
  159. data/spec/factories/reading_groups.rb +28 -0
  160. data/spec/factories/readings.rb +30 -0
  161. data/spec/factories/repositories.rb +39 -0
  162. data/spec/helpers/aggregation_options_spec.rb +31 -0
  163. data/spec/helpers/hash_converters_spec.rb +111 -0
  164. data/spec/helpers/xml_converters_spec.rb +64 -0
  165. data/spec/kalibro_entities_spec.rb +112 -0
  166. data/spec/savon/fixtures/config.yml +2 -0
  167. data/spec/savon/fixtures/invalid_config.yml +2 -0
  168. data/spec/savon/fixtures/project/does_not_exists.xml +1 -0
  169. data/spec/savon/savon_test_helper.rb +14 -0
  170. data/spec/spec_helper.rb +111 -0
  171. metadata +479 -0
@@ -0,0 +1,35 @@
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
+ FactoryGirl.define do
18
+ factory :project, class: KalibroClient::Entities::Processor::Project do
19
+ name "QtCalculator"
20
+ description "A simple calculator for us."
21
+
22
+ trait :with_id do
23
+ id 1
24
+ end
25
+
26
+ factory :project_with_id, traits: [:with_id]
27
+ end
28
+
29
+ factory :another_project, class: KalibroClient::Entities::Processor::Project do
30
+ id 42
31
+ name "Kalibro"
32
+ description "A Kalibro description."
33
+ end
34
+
35
+ end
@@ -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
+ FactoryGirl.define do
18
+ factory :range_snapshot, class: KalibroClient::Entities::Configurations::RangeSnapshot do
19
+ beginning 1.1
20
+ self.end 5.1
21
+ label "Snapshot"
22
+ grade 10.1
23
+ color "FF2284"
24
+ comments "Comment"
25
+ end
26
+ end
@@ -0,0 +1,28 @@
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
+ FactoryGirl.define do
18
+ factory :reading_group, class: KalibroClient::Entities::Configurations::ReadingGroup do
19
+ name "Mussum"
20
+ description "Cacildis!"
21
+
22
+ trait :with_id do
23
+ id 1
24
+ end
25
+
26
+ factory :reading_group_with_id, traits: [:with_id]
27
+ end
28
+ end
@@ -0,0 +1,30 @@
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
+ FactoryGirl.define do
18
+ factory :reading, class: KalibroClient::Entities::Configurations::Reading do
19
+ label "Good"
20
+ grade 10.5
21
+ color "33dd33"
22
+ reading_group_id 31
23
+
24
+ trait :with_id do
25
+ id 42
26
+ end
27
+
28
+ factory :reading_with_id, traits: [:with_id]
29
+ end
30
+ end
@@ -0,0 +1,39 @@
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
+ FactoryGirl.define do
18
+ factory :repository, class: KalibroClient::Entities::Processor::Repository do
19
+ name "QtCalculator"
20
+ description "A simple calculator"
21
+ license "GPLv3"
22
+ period 1
23
+ scm_type "SVN"
24
+ address "svn://svn.code.sf.net/p/qt-calculator/code/trunk"
25
+ configuration_id 1
26
+ project_id 1
27
+ send_email "test@test.com"
28
+
29
+ trait :with_id do
30
+ id 1
31
+ end
32
+
33
+ factory :repository_with_id, traits: [:with_id]
34
+ end
35
+
36
+ factory :another_repository, class: KalibroClient::Entities::Processor::Repository, parent: :repository do
37
+ id 2
38
+ end
39
+ end
@@ -0,0 +1,31 @@
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
+ require 'kalibro_client/helpers/aggregation_options'
19
+
20
+ include AggregationOptions
21
+
22
+ describe 'all_with_label' do
23
+ it 'should return the list of aggregation methods available' do
24
+ expect(all_with_label).to eq(
25
+ [
26
+ ["Average","AVERAGE"], ["Median", "MEDIAN"], ["Maximum", "MAXIMUM"], ["Minimum", "MINIMUM"],
27
+ ["Count", "COUNT"], ["Standard Deviation", "STANDARD_DEVIATION"]
28
+ ]
29
+ )
30
+ end
31
+ end
@@ -0,0 +1,111 @@
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
+ require 'kalibro_client/helpers/hash_converters'
19
+
20
+ include HashConverters
21
+
22
+ describe HashConverters do
23
+ describe 'date_with_miliseconds' do
24
+ context 'with 21/12/1995 (first Ruby publication)' do
25
+ it 'should return 1995-12-21T00:00:00.0/1+00:00' do
26
+ expect(date_with_milliseconds(DateTime.parse("21/12/1995"))).to eq("1995-12-21T00:00:00.0/1+00:00")
27
+ end
28
+ end
29
+ end
30
+
31
+ describe 'convert_to_hash' do
32
+ context 'with a nil value' do
33
+ it 'should return nil' do
34
+ expect(convert_to_hash(nil)).to be_nil
35
+ end
36
+ end
37
+
38
+ context 'with an Array' do
39
+ before :each do
40
+ @array = []
41
+ @element1 = :kalibro
42
+
43
+ @array << @element1
44
+ end
45
+
46
+ it 'should return the Array wth its elements converted' do
47
+ expect(convert_to_hash(@array)[0]).to eq(@element1.to_s)
48
+ end
49
+ end
50
+
51
+ context 'with a Base' do
52
+ before :each do
53
+ @model = KalibroClient::Entities::Base.new
54
+ end
55
+
56
+ it "should return the Base's Hash" do
57
+ expect(convert_to_hash(@model)).to eq(@model.to_hash)
58
+ end
59
+ end
60
+
61
+ context 'with a DateTime' do
62
+ before :each do
63
+ @date = DateTime.parse("21/12/1995")
64
+ end
65
+
66
+ it 'should return th date with miliseconds' do
67
+ expect(convert_to_hash(@date)).to eq(date_with_milliseconds(@date))
68
+ end
69
+ end
70
+
71
+ context 'with an + infinite Float' do
72
+ it 'should return INF' do
73
+ expect(convert_to_hash(1.0/0.0)).to eq('INF')
74
+ end
75
+ end
76
+
77
+ context 'with an - infinite Float' do
78
+ it 'should return -INF' do
79
+ expect(convert_to_hash(-1.0/0.0)).to eq('-INF')
80
+ end
81
+ end
82
+ end
83
+
84
+ describe 'field_to_hash' do
85
+ context 'with a nil field value' do
86
+ before do
87
+ @model = KalibroClient::Entities::Base.new
88
+ @model.expects(:send).with(:field_getter).returns(nil)
89
+ end
90
+
91
+ it 'should return an instance of Hash' do
92
+ expect(@model.field_to_hash(:field_getter)).to be_a(Hash)
93
+ end
94
+
95
+ it 'should return an empty Hash' do
96
+ expect(@model.field_to_hash(:field_getter)).to eq({})
97
+ end
98
+ end
99
+
100
+ context 'with a Float field value' do
101
+ before do
102
+ @model = KalibroClient::Entities::Base.new
103
+ @model.expects(:send).with(:field_getter).returns(1.0)
104
+ end
105
+
106
+ it 'should return an instance of Hash' do
107
+ expect(@model.field_to_hash(:field_getter)).to be_a(Hash)
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,64 @@
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
+ require 'kalibro_client/helpers/xml_converters'
19
+
20
+ include XMLConverters
21
+
22
+ describe XMLConverters do
23
+ describe 'xml_instance_class_name' do
24
+ before { @model = KalibroClient::Entities::Base.new }
25
+
26
+ it 'should return modelXml' do
27
+ expect(xml_instance_class_name(@model)).to eq('baseXml')
28
+ end
29
+ end
30
+
31
+ describe 'get_xml' do
32
+ context 'with an object that is not an instance of Base' do
33
+ before { @object = "kalibro" }
34
+
35
+ it 'should return a Hash' do
36
+ expect(get_xml("field", @object)).to be_a(Hash)
37
+ end
38
+
39
+ it 'should return an empty Hash' do
40
+ expect(get_xml("field", @object)).to eq({})
41
+ end
42
+ end
43
+
44
+ context 'with an instance of Base' do
45
+ before { @object = KalibroClient::Entities::Base.new }
46
+
47
+ it 'should return a Hash' do
48
+ expect(get_xml("field", @object)).to be_a(Hash)
49
+ end
50
+
51
+ it 'should return the XML Hash' do
52
+ field_xml_hash = {:attributes! =>
53
+ {:field =>
54
+ {"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
55
+ "xsi:type"=>"kalibro:baseXml"
56
+ }
57
+ }
58
+ }
59
+
60
+ expect(get_xml("field", @object)).to eq(field_xml_hash)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,112 @@
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 do
20
+
21
+ context 'configuration' do
22
+ #FIXME: there should be a better way to keep the default values
23
+ let(:config) { { processor_address: "http://localhost:8082",
24
+ configurations_address: "http://localhost:8083" } }
25
+
26
+ describe 'config' do
27
+ it 'should return the default configuration' do
28
+ expect(KalibroClient.config).to eq({
29
+ processor_address: "http://localhost:8082",
30
+ configurations_address: "http://localhost:8083"
31
+ })
32
+ end
33
+ end
34
+
35
+ describe 'configure' do
36
+ after(:each) {KalibroClient.configure(config)}
37
+
38
+ it 'should set the address' do
39
+ KalibroClient.configure({processor_address: 'http://test.test'})
40
+ expect(KalibroClient.config[:processor_address]).to eq('http://test.test')
41
+ end
42
+ end
43
+
44
+ describe 'configure_with' do
45
+ context 'with an existent YAML' do
46
+ after(:each) {KalibroClient.configure(config)}
47
+
48
+ it 'should set the config' do
49
+ KalibroClient.configure_with('spec/savon/fixtures/config.yml')
50
+
51
+ expect(KalibroClient.config).to eq({
52
+ processor_address: 'http://test1.test1',
53
+ configurations_address: 'http://test2.test2'})
54
+ end
55
+ end
56
+
57
+ context 'with an inexistent YAML' do
58
+ before :each do
59
+ @logger = Logger.new(File::NULL)
60
+ KalibroClient.expects(:logger).returns(@logger)
61
+ end
62
+
63
+ it 'should keep the defaults' do
64
+ KalibroClient.configure_with('spec/savon/fixtures/inexistent_file.yml')
65
+ expect(KalibroClient.config).to eq(config)
66
+ end
67
+
68
+ it 'should log an warning' do
69
+ @logger.expects(:warn).with("YAML configuration file couldn't be found. Using defaults.")
70
+
71
+ KalibroClient.configure_with('spec/savon/fixtures/inexistent_file.yml')
72
+ end
73
+ end
74
+
75
+ context 'with an invalid YAML' do
76
+ before :each do
77
+ @logger = Logger.new(File::NULL)
78
+ KalibroClient.expects(:logger).returns(@logger)
79
+ end
80
+
81
+ it 'should keep the defaults' do
82
+ KalibroClient.configure_with('spec/savon/fixtures/invalid_config.yml')
83
+ expect(KalibroClient.config).to eq(config)
84
+ end
85
+
86
+ it 'should log an warning' do
87
+ @logger.expects(:warn).with("YAML configuration file contains invalid syntax. Using defaults.")
88
+
89
+ KalibroClient.configure_with('spec/savon/fixtures/invalid_config.yml')
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+ context 'Logger' do
96
+ describe 'logger' do
97
+ it 'should return the default logger' do
98
+ expect(KalibroClient.logger).to be_a(Logger)
99
+ end
100
+ end
101
+
102
+ describe 'logger=' do
103
+ it 'should set the logger' do
104
+ logger = Logger.new(STDOUT)
105
+
106
+ KalibroClient.logger = logger
107
+
108
+ expect(KalibroClient.logger).to eq(logger)
109
+ end
110
+ end
111
+ end
112
+ end