Skip to content
Browse files

Randgen.word should not return a string that does not match /^\w+$/

  • Loading branch information...
1 parent 7a090e9 commit 1d1f192f27b93796f9c9cf4152311127721ee00e @benburkert committed Sep 8, 2008
Showing with 14 additions and 1 deletion.
  1. +5 −1 lib/randgen.rb
  2. +9 −0 spec/unit/randgen_spec.rb
View
6 lib/randgen.rb
@@ -31,7 +31,11 @@ def self.alpha_numeric(options = {})
end
def self.word(options = {})
- Dictionary.words(options).pick
+ begin
+ word = Dictionary.words(options).pick
+ end until word =~ /^\w+$/
+
+ word
end
def self.sentence(options = {})
View
9 spec/unit/randgen_spec.rb
@@ -70,6 +70,15 @@
Randgen.word(:length => length).length.should == length
end
end
+
+ it "should not return a string that is not a word" do
+ strings = %w[foo's bars]
+ Dictionary.should_receive(:words).at_least(1).and_return strings
+
+ 100.times do
+ Randgen.word.should_not == "foo's"
+ end
+ end
end
describe ".sentence" do

0 comments on commit 1d1f192

Please sign in to comment.
Something went wrong with that request. Please try again.