Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions app/views/compare_runs/getCompareJson.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
var row = "";
var CompareTableRowTemplate = templates.getCompareTableRowTemplate();
var CompareTableColumnTemplate = templates.getCompareTableColumnTemplate();
for (var index = 0; index < number_of_failing_tests; index++) {
if (index%3) {
var MAXIMUM_COLUMNS = 2;

for(var index=0;index<number_of_failing_tests;){
for(var colIndex=0;colIndex<MAXIMUM_COLUMNS;colIndex++){
row += templates.render(CompareTableColumnTemplate, {
"ClassName": class_name_array[index].class_name
"ClassName": (index<number_of_failing_tests)?class_name_array[index].class_name : ""
});
}
else {
classNames += templates.render(CompareTableRowTemplate, {
index++;
}
classNames += templates.render(CompareTableRowTemplate, {
"ClassNameColumns": row
});
row = "";
}
});
row = "";
}
return classNames;
}
Expand Down
13 changes: 13 additions & 0 deletions spec/helpers/comparerunscustommatchers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module CompareRunsCustomMatchers
RSpec::Matchers.define :contain_all do |expected|
match do |actual|
(actual.length == expected.length ) and (actual.to_set == expected.to_set)
end
end

RSpec::Matchers.define :contain_none_of do |expected|
match do |actual|
expected & actual == []
end
end
end
91 changes: 91 additions & 0 deletions spec/helpers/comparesunsspechelper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@


module CompareRunsSpecHelper

include DataHelper

def perform_common_setup
@jan_1_2013 ="2013-01-01 00:00:00 UTC"
@jan_2_2013 ="2013-01-02 00:00:00 UTC"
@unit_tests = "UNIT TESTS"
end

def create_new_project_and_subproject
@project = create_project("COMPARE_RUNS_PROJECT")
@sub_project = create_subproject_for_project(@project,"COMPARE_RUNS_SUBPROJECT")
end

def records_with_error_for(arg_sub_project,arg_test_category,arg_date)
extract_class_names_from(
CompareRuns.get_test_suite_records_with_errors_for(arg_date,
arg_sub_project.id,
arg_test_category)
)
end

def create_class_errors(arg_suite,arg_hash_class_error)
arg_hash_class_error.each_pair do |key , value|
add_failed_tests_from_suite(arg_suite , key , value)
end
end

def class_error_hash_from(*arg_prefixes)
result_hash = {}
arg_prefixes.each do |arg_prefix|
result_hash[create_class_name(arg_prefix)] = create_err_msg(arg_prefix)
end
result_hash
end

def class_name_arr_from(*arg_prefixes)
arg_prefixes.map{|prefix| create_class_name prefix}
end

def create_class_name(arg_prefix)
"class_#{arg_prefix}"
end

def create_err_msg(arg_prefix)
"error for class_#{arg_prefix}"
end

def form_data(arg_subproject,arg_test_category,arg_date1,arg_date2)
{"sub_projects" => arg_subproject.id,
"test_types" => arg_test_category,
"date_one" => arg_date1,
"date_two" => arg_date2}
end

def get_compare_result
@compare_result=
CompareRuns.getCompareResult form_data(@sub_project,@unit_tests,@jan_1_2013,@jan_2_2013)
end

def common_test_failures
extract_class_names_from @compare_result[:common_failures]
end

def combined_test_failures
extract_class_names_from @compare_result[:combined_total_failures]
end

def day_one_test_failures
extract_class_names_from @compare_result[:test_case_records_for_date_one]
end

def day_two_test_failures
extract_class_names_from @compare_result[:test_case_records_for_date_two]
end

def extract_class_names_from(arg_arr_test_case_records)
return [] unless arg_arr_test_case_records
arg_arr_test_case_records.map {|record| record.class_name}
end

def clean_up_data
delete_project_and_associated_records "COMPARE_RUNS_PROJECT"
end



end
38 changes: 38 additions & 0 deletions spec/helpers/datahelper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,42 @@ def get_metadata(arg_sub_project , arg_test_category , arg_date)
arg_date)
end

def delete_project_and_associated_records(project_name)
projects = Project.find_all_by_name(project_name)
projects.each do |project|
subprojects = SubProject.find_all_by_project_id project.id
delete_sub_projects_and_associated_records subprojects
project.delete
end
end

def delete_sub_projects_and_associated_records(subprojects)
subprojects.each do |subproject|
metadata = TestMetadatum.find_all_by_sub_project_id subproject.id
delete_metadata_and_associated_records metadata
subproject.delete
end
end

def delete_metadata_and_associated_records(test_metadata)
test_metadata.each do |test_metadatum|
test_suites = TestSuiteRecord.find_all_by_test_metadatum_id test_metadatum.id
delete_test_suites_and_associated_records test_suites
test_metadatum.delete
end
end

def delete_test_suites_and_associated_records(test_suites)
test_suites.each do |test_suite|
test_case_records = TestCaseRecord.find_all_by_test_suite_record_id test_suite.id
delete_test_case_records test_case_records
test_suite.delete
end
end

def delete_test_case_records(test_case_records)
test_case_records.each do |test_case_record|
test_case_record.delete
end
end
end
106 changes: 4 additions & 102 deletions spec/models/compare_runs_spec.rb
Original file line number Diff line number Diff line change
@@ -1,105 +1,6 @@
require "rspec"


module CompareRunsCustomMatchers
RSpec::Matchers.define :contain_all do |expected|
match do |actual|
(actual.length == expected.length ) and (actual.to_set == expected.to_set)
end
end

RSpec::Matchers.define :contain_none_of do |expected|
match do |actual|
expected & actual == []
end
end
end


module CompareRunsSpecHelper

include DataHelper

def perform_common_setup
@jan_1_2013 ="2013-01-01 00:00:00 UTC"
@jan_2_2013 ="2013-01-02 00:00:00 UTC"
@unit_tests = "UNIT TESTS"
end

def create_new_project_and_subproject
@project = create_project("COMPARE_RUNS_PROJECT")
@sub_project = create_subproject_for_project(@project,"COMPARE_RUNS_SUBPROJECT")
end

def records_with_error_for(arg_sub_project,arg_test_category,arg_date)
extract_class_names_from(
CompareRuns.get_test_suite_records_with_errors_for(arg_date,
arg_sub_project.id,
arg_test_category)
)
end

def create_class_errors(arg_suite,arg_hash_class_error)
arg_hash_class_error.each_pair do |key , value|
add_failed_tests_from_suite(arg_suite , key , value)
end
end

def class_error_hash_from(*arg_prefixes)
result_hash = {}
arg_prefixes.each do |arg_prefix|
result_hash[create_class_name(arg_prefix)] = create_err_msg(arg_prefix)
end
result_hash
end

def class_name_arr_from(*arg_prefixes)
arg_prefixes.map{|prefix| create_class_name prefix}
end

def create_class_name(arg_prefix)
"class_#{arg_prefix}"
end

def create_err_msg(arg_prefix)
"error for class_#{arg_prefix}"
end

def form_data(arg_subproject,arg_test_category,arg_date1,arg_date2)
{"sub_projects" => arg_subproject.id,
"test_types" => arg_test_category,
"date_one" => arg_date1,
"date_two" => arg_date2}
end

def get_compare_result
@compare_result=
CompareRuns.getCompareResult form_data(@sub_project,@unit_tests,@jan_1_2013,@jan_2_2013)
end

def common_test_failures
extract_class_names_from @compare_result[:common_failures]
end

def combined_test_failures
extract_class_names_from @compare_result[:combined_total_failures]
end

def day_one_test_failures
extract_class_names_from @compare_result[:test_case_records_for_date_one]
end

def day_two_test_failures
extract_class_names_from @compare_result[:test_case_records_for_date_two]
end

def extract_class_names_from(arg_arr_test_case_records)
return [] unless arg_arr_test_case_records
arg_arr_test_case_records.map {|record| record.class_name}
end

end

require 'rspec'
require File.expand_path("spec/helpers/comparesunsspechelper.rb")
require File.expand_path("spec/helpers/comparerunscustommatchers.rb")

describe "CompareRuns" do

Expand Down Expand Up @@ -155,6 +56,7 @@ def extract_class_names_from(arg_arr_test_case_records)
create_class_errors(@test_suite1,class_error_hash_from("UT001","UT002","UT003"))
create_class_errors(@test_suite2,class_error_hash_from("IT001","IT002","IT003"))
end

it "should return only the records for the requested test category and exclude others on the same day" do
expected_ut_errors = class_name_arr_from("UT001","UT002","UT003")
expected_it_errors = class_name_arr_from("IT001","IT002","IT003")
Expand Down
9 changes: 9 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|


config.treat_symbols_as_metadata_keys_with_true_values = true




# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
Expand Down Expand Up @@ -62,6 +69,8 @@
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false

config.filter_run_excluding :ignore => true

# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
Expand Down
Loading