[macruby-changes] [1462] MacRuby/branches/experimental/spec/frozen/core/array/sample_spec.rb

source_changes at macosforge.org source_changes at macosforge.org
Wed Apr 22 15:11:14 PDT 2009


Revision: 1462
          http://trac.macosforge.org/projects/ruby/changeset/1462
Author:   eloy.de.enige at gmail.com
Date:     2009-04-22 15:11:14 -0700 (Wed, 22 Apr 2009)
Log Message:
-----------
Correcting style in last commit:

* No need for 2 arrays in the first test case.
* Adding guards for versions < 1.9
* Fixing descriptions (we don't use should).

Modified Paths:
--------------
    MacRuby/branches/experimental/spec/frozen/core/array/sample_spec.rb

Modified: MacRuby/branches/experimental/spec/frozen/core/array/sample_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/array/sample_spec.rb	2009-04-22 22:11:05 UTC (rev 1461)
+++ MacRuby/branches/experimental/spec/frozen/core/array/sample_spec.rb	2009-04-22 22:11:14 UTC (rev 1462)
@@ -1,20 +1,23 @@
 require File.dirname(__FILE__) + '/../../spec_helper'
 require File.dirname(__FILE__) + '/fixtures/classes'
 
+describe "Array#sample" do
+  ruby_version_is "" ... "1.9" do
+    it "is not defined" do
+      lambda { [].sample }.should raise_error(NoMethodError)
+    end
+  end
 
-describe "Array#sample" do
   ruby_version_is "1.9" do
-    it "should select an value from the array" do
+    it "selects a random value from the array" do
       a = [1,2,3,4]
-      b = [4,3,2,1]
       10.times {
-        b.include?(a.sample).should be_true
+        a.include?(a.sample).should be_true
       }
     end
 
-    it "should return a nil value if the array is empty" do
-      a = []
-      a.sample.should be_nil
+    it "returns nil for empty arrays" do
+      [].sample.should be_nil
     end
   end
 end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090422/47b35304/attachment-0001.html>


More information about the macruby-changes mailing list