Permalink
Browse files

Fix randomness in lorem ipsum words method and friends

  • Loading branch information...
1 parent 427ce83 commit 8b392bfed259d55a63c4d43549b8b3731dabcefb @nate nate committed Sep 5, 2011
View
4 lib/forgery/forgery/basic.rb
@@ -82,7 +82,7 @@ def self.number(options={})
options = {:at_least => 1,
:at_most => 10}.merge(options)
- Forgery::Extend((options[:at_least]..options[:at_most])).random
+ Forgery::Extend(options[:at_least]..options[:at_most]).random
end
def self.text(options={})
@@ -100,7 +100,7 @@ def self.text(options={})
allowed_characters += NUMERIC if options[:allow_numeric]
allowed_characters += SPECIAL_CHARACTERS if options[:allow_special]
- length = options[:exactly] || Forgery::Extend((options[:at_least]..options[:at_most])).random
+ length = options[:exactly] || Forgery::Extend(options[:at_least]..options[:at_most]).random
Forgery::Extend(allowed_characters).random_subset(length).join
end
View
2 lib/forgery/forgery/lorem_ipsum.rb
@@ -99,7 +99,7 @@ def self.range_from_quantity(quantity, options={})
return quantity if quantity.is_a?(Range)
if options[:random]
- start = (0..options[:random_limit]).random
+ start = Forgery::Extend(0..options[:random_limit]).random
start..(start+quantity-1)
else
0..(quantity-1)
View
12 spec/extensions/range_spec.rb
@@ -3,29 +3,29 @@
describe Range do
it "should get a random number out of the range" do
- range = Forgery::Extend((0..9))
+ range = Forgery::Extend(0..9)
10.times { range.should include(range.random) }
end
it "should not take a long time when the range is huge" do
- Timeout.timeout(1){Forgery::Extend((1234567890..12345678901234567890)).random}.should_not raise_error(Timeout::Error)
+ Timeout.timeout(1){Forgery::Extend(1234567890..12345678901234567890).random}.should_not raise_error(Timeout::Error)
end
it "should return nil for a random number from a reverse range" do
- 10.times { Forgery::Extend((9..0)).random.should be_nil }
+ 10.times { Forgery::Extend(9..0).random.should be_nil }
end
it "should get a random string our of the range" do
- range = Forgery::Extend(("a".."z"))
+ range = Forgery::Extend("a".."z")
10.times { range.should include(range.random) }
end
it "should return nil if the maximum is less than the minimum" do
- Forgery::Extend(("z".."a")).random.should be_nil
+ Forgery::Extend("z".."a").random.should be_nil
end
it "should not return the maximum at excluded range" do
Kernel.should_receive(:rand).with(9).and_return(8)
- Forgery::Extend((0...9)).random.should_not be_equal 9
+ Forgery::Extend(0...9).random.should_not be_equal 9
end
end
View
4 spec/forgery/lorem_ipsum_spec.rb
@@ -94,6 +94,10 @@
it "should return text with 1 or more character" do
Forgery::LoremIpsum.words.size.should >= 1
end
+
+ it "should return a random set of words" do
+ Forgery::LoremIpsum.words(2, :random => true)
+ end
end
describe ".word" do

0 comments on commit 8b392bf

Please sign in to comment.