Commit b01bb30aef05c950e5e6f75803f059f2a63b46aa

Authored by Diego Camarinha
Committed by Rafael Manzo
1 parent 93da3694

Working on metric configuration tests.

Pending: Fix compound metric configuration tests.

Signed off by: Rafael R. Manzo <rr.manzo@gmail.com>
Gemfile.lock
1 1 GIT
2 2 remote: https://github.com/mezuro/kalibro_client
3   - revision: cd8c53baa30bf507e9ef7a59407ef3cfe9226cb4
  3 + revision: 59630ab6b9dbf7a763c6c0ee08404ec4c9acd65b
4 4 specs:
5 5 kalibro_client (0.0.1)
6 6 activeresource (~> 4.0.0)
... ... @@ -57,7 +57,7 @@ GEM
57 57 binding_of_caller (0.7.2)
58 58 debug_inspector (>= 0.0.1)
59 59 builder (3.2.2)
60   - capistrano (3.3.4)
  60 + capistrano (3.3.5)
61 61 capistrano-stats (~> 1.1.0)
62 62 i18n
63 63 rake (>= 10.0.0)
... ... @@ -71,7 +71,7 @@ GEM
71 71 capistrano-rvm (0.1.2)
72 72 capistrano (~> 3.0)
73 73 sshkit (~> 1.2)
74   - capistrano-stats (1.1.0)
  74 + capistrano-stats (1.1.1)
75 75 capybara (2.4.4)
76 76 mime-types (>= 1.16)
77 77 nokogiri (>= 1.3.3)
... ... @@ -89,7 +89,7 @@ GEM
89 89 coffee-script-source
90 90 execjs
91 91 coffee-script-source (1.8.0)
92   - colorize (0.7.3)
  92 + colorize (0.7.5)
93 93 colorpicker (0.0.5)
94 94 coveralls (0.7.1)
95 95 multi_json (~> 1.3)
... ... @@ -165,7 +165,7 @@ GEM
165 165 net-scp (1.2.1)
166 166 net-ssh (>= 2.6.5)
167 167 net-ssh (2.9.1)
168   - netrc (0.9.0)
  168 + netrc (0.10.1)
169 169 nokogiri (1.6.5)
170 170 mini_portile (~> 0.6.0)
171 171 orm_adapter (0.5.0)
... ... @@ -247,8 +247,8 @@ GEM
247 247 activesupport (>= 3.0)
248 248 sprockets (>= 2.8, < 4.0)
249 249 sqlite3 (1.3.10)
250   - sshkit (1.5.1)
251   - colorize
  250 + sshkit (1.6.1)
  251 + colorize (>= 0.7.0)
252 252 net-scp (>= 1.1.2)
253 253 net-ssh (>= 2.8.0)
254 254 term-ansicolor (1.3.0)
... ... @@ -269,7 +269,9 @@ GEM
269 269 json (>= 1.8.0)
270 270 warden (1.2.3)
271 271 rack (>= 1.0)
272   - websocket-driver (0.4.0)
  272 + websocket-driver (0.5.0)
  273 + websocket-extensions (>= 0.1.0)
  274 + websocket-extensions (0.1.1)
273 275 xpath (2.0.0)
274 276 nokogiri (~> 1.3)
275 277  
... ...
app/controllers/compound_metric_configurations_controller.rb
... ... @@ -3,7 +3,7 @@ class CompoundMetricConfigurationsController &lt; BaseMetricConfigurationsControlle
3 3  
4 4 def create
5 5 super
6   - metric_configuration.metric.compound = true
  6 + metric_configuration.metric_snapshot.compound = true
7 7 respond_to do |format|
8 8 create_and_redir(format)
9 9 end
... ...
spec/controllers/compound_metric_configurations_controller_spec.rb
... ... @@ -31,38 +31,40 @@ describe CompoundMetricConfigurationsController, :type =&gt; :controller do
31 31 end
32 32  
33 33 describe 'create' do
34   - let!(:metric_configuration_params) { Hash[FactoryGirl.attributes_for(:metric_configuration).map { |k,v| [k.to_s, v.to_s] }] } #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with symbols and integers
35   - let!(:metric_params) { Hash[FactoryGirl.attributes_for(:metric).map { |k,v| [k.to_s, v.to_s] }] } #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with symbols and integers
36   - let(:compound_metric_configuration) { FactoryGirl.build(:compound_metric_configuration) }
37   -
38   - before do
39   - sign_in FactoryGirl.create(:user)
40   - metric_configuration_params["metric"] = metric_params
41   - end
  34 + pending 'waiting for metric on kalibro_client' do
  35 + let!(:metric_configuration_params) { Hash[FactoryGirl.attributes_for(:metric_configuration, metric_snapshot_id: 42).map { |k,v| [k.to_s, v.to_s] }] } #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with symbols and integers
  36 + let!(:metric_params) { Hash[FactoryGirl.attributes_for(:metric).map { |k,v| [k.to_s, v.to_s] }] } #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with symbols and integers
  37 + let(:compound_metric_configuration) { FactoryGirl.build(:compound_metric_configuration) }
42 38  
43   - context 'when the current user owns the reading group' do
44   - before :each do
45   - subject.expects(:kalibro_configuration_owner?).returns true
  39 + before do
  40 + sign_in FactoryGirl.create(:user)
  41 + metric_configuration_params["metric"] = metric_params
46 42 end
47 43  
48   - context 'with valid fields' do
  44 + context 'when the current user owns the reading group' do
49 45 before :each do
50   - MetricConfiguration.any_instance.expects(:save).returns(true)
51   -
52   - post :create, kalibro_configuration_id: kalibro_configuration.id, metric_configuration: metric_configuration_params
  46 + subject.expects(:kalibro_configuration_owner?).returns true
53 47 end
54 48  
55   - it { is_expected.to respond_with(:redirect) }
56   - end
  49 + context 'with valid fields' do
  50 + before :each do
  51 + MetricConfiguration.any_instance.expects(:save).returns(true)
57 52  
58   - context 'with invalid fields' do
59   - before :each do
60   - MetricConfiguration.any_instance.expects(:save).returns(false)
61   - MetricConfiguration.expects(:metric_configurations_of).with(kalibro_configuration.id).returns([compound_metric_configuration])
62   - post :create, kalibro_configuration_id: kalibro_configuration.id, metric_configuration: metric_configuration_params
  53 + post :create, kalibro_configuration_id: kalibro_configuration.id, metric_configuration: metric_configuration_params
  54 + end
  55 +
  56 + it { is_expected.to respond_with(:redirect) }
63 57 end
64 58  
65   - it { is_expected.to render_template(:new) }
  59 + context 'with invalid fields' do
  60 + before :each do
  61 + MetricConfiguration.any_instance.expects(:save).returns(false)
  62 + MetricConfiguration.expects(:metric_configurations_of).with(kalibro_configuration.id).returns([compound_metric_configuration])
  63 + post :create, kalibro_configuration_id: kalibro_configuration.id, metric_configuration: metric_configuration_params
  64 + end
  65 +
  66 + it { is_expected.to render_template(:new) }
  67 + end
66 68 end
67 69 end
68 70 end
... ...
spec/controllers/metric_configurations_controller_spec.rb
... ... @@ -11,7 +11,8 @@ describe MetricConfigurationsController, :type =&gt; :controller do
11 11 context 'when adding new metrics' do
12 12 before :each do
13 13 subject.expects(:kalibro_configuration_owner?).returns true
14   - KalibroClient::Processor::MetricCollector.expects(:all).returns([metric_collector])
  14 + KalibroClient::Processor::MetricCollector.expects(:all_names).returns([metric_collector])
  15 + KalibroConfiguration.expects(:find).with(kalibro_configuration.id).returns(kalibro_configuration)
15 16 get :choose_metric, kalibro_configuration_id: kalibro_configuration.id
16 17 end
17 18  
... ... @@ -21,7 +22,8 @@ describe MetricConfigurationsController, :type =&gt; :controller do
21 22 end
22 23  
23 24 describe 'new' do
24   - let(:metric_collector) { FactoryGirl.build(:metric_collector) }
  25 + let!(:metric_collector) { FactoryGirl.build(:metric_collector) }
  26 + let!(:native_metric) { FactoryGirl.build(:loc) }
25 27 before :each do
26 28 sign_in FactoryGirl.create(:user)
27 29 end
... ... @@ -30,7 +32,8 @@ describe MetricConfigurationsController, :type =&gt; :controller do
30 32 before :each do
31 33 subject.expects(:kalibro_configuration_owner?).returns true
32 34 KalibroClient::Processor::MetricCollector.expects(:find).with(metric_collector.name).returns(metric_collector)
33   - post :new, kalibro_configuration_id: kalibro_configuration.id, metric_name: "Lines of Code", metric_collector_name: metric_collector.name
  35 + metric_collector.expects(:metric).with(native_metric.code).returns(native_metric)
  36 + post :new, kalibro_configuration_id: kalibro_configuration.id, metric_code: native_metric.code, metric_collector_name: metric_collector.name
34 37 end
35 38  
36 39 it { is_expected.to respond_with(:success) }
... ...
spec/controllers/mezuro_configurations_controller_spec.rb
... ... @@ -71,6 +71,10 @@ describe KalibroConfigurationsController, :type =&gt; :controller do
71 71 end
72 72  
73 73 it { is_expected.to render_template(:show) }
  74 +
  75 + after :each do
  76 + Rails.cache.clear
  77 + end
74 78 end
75 79  
76 80 describe 'destroy' do
... ...
spec/factories/metrics.rb
1 1 FactoryGirl.define do
2   - factory :metric, class: KalibroClient::Processor::Metric do
  2 + factory :metric, class: KalibroClient::Processor::NativeMetric do
3 3 name "Total Abstract Classes"
4 4 code "total_abstract_classes"
5   - compound false
6 5 scope "SOFTWARE"
7 6 description nil
  7 + languages { [:C] }
8 8  
9   - initialize_with { new(compound, name, code, scope) }
  9 + initialize_with { new(name, code, scope, description, languages) }
10 10 end
11 11  
12   - factory :loc, class: KalibroClient::Processor::Metric do
  12 + factory :loc, class: KalibroClient::Processor::NativeMetric do
13 13 name "Lines of Code"
14 14 code "loc"
15   - compound false
16 15 scope "CLASS"
17 16 description nil
  17 + languages { [:C] }
18 18  
19   - initialize_with { new(compound, name, code, scope) }
  19 + initialize_with { new(name, code, scope, description, languages) }
20 20 end
21 21  
22 22 factory :compound_metric, class: KalibroClient::Processor::CompoundMetric do
... ... @@ -26,6 +26,6 @@ FactoryGirl.define do
26 26 description nil
27 27 script ""
28 28  
29   - initialize_with { new(name, code, scope, script) }
  29 + initialize_with { new(name, code, scope, description, script) }
30 30 end
31 31 end
... ...