From ff7342cc9a1903a98f354955519e77c8b9d879fd Mon Sep 17 00:00:00 2001 From: Renan Fichberg Date: Fri, 22 Aug 2014 15:35:58 -0300 Subject: [PATCH] Fixed test related to code. --- features/metric_configuration/create.feature | 2 -- features/metric_configuration/delete.feature | 4 ++-- features/metric_configuration/edition.feature | 21 +++------------------ spec/controllers/metric_configurations_controller_spec.rb | 9 ++++++--- spec/factories/metric_configurations.rb | 2 +- spec/factories/metrics.rb | 3 +++ 6 files changed, 15 insertions(+), 26 deletions(-) diff --git a/features/metric_configuration/create.feature b/features/metric_configuration/create.feature index 5522160..a7f5a07 100644 --- a/features/metric_configuration/create.feature +++ b/features/metric_configuration/create.feature @@ -19,12 +19,10 @@ Feature: Metric Configuration Creation And I click the Add Metric link And I click the "Analizo" h3 And I click the Total Lines of Code link - And I fill the Code field with "My Code" And I fill the Weight field with "2" And I set the select field "Aggregation Form" as "Average" And I set the select field "Reading Group" as "Scholar" When I press the Save button - Then I should see "My Code" Then I should see "Total Lines of Code" Then I should see "2" diff --git a/features/metric_configuration/delete.feature b/features/metric_configuration/delete.feature index 1702df0..9e43084 100644 --- a/features/metric_configuration/delete.feature +++ b/features/metric_configuration/delete.feature @@ -10,7 +10,7 @@ Feature: Metric Configuration Deletion And I own a sample configuration And I have a sample reading group And I have a sample metric configuration within the given mezuro configuration - When I am at the Sample Configuration page + When I am at the Sample Configuration page And I click the Destroy link Then I should see "There are no metric configurations yet!" @@ -21,5 +21,5 @@ Feature: Metric Configuration Deletion And I have a sample configuration And I have a sample reading group And I have a sample metric configuration within the given mezuro configuration - When I am at the Sample Configuration page + When I am at the Sample Configuration page Then I should not see "Destroy" \ No newline at end of file diff --git a/features/metric_configuration/edition.feature b/features/metric_configuration/edition.feature index 40a7d25..d084a7a 100644 --- a/features/metric_configuration/edition.feature +++ b/features/metric_configuration/edition.feature @@ -22,22 +22,9 @@ Feature: Metric Configuration edition And I have a sample metric configuration within the given mezuro configuration And I am at the Sample Configuration page When I click the Edit link - And I fill the Code field with "Another_Code" + And I fill the Weight field with "3.0" And I press the Save button - Then I should see "Another_Code" - - @kalibro_restart - Scenario: trying to edit with an existing code - Given I am a regular user - And I am signed in - And I own a sample configuration - And I have a sample reading group - And I have a sample metric configuration within the given mezuro configuration - And I have another metric configuration with code "Another_Code" within the given mezuro configuration - When I visit the sample metric configuration edit page - And I fill the Code field with "Another_Code" - And I press the Save button - Then I should see "Code There's already" + Then I should see "3.0" @kalibro_restart Scenario: trying to edit with blank fields @@ -47,8 +34,6 @@ Feature: Metric Configuration edition And I have a sample reading group And I have a sample metric configuration within the given mezuro configuration When I visit the sample metric configuration edit page - And I fill the Code field with " " And I fill the Weight field with " " And I press the Save button - Then I should see "Code can't be blank" - And I should see "Weight can't be blank" \ No newline at end of file + Then I should see "Weight can't be blank" \ No newline at end of file diff --git a/spec/controllers/metric_configurations_controller_spec.rb b/spec/controllers/metric_configurations_controller_spec.rb index 776fdd4..afe65fb 100644 --- a/spec/controllers/metric_configurations_controller_spec.rb +++ b/spec/controllers/metric_configurations_controller_spec.rb @@ -48,6 +48,7 @@ describe MetricConfigurationsController, :type => :controller do end describe 'create' do + let!(:metric_configuration) { FactoryGirl.build(:metric_configuration) } 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 let(:mezuro_configuration) { FactoryGirl.build(:mezuro_configuration) } let(:base_tool) { FactoryGirl.build(:base_tool) } @@ -65,8 +66,9 @@ describe MetricConfigurationsController, :type => :controller do before :each do MetricConfiguration.any_instance.expects(:save).returns(true) KalibroGatekeeperClient::Entities::BaseTool.expects(:find_by_name).with(base_tool.name).returns(base_tool) + base_tool.expects(:metric).with(metric_configuration.metric.name).returns(metric_configuration.metric) - post :create, mezuro_configuration_id: mezuro_configuration.id, metric_configuration: metric_configuration_params, base_tool_name: base_tool.name + post :create, mezuro_configuration_id: mezuro_configuration.id, metric_configuration: metric_configuration_params, base_tool_name: base_tool.name, metric_name: metric_configuration.metric.name end it { is_expected.to respond_with(:redirect) } @@ -76,15 +78,16 @@ describe MetricConfigurationsController, :type => :controller do before :each do MetricConfiguration.any_instance.expects(:save).returns(false) KalibroGatekeeperClient::Entities::BaseTool.expects(:find_by_name).with(base_tool.name).returns(base_tool) + base_tool.expects(:metric).with(metric_configuration.metric.name).returns(metric_configuration.metric) - post :create, mezuro_configuration_id: mezuro_configuration.id, metric_configuration: metric_configuration_params, base_tool_name: base_tool.name + post :create, mezuro_configuration_id: mezuro_configuration.id, metric_configuration: metric_configuration_params, base_tool_name: base_tool.name, metric_name: metric_configuration.metric.name end it { is_expected.to render_template(:new) } end end end - + describe 'show' do let(:metric_configuration) { FactoryGirl.build(:metric_configuration) } let(:reading_group) { FactoryGirl.build(:reading_group) } diff --git a/spec/factories/metric_configurations.rb b/spec/factories/metric_configurations.rb index 6bcf0eb..859ebf4 100644 --- a/spec/factories/metric_configurations.rb +++ b/spec/factories/metric_configurations.rb @@ -1,7 +1,7 @@ FactoryGirl.define do factory :metric_configuration, class: MetricConfiguration do id 1 - code 'native' + code 'total_abstract_classes' metric {FactoryGirl.build(:metric)} base_tool_name "Analizo" weight 1 diff --git a/spec/factories/metrics.rb b/spec/factories/metrics.rb index 2ddc281..f0ff685 100644 --- a/spec/factories/metrics.rb +++ b/spec/factories/metrics.rb @@ -1,6 +1,7 @@ FactoryGirl.define do factory :metric, class: KalibroGatekeeperClient::Entities::Metric do name "Total Abstract Classes" + code "total_abstract_classes" compound false scope "SOFTWARE" description nil @@ -10,6 +11,7 @@ FactoryGirl.define do factory :loc, class: KalibroGatekeeperClient::Entities::Metric do name "Lines of Code" + code "loc" compound false scope "CLASS" description nil @@ -19,6 +21,7 @@ FactoryGirl.define do factory :compound_metric, class: KalibroGatekeeperClient::Entities::Metric do name "Compound" + code "compound" compound true scope "CLASS" description nil -- libgit2 0.21.2