Skip to content

Commit 5963844

Browse files
committed
Made the tests pass; minor cleanup
1 parent 29df617 commit 5963844

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

test/test_address_extractor.rb

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
$: << File.dirname(__FILE__)+"/../lib"
2-
3-
require 'test/unit'
4-
require 'address_extractor.rb'
5-
require 'test_helper.rb'
1+
require 'address_extractor'
2+
require 'test_helper'
63
include TestDataHelper
74

85
class AddressExtractorTest < Test::Unit::TestCase
9-
include Helpers
10-
116
def test_first_address_extraction
127
each_test_data do |test_data|
138
address = AddressExtractor.first_address(test_data[:input])
149
flunk "No address found in:\n#{test_data[:input]}" if address.nil?
1510
assert_equal_hashes address, test_data[:expected_output].first
1611
end
1712
end
18-
13+
1914
def test_find_addresses
2015
each_test_data do |test_data|
2116
addresses = AddressExtractor.find_addresses(test_data[:input])
@@ -25,11 +20,11 @@ def test_find_addresses
2520
end
2621
end
2722
end
28-
23+
2924
def test_replace_first_address
3025
string = AddressExtractor.replace_first_address(test_data.first[:input]) do |address_hash, address|
3126
assert_equal_hashes address_hash, test_data.first[:expected_output].first
32-
assert_match /^\s*123 Foo St., Someplace FL\s*/, address
27+
assert_match /^\s*123 Foo St., Someplace FL\s*/, address
3328
"skidoosh"
3429
end
3530
assert string =~ /Please send the package to skidoosh/
@@ -70,7 +65,7 @@ def test_no_addresses_found
7065

7166
test_input "Let's meet tomorrow at noon at 123 Foo Bar Street, Scooby, NY 12345",
7267
{ :street1 => "123 Foo Bar Street", :street2 => nil, :city => "Scooby", :state => "NY", :zip => "12345" }
73-
68+
7469
test_input "Let's meet tomorrow at noon at 123 Foo Bar Street, Scooby, NY, 12345",
7570
{ :street1 => "123 Foo Bar Street", :street2 => nil, :city => "Scooby", :state => "NY", :zip => "12345" }
7671

@@ -85,4 +80,4 @@ def test_no_addresses_found
8580

8681
test_input "Apple Computer, Inc. 1 Infinite Loop, Cupertino, CA 95014",
8782
{ :street1 => "1 Infinite Loop", :street2 => nil, :city => "Cupertino", :state => "CA", :zip => "95014" }
88-
83+

test/test_helper.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
module TestDataHelper
2-
3-
TEST_DATA = []
1+
require 'test/unit'
42

3+
module TestDataHelper
54
def test_input(input_string, *expected_outputs)
65
test_data << { :input => input_string, :expected_output => expected_outputs }
76
end
87

98
def each_test_data
109
test_data.each { |t| yield(t) }
1110
end
12-
11+
1312
def test_data
14-
TEST_DATA
13+
@@test_data ||= []
1514
end
16-
1715
end
1816

1917
module Helpers
20-
2118
def assert_equal_hashes(a,b)
2219
(a.keys + b.keys).uniq.each do |k|
2320
assert_equal a[k], b[k], "a[#{k.inspect}] = #{a[k].inspect} != b[#{k.inspect}] = #{b[k].inspect}"
2421
end
2522
end
26-
23+
end
24+
25+
class Test::Unit::TestCase
26+
include Helpers
2727
end

0 commit comments

Comments
 (0)