mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Added Array#rand (closes #9170) [norbert]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7486 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
0b0931e150
commit
3f29043f45
5 changed files with 35 additions and 3 deletions
|
@ -1,5 +1,11 @@
|
|||
*SVN*
|
||||
|
||||
* Added Array#rand #9170 [norbert]. Examples:
|
||||
|
||||
[].rand # => nil
|
||||
['a'].rand # => 'a'
|
||||
[1,2,3].rand # => 1 or 2 or 3
|
||||
|
||||
* Deprecation: removed Reloadable. [Jeremy Kemper]
|
||||
|
||||
* Make the utf-handler return the correct value for non-matching regular expressions. Closes #9049 [manfred]
|
||||
|
|
|
@ -18,7 +18,6 @@ task :default => :test
|
|||
Rake::TestTask.new { |t|
|
||||
t.pattern = 'test/**/*_test.rb'
|
||||
t.verbose = true
|
||||
t.warning = true
|
||||
}
|
||||
|
||||
# Create compressed packages
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
require File.dirname(__FILE__) + '/array/conversions'
|
||||
require File.dirname(__FILE__) + '/array/grouping'
|
||||
require File.dirname(__FILE__) + '/array/extract_options'
|
||||
require File.dirname(__FILE__) + '/array/grouping'
|
||||
require File.dirname(__FILE__) + '/array/random_access'
|
||||
|
||||
class Array #:nodoc:
|
||||
include ActiveSupport::CoreExtensions::Array::Conversions
|
||||
include ActiveSupport::CoreExtensions::Array::Grouping
|
||||
include ActiveSupport::CoreExtensions::Array::ExtractOptions
|
||||
include ActiveSupport::CoreExtensions::Array::Grouping
|
||||
include ActiveSupport::CoreExtensions::Array::RandomAccess
|
||||
end
|
||||
|
|
|
@ -3,5 +3,14 @@ require 'test/unit'
|
|||
$:.unshift "#{File.dirname(__FILE__)}/../lib"
|
||||
require 'active_support'
|
||||
|
||||
# Wrap tests that use Mocha and skip if unavailable.
|
||||
def uses_mocha(test_name)
|
||||
require 'rubygems'
|
||||
require 'mocha'
|
||||
yield
|
||||
rescue LoadError
|
||||
$stderr.puts "Skipping #{test_name} tests. `gem install mocha` and try again."
|
||||
end
|
||||
|
||||
# Show backtraces for deprecated behavior for quicker cleanup.
|
||||
ActiveSupport::Deprecation.debug = true
|
||||
|
|
|
@ -200,3 +200,19 @@ class ArrayExtractOptionsTests < Test::Unit::TestCase
|
|||
assert_equal({:a=>:b}, [1, {:a=>:b}].extract_options!)
|
||||
end
|
||||
end
|
||||
|
||||
uses_mocha "ArrayExtRandomTests" do
|
||||
|
||||
class ArrayExtRandomTests < Test::Unit::TestCase
|
||||
def test_random_element_from_array
|
||||
assert_nil [].rand
|
||||
|
||||
Kernel.expects(:rand).with(1).returns(0)
|
||||
assert_equal 'x', ['x'].rand
|
||||
|
||||
Kernel.expects(:rand).with(3).returns(1)
|
||||
assert_equal 2, [1, 2, 3].rand
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue