diff --git a/app/views/compare_runs/getCompareJson.html.erb b/app/views/compare_runs/getCompareJson.html.erb index feaed07..bcdd0d8 100644 --- a/app/views/compare_runs/getCompareJson.html.erb +++ b/app/views/compare_runs/getCompareJson.html.erb @@ -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 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 \ No newline at end of file diff --git a/spec/helpers/datahelper.rb b/spec/helpers/datahelper.rb index 3058f95..60477aa 100644 --- a/spec/helpers/datahelper.rb +++ b/spec/helpers/datahelper.rb @@ -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 diff --git a/spec/models/compare_runs_spec.rb b/spec/models/compare_runs_spec.rb index 568e285..899aaf4 100644 --- a/spec/models/compare_runs_spec.rb +++ b/spec/models/compare_runs_spec.rb @@ -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 @@ -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") diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 656902f..5084be6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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: @@ -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. diff --git a/spec/views/compare_runs/getcomparejson_spec.rb b/spec/views/compare_runs/getcomparejson_spec.rb new file mode 100644 index 0000000..ace22ba --- /dev/null +++ b/spec/views/compare_runs/getcomparejson_spec.rb @@ -0,0 +1,239 @@ +require 'spec_helper' +require 'rspec' +require File.expand_path("spec/helpers/comparesunsspechelper.rb") +require File.expand_path("spec/helpers/comparerunscustommatchers.rb") + +class Fixnum + def tests_failing + "Number of failing tests: #{self}" + end +end + +module CompareRunsSeleniumHelper + + def open_compare_runs_page + visit '/compare_runs' + page.driver.browser.manage.window.maximize + end + + def select_by_value(id, value) + option_xpath = "//*[@id='#{id}']/option[@value='#{value}']" + option = find(:xpath, option_xpath).text + select(option, :from => id) + end + + def table(id) + find_by_id(id) + end + + def classnames_listed_for_table(tablename) + all(:xpath , "//table[@id='#{tablename}']/tbody/tr/td").map{|t| t.native.text} - [""] + end + + def perform_default_selections + select "COMPARE_RUNS_PROJECT" , from: "project_select" + select "COMPARE_RUNS_SUBPROJECT" , from: "sub_project_select" + select @unit_tests , from:"test_types_select" + select_by_value "date_one_select" , @jan_1_2013.sub("UTC","") + select_by_value "date_two_select" , @jan_2_2013.sub("UTC","") + find_by_id("compare_runs").click + end + + def open_compare_runs_page_and_perform_default_selection + open_compare_runs_page + perform_default_selections + end +end + +#open CompareRunsSpecHelper and add some common methods +module CompareRunsSpecHelper + def create_test_suites + @metadata1 = create_metadatum(@sub_project , @jan_1_2013 , @unit_tests) + @metadata2 = create_metadatum(@sub_project , @jan_2_2013 , @unit_tests) + @suite1 = create_suite_with_metadata(@metadata1 , "suite001") + @suite2 = create_suite_with_metadata(@metadata2 , "suite002") + end +end + + +describe "Compare Runs " , js:true do + + self.use_transactional_fixtures = false + include CompareRunsSpecHelper + include CompareRunsSeleniumHelper + include CompareRunsCustomMatchers + + before(:each) do + clean_up_data + perform_common_setup + create_new_project_and_subproject + create_test_suites + end + + after(:each){clean_up_data} + + context "when there are no failures" do + + before do + open_compare_runs_page_and_perform_default_selection + end + + it "shows errors and error counts correctly" do + table("result_table_common").should have_content(0.tests_failing) + table("result_table_both").should have_content(0.tests_failing) + table("result_table_date1").should have_content(0.tests_failing) + table("result_table_date2").should have_content(0.tests_failing) + classnames_listed_for_table("result_table_common").should be_empty + classnames_listed_for_table("result_table_both").should be_empty + classnames_listed_for_table("result_table_date1").should be_empty + classnames_listed_for_table("result_table_date2").should be_empty + end + end + + context "when there are failures only for day 1" do + + before do + create_class_errors(@suite1,class_error_hash_from("001","002","003","004")) + @expected_day_1_failures = class_name_arr_from "001","002","003","004" + open_compare_runs_page_and_perform_default_selection + end + + it "shows errors and error counts correctly" do + table("result_table_common").should have_content(0.tests_failing) + table("result_table_both").should have_content(4.tests_failing) + table("result_table_date1").should have_content(4.tests_failing) + table("result_table_date2").should have_content(0.tests_failing) + classnames_listed_for_table("result_table_common").should be_empty + classnames_listed_for_table("result_table_both").should contain_all @expected_day_1_failures + classnames_listed_for_table("result_table_date1").should contain_all @expected_day_1_failures + classnames_listed_for_table("result_table_date2").should be_empty + end + + end + + context "when there are failures only for day 2" do + before do + create_class_errors(@suite2,class_error_hash_from("001","002","003","004")) + @expected_day_2_failures = class_name_arr_from "001","002","003","004" + open_compare_runs_page_and_perform_default_selection + end + + it "shows errors and error counts correctly" do + table("result_table_common").should have_content(0.tests_failing) + table("result_table_both").should have_content(4.tests_failing) + table("result_table_date2").should have_content(4.tests_failing) + table("result_table_date1").should have_content(0.tests_failing) + classnames_listed_for_table("result_table_common").should be_empty + classnames_listed_for_table("result_table_both").should contain_all @expected_day_2_failures + classnames_listed_for_table("result_table_date1").should be_empty + classnames_listed_for_table("result_table_date2").should contain_all @expected_day_2_failures + end + end + + context "when the failures for both days are exactly the same" do + before do + create_class_errors(@suite1,class_error_hash_from("001","002","003","004","005")) + create_class_errors(@suite2,class_error_hash_from("001","002","003","004","005")) + @expected_failures = class_name_arr_from "001","002","003","004","005" + open_compare_runs_page_and_perform_default_selection + end + + it "shows errors and error counts correctly" do + table("result_table_common").should have_content(5.tests_failing) + table("result_table_both").should have_content(5.tests_failing) + table("result_table_date2").should have_content(5.tests_failing) + table("result_table_date1").should have_content(5.tests_failing) + classnames_listed_for_table("result_table_common").should contain_all @expected_failures + classnames_listed_for_table("result_table_both").should contain_all @expected_failures + classnames_listed_for_table("result_table_date1").should contain_all @expected_failures + classnames_listed_for_table("result_table_date2").should contain_all @expected_failures + end + end + + context "when the failures for both days are mutually exclusive" do + before do + create_class_errors(@suite1,class_error_hash_from("001","002","003")) + create_class_errors(@suite2,class_error_hash_from("004","005","006","007")) + @expected_day_1_failures = class_name_arr_from "001","002","003" + @expected_day_2_failures = class_name_arr_from "004","005","006","007" + @expected_total_failures = @expected_day_1_failures + @expected_day_2_failures + open_compare_runs_page_and_perform_default_selection + end + + it "shows errors and error counts correctly" do + table("result_table_common").should have_content(0.tests_failing) + table("result_table_both").should have_content(7.tests_failing) + table("result_table_date1").should have_content(3.tests_failing) + table("result_table_date2").should have_content(4.tests_failing) + classnames_listed_for_table("result_table_common").should be_empty + classnames_listed_for_table("result_table_both").should contain_all @expected_total_failures + classnames_listed_for_table("result_table_date1").should contain_all @expected_day_1_failures + classnames_listed_for_table("result_table_date2").should contain_all @expected_day_2_failures + end + end + + context "when there are some common failures" do + before do + create_class_errors(@suite1,class_error_hash_from("001","002","003")) + create_class_errors(@suite2,class_error_hash_from("002","003","004")) + @expected_day_1_failures = class_name_arr_from "001","002","003" + @expected_day_2_failures = class_name_arr_from "002","003","004" + @expected_common_failures = class_name_arr_from "002","003" + @expected_total_failures = class_name_arr_from "001","002","003","004" + open_compare_runs_page_and_perform_default_selection + end + + it "shows errors and error counts correctly" do + table("result_table_common").should have_content(2.tests_failing) + table("result_table_both").should have_content(4.tests_failing) + table("result_table_date1").should have_content(3.tests_failing) + table("result_table_date2").should have_content(3.tests_failing) + classnames_listed_for_table("result_table_common").should contain_all @expected_common_failures + classnames_listed_for_table("result_table_both").should contain_all @expected_total_failures + classnames_listed_for_table("result_table_date1").should contain_all @expected_day_1_failures + classnames_listed_for_table("result_table_date2").should contain_all @expected_day_2_failures + end + end + + context "when failures in day 1 are a subset of failures in day 2" do + before do + create_class_errors(@suite1,class_error_hash_from("001","002","003")) + create_class_errors(@suite2,class_error_hash_from("001","002","003","004","005")) + @expected_day_1_failures = class_name_arr_from "001","002","003" + @expected_day_2_failures = class_name_arr_from "001","002","003","004","005" + open_compare_runs_page_and_perform_default_selection + end + + it "shows errors and error counts correctly" do + table("result_table_common").should have_content(3.tests_failing) + table("result_table_both").should have_content(5.tests_failing) + table("result_table_date1").should have_content(3.tests_failing) + table("result_table_date2").should have_content(5.tests_failing) + classnames_listed_for_table("result_table_common").should contain_all @expected_day_1_failures + classnames_listed_for_table("result_table_both").should contain_all @expected_day_2_failures + classnames_listed_for_table("result_table_date1").should contain_all @expected_day_1_failures + classnames_listed_for_table("result_table_date2").should contain_all @expected_day_2_failures + end + end + + context "when failures in day 2 are a subset of failures in day 1" do + before do + create_class_errors(@suite1,class_error_hash_from("001","002","003","004","005")) + create_class_errors(@suite2,class_error_hash_from("001","002","003")) + @expected_day_1_failures = class_name_arr_from "001","002","003","004","005" + @expected_day_2_failures = class_name_arr_from "001","002","003" + open_compare_runs_page_and_perform_default_selection + end + + it "shows errors and error counts correctly" do + table("result_table_common").should have_content(3.tests_failing) + table("result_table_both").should have_content(5.tests_failing) + table("result_table_date1").should have_content(5.tests_failing) + table("result_table_date2").should have_content(3.tests_failing) + classnames_listed_for_table("result_table_common").should contain_all @expected_day_2_failures + classnames_listed_for_table("result_table_both").should contain_all @expected_day_1_failures + classnames_listed_for_table("result_table_date1").should contain_all @expected_day_1_failures + classnames_listed_for_table("result_table_date2").should contain_all @expected_day_2_failures + end + end +end \ No newline at end of file