forked from sevenwire/forgery
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed ruby facets because of potentially conflicting licenses and 'YAGNI'. Changing to RSpec for great profit. Improving random range extension.
- Loading branch information
Nathan Sutton
committed
Jun 1, 2008
1 parent
0c5211e
commit d68c02a
Showing
30 changed files
with
211 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'rake' | ||
require 'spec/rake/spectask' | ||
|
||
desc 'Default: run specs.' | ||
task :default => :spec | ||
|
||
desc 'Run the specs' | ||
Spec::Rake::SpecTask.new(:spec) do |t| | ||
t.spec_opts = ['--colour --format progress --loadby mtime --reverse'] | ||
t.spec_files = FileList['spec/**/*_spec.rb'] | ||
end |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Array | ||
def random | ||
self[Kernel.rand(size)] | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
class Range | ||
def at_rand | ||
Kernel.rand(self.last - self.first + 1) + self.first | ||
def random | ||
return nil unless self.max | ||
Integer(min) && Integer(max) | ||
Kernel.rand(self.max - self.min + 1) + self.min | ||
rescue ArgumentError | ||
self.to_a.random | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
class String | ||
def numerify | ||
self.gsub(/#/) { Kernel.rand(10).to_s } | ||
def to_numbers(replace='#') | ||
self.gsub(/#{replace}/){ Kernel.rand(10) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
class PersonalForgery < Forgery | ||
def self.gender | ||
%w{Male Female}.at_rand | ||
%w{Male Female}.random | ||
end | ||
|
||
def self.abbreviated_gender | ||
gender[0,1] | ||
end | ||
|
||
def self.shirt_size | ||
%w{XS S M L XL 2XL 3XL}.at_rand | ||
%w{XS S M L XL 2XL 3XL}.random | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1-(###)###-#### | ||
#-(###)###-#### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require File.dirname(__FILE__) + '/../spec_helper' | ||
|
||
describe Array do | ||
before do | ||
@array = [0,1,2,3,4,5,6,7,8,9] | ||
end | ||
|
||
it "should get a random item out of the array" do | ||
10.times { @array.should include(@array.random) } | ||
end | ||
|
||
it "should return nil if the array is empty" do | ||
[].random.should be_nil | ||
end | ||
end |
Oops, something went wrong.