Browse files

converted Webster from a module into a class, renamed #random to #ran…

…dom_word
  • Loading branch information...
1 parent aa78429 commit bd526412bc25e5db2de84d518a908e3f068dbc44 Jared Carroll committed Jan 8, 2009
Showing with 7 additions and 8 deletions.
  1. +2 −2 lib/webster.rb
  2. +5 −6 test/webster_test.rb
View
4 lib/webster.rb
@@ -1,10 +1,10 @@
-module Webster
+class Webster
DICTIONARY = File.open(File.join(File.dirname(__FILE__), 'words')) do |file|
file.readlines.collect {|each| each.chomp}
end
- def random
+ def random_word
DICTIONARY[rand(DICTIONARY.size)]
end
View
11 test/webster_test.rb
@@ -5,8 +5,6 @@
class WebsterTest < Test::Unit::TestCase
- include Webster
-
context "#dictionary" do
setup do
@dictionary = Webster::DICTIONARY
@@ -21,17 +19,18 @@ class WebsterTest < Test::Unit::TestCase
should "not contain offensive words or offensive-sounding words" do
@blacklist.each do |word|
- assert !@dictionary.include?(word), "The blacklist word, #{word}, is in the dictionary."
+ assert ! @dictionary.include?(word), "The blacklist word, #{word}, is in the dictionary."
end
end
end
- context "#random" do
+ context "#random_word" do
setup do
- @random = random
+ webster = Webster.new
+ @random = webster.random_word
end
- should "be a word" do
+ should "be a String" do
assert_kind_of String, @random
end

0 comments on commit bd52641

Please sign in to comment.