From 3f29043f456af423c4ec7599040625c87321aa77 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 15 Sep 2007 21:39:04 +0000 Subject: Added Array#rand (closes #9170) [norbert] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7486 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/test/abstract_unit.rb | 9 +++++++++ activesupport/test/core_ext/array_ext_test.rb | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb index 8e237beac2..fba9ff97b2 100644 --- a/activesupport/test/abstract_unit.rb +++ b/activesupport/test/abstract_unit.rb @@ -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 diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 8c2edfc457..a5bae8c900 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -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 -- cgit v1.2.3