From 2e28fb7fc5b77133250666345eb19f6da6682970 Mon Sep 17 00:00:00 2001 From: Lars Willighagen Date: Thu, 12 Jul 2018 20:29:22 +0200 Subject: [PATCH 1/5] Update Travis-CI node version --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f56228d..f10b567 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,8 @@ language: ruby rvm: - 2.1.0 before_install: - - nvm install 0.10.32 - - nvm use 0.10.32 + - nvm install 8.11.3 + - nvm use 8.11.3 - npm update npm -g install: - npm install --global quickscrape@0.4.6 From 83f2f653f005ac195f416a9dd96c2c577b6130be Mon Sep 17 00:00:00 2001 From: Lars Willighagen Date: Fri, 13 Jul 2018 00:08:33 +0200 Subject: [PATCH 2/5] Update Travis-CI ruby version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f10b567..f8e5ba1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: ruby rvm: - - 2.1.0 + - 2.5.1 before_install: - nvm install 8.11.3 - nvm use 8.11.3 From 2b433fe117bd89797c39cb4cd0ad3e17c5489ff2 Mon Sep 17 00:00:00 2001 From: Lars Willighagen Date: Fri, 13 Jul 2018 00:08:42 +0200 Subject: [PATCH 3/5] Update tests --- test/test_all.rb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/test/test_all.rb b/test/test_all.rb index 172f6da..17ec6ff 100755 --- a/test/test_all.rb +++ b/test/test_all.rb @@ -54,7 +54,7 @@ def coverage(scraperjsonpath, results) cmd += " --scraper #{scraper}" cmd += " --output output" cmd += " --loglevel debug" - puts `#{cmd}` + system "#{cmd}", [:out, :err] => File::NULL # load the output cleanurl = url.gsub(/:?\/+/, '_') Dir.chdir("output/#{cleanurl}") do @@ -75,13 +75,9 @@ def coverage(scraperjsonpath, results) end coverage_files << coverage(scraper, results) # compare results to expected - expected.each do |hash| - key = hash.keys.first - exp_val = hash[key] - exist = results.detect { |result| result.key? key } - match = results.detect do |result| - result.key?(key) && result[key] == exp_val - end + expected.each do |key, exp_val| + exist = results.key? key + match = results.key?(key) && results[key] == exp_val if exist && match puts "PASS: #{key}" passed += 1 From 11c1e059d02b42e9cd8dc51e1916a88a158a8fb8 Mon Sep 17 00:00:00 2001 From: Lars Willighagen Date: Fri, 13 Jul 2018 00:23:56 +0200 Subject: [PATCH 4/5] Add spacing and colouring to tests --- test/test_all.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/test/test_all.rb b/test/test_all.rb index 17ec6ff..abc5cb4 100755 --- a/test/test_all.rb +++ b/test/test_all.rb @@ -11,6 +11,10 @@ warnings = 0 errors = 0 +log_PASS = "\e[0;32mPASS\e[39m" +log_WARN = "\e[0;33mWARN\e[39m" +log_ERROR = "\e[0;31mERROR\e[39m" + # generate coverage information for tests def coverage(scraperjsonpath, results) # get the element names @@ -34,6 +38,7 @@ def coverage(scraperjsonpath, results) coverage_files = [] tmpdir = Dir.mktmpdir puts "using tmp dir #{tmpdir}" +puts "" Dir.chdir(tmpdir) do scrapers.each do |scraper| scrapercount += 1 @@ -59,7 +64,7 @@ def coverage(scraperjsonpath, results) cleanurl = url.gsub(/:?\/+/, '_') Dir.chdir("output/#{cleanurl}") do unless File.exist? 'results.json' - puts "FAIL: no results from scraping" + puts "#{log_ERROR}: no results from scraping" errors += 1 coverage_files << coverage(scraper, {}) next @@ -79,22 +84,23 @@ def coverage(scraperjsonpath, results) exist = results.key? key match = results.key?(key) && results[key] == exp_val if exist && match - puts "PASS: #{key}" + puts "#{log_PASS}: #{key}" passed += 1 elsif exist - puts "WARN: #{key} exists in results but is not exactly the same" + puts "#{log_WARN}: #{key} exists in results but is not exactly the same" warnings += 1 else - puts "ERROR: #{key} not found in results" + puts "#{log_ERROR}: #{key} not found in results" puts "expected value: #{exp_val}" errors += 1 end end else - puts "WARN: no test found!" + puts "#{log_WARN}: no test found!" warnings += 1 coverage_files << coverage(scraper, {}) end + puts "" end end From 8f29ec46e065af08493be54839f4379e5575f1db Mon Sep 17 00:00:00 2001 From: Lars Willighagen Date: Fri, 13 Jul 2018 01:11:50 +0200 Subject: [PATCH 5/5] Fix coverage Before, coverage was 0 all round. Added another criterium: values shouldn't be empty. If they can be, any value is automatically counted, even if it isn't found. When testing, a property "foo" was added, without any sensible target. Naturally, this returned nothing. However, it still counted towards the coverage total. --- test/test_all.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_all.rb b/test/test_all.rb index abc5cb4..952b3ba 100755 --- a/test/test_all.rb +++ b/test/test_all.rb @@ -23,7 +23,7 @@ def coverage(scraperjsonpath, results) # calculate coverage elements.each do |element| # calculate coverage for this line - if results.detect { |result| result.is_a?(Hash) && result.key?(element) } + if results.key?(element) && !results[element]['value'].empty? coverage << 1 else coverage << 0