From 43649f306c9a63832b968cef91c1f6b0d808d065 Mon Sep 17 00:00:00 2001 From: John Britton Date: Tue, 11 Sep 2012 16:22:39 -0700 Subject: [PATCH 1/2] add tests for whitespace, make tests pass --- lib/swot.rb | 4 +--- test/test_swot.rb | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/swot.rb b/lib/swot.rb index bf11fb3f1f..dee1355225 100644 --- a/lib/swot.rb +++ b/lib/swot.rb @@ -131,8 +131,8 @@ module Swot # Returns true if the domain name belongs to an academic institution; # false oterwise. def is_academic?(text) - text.strip! return false if text.nil? + text.strip! begin domain = get_domain(text) return false if domain.nil? @@ -169,7 +169,6 @@ module Swot # Returns true if the domain name belongs to a known academic instition; # false otherwise. def match_academic_domain?(domain) - domain.strip! File.exists?("#{File.expand_path(__FILE__+'/..')}/domains/#{domain.tld}/#{domain.sld}") end @@ -177,7 +176,6 @@ module Swot # # Return the institution name, or nil if not found. def name_from_academic_domain(domain) - domain.strip! begin file = File.open("#{File.expand_path(__FILE__+'/..')}/domains/#{domain.tld}/#{domain.sld}", "rb") contents = file.read diff --git a/test/test_swot.rb b/test/test_swot.rb index 8edaaeee89..41596655ce 100644 --- a/test/test_swot.rb +++ b/test/test_swot.rb @@ -38,6 +38,10 @@ class TestEmail < Test::Unit::TestCase assert_equal Swot::is_academic?(nil), false assert_equal Swot::is_academic?(''), false assert_equal Swot::is_academic?('the'), false + + assert_equal Swot::is_academic?(' stanford.edu'), true + assert_equal Swot::is_academic?('lee@strath.ac.uk '), true + assert_equal Swot::is_academic?(' gmail.com '), false end should "returns name of valid institution" do From 5c55df4de5b537e879073b26d140527608538385 Mon Sep 17 00:00:00 2001 From: John Britton Date: Tue, 11 Sep 2012 16:34:08 -0700 Subject: [PATCH 2/2] fix whitespace --- test/test_swot.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_swot.rb b/test/test_swot.rb index 41596655ce..3399911785 100644 --- a/test/test_swot.rb +++ b/test/test_swot.rb @@ -40,7 +40,7 @@ class TestEmail < Test::Unit::TestCase assert_equal Swot::is_academic?('the'), false assert_equal Swot::is_academic?(' stanford.edu'), true - assert_equal Swot::is_academic?('lee@strath.ac.uk '), true + assert_equal Swot::is_academic?('lee@strath.ac.uk '), true assert_equal Swot::is_academic?(' gmail.com '), false end