Permalink
Browse files

changed so DICTIONARY is set on module loading

  • Loading branch information...
1 parent ed15f4b commit 64a784a485d30e673417a93fb670c1020e22d423 Jared Carroll committed Dec 11, 2008
Showing with 10 additions and 19 deletions.
  1. +5 −12 lib/webster.rb
  2. +5 −7 test/webster_test.rb
View
@@ -1,18 +1,11 @@
-class Webster
+module Webster
- DICTIONARY_FILE = File.join(File.dirname(__FILE__), "words")
-
- attr_accessor :dictionary
-
- def initialize
- @dictionary = []
- File.open(DICTIONARY_FILE) do |file|
- @dictionary = file.readlines.collect { |word| word.chomp }
- end
+ DICTIONARY = File.open(File.join(File.dirname(__FILE__), 'words')) do |file|
+ file.readlines.collect {|each| each.chomp}
end
-
+
def random
- dictionary[rand(dictionary.size)]
+ DICTIONARY[rand(DICTIONARY.size)]
end
end
View
@@ -1,16 +1,15 @@
require 'test/unit'
require 'rubygems'
require 'shoulda'
-require 'quietbacktrace'
-require 'redgreen'
require File.join(File.dirname(__FILE__), "..", "lib", "webster")
class WebsterTest < Test::Unit::TestCase
+ include Webster
+
context "#dictionary" do
setup do
- @webster = Webster.new
- @dictionary = @webster.dictionary
+ @dictionary = Webster::DICTIONARY
@blacklist = %w(bastaard bastard bastardly bastardy bedamn bitch damnable damnably damnation
damnatory damned damner damnify damnii damning damningly damnonii damnous damnously
shita shitepoke shother shittah shittim undamned undamning undamn
@@ -29,8 +28,7 @@ class WebsterTest < Test::Unit::TestCase
context "#random" do
setup do
- @webster = Webster.new
- @random = @webster.random
+ @random = random
end
should "be a word" do
@@ -54,7 +52,7 @@ class WebsterTest < Test::Unit::TestCase
end
should "be a word in the dictionary" do
- assert @webster.dictionary.include?(@random)
+ assert Webster::DICTIONARY.include?(@random)
end
end

0 comments on commit 64a784a

Please sign in to comment.