Forum: Ruby Do not understand the error messages.

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
39d8572ef267bc6771f1ef52527a9784?d=identicon&s=25 Roelof Wobben (Guest)
on 2014-06-21 15:01
(Received via mailing list)

    <meta http-equiv="content-type" content="text/html;
  <body text="#000000" bgcolor="#FFFFFF">
    Hello, <br>
    I have this : <br>
    def random_select(array, n)<br>
    &nbsp; numbers ={ Random.rand(array.length) } <br>
    &nbsp; numbers.each do |x| <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; puts array[x] <br>
    &nbsp; end<br>
    but I see these error messages: <br>
    <dl class="window" id="magic_block-output-1188" style="display:
      <dt class="fail">Makes a call to 'rand' or 'Array#shuffle'</dt>
      <dd class="fail">RSpec::Expectations::ExpectationNotMetError</dd>
      <dd class="fail">expected false to be true</dd>
    <dl class="window" id="magic_block-output-1188" style="display:
      <dt class="fail">returns only the values present in the array
        passed to the method</dt>
      <dd class="fail">RSpec::Expectations::ExpectationNotMetError</dd>
      <dd class="fail">expected [902, 467, 807, 569] to include 0</dd>
    <p>Can someone explain both to me ?<br>
620676bac4e81aae46ba1f252dbc76ce?d=identicon&s=25 Rylee Fowler (rylee)
on 2014-06-21 16:05
(Received via mailing list)
Hash: SHA512

These are RSpec issues. Something in your test suite is not meeting

On 6/21/2014 09:01, Roelof Wobben wrote:
> Roelof

- --
Rylee Fowler
Version: GnuPG v2.0.22 (MingW32)
Comment: Using GnuPG with Thunderbird -

39d8572ef267bc6771f1ef52527a9784?d=identicon&s=25 Roelof Wobben (Guest)
on 2014-06-21 16:10
(Received via mailing list)
I know that and there are not mine expectations but of the site


Rylee Fowler schreef op 21-6-2014 16:04:
39d8572ef267bc6771f1ef52527a9784?d=identicon&s=25 Roelof Wobben (Guest)
on 2014-06-21 18:15
(Received via mailing list)
I do not understand them on this way :

Makes a call to 'rand' or 'Array#shuffle'
RSpec::Expectations::ExpectationNotMetError expected false to be

I do use rand. See here :  numbers ={
Random.rand(array.length) }

returns only the values present in the array passed to the method
RSpec::Expectations::ExpectationNotMetError expected [902, 467,
807, 569] to include 0

I do that. I looked how many numbers there are. choose 2 numbers of it
by thier index.
and why schould it include 0 in a array which not contains 0.


Roelof Wobben schreef op 21-6-2014 16:10:
2ffac40f8a985a2b2749244b8a1c4161?d=identicon&s=25 Mike Stok (Guest)
on 2014-06-22 00:34
(Received via mailing list)
On Jun 21, 2014, at 12:14 PM, Roelof Wobben <> wrote:

> RSpec::Expectations::ExpectationNotMetError expected [902, 467,
>> Roelof

I am not familiar with rubymonkey, but the (perhaps poorly worded?)
error messages suggest that they expected you to call a different rand.
There is a rand method in Kernel, which is the one which you usually get
as Kernel is an ancestor of most objects.  For example in irb (an
interactive ruby shell):

~/tmp ∙ irb
irb(main):001:0> class X
irb(main):002:1>   def try_rand
irb(main):003:2>     rand(10)
irb(main):004:2>   end
irb(main):005:1> end
=> :try_rand
=> 2
irb(main):007:0> X.ancestors
=> [X, Object, Kernel, BasicObject]
irb(main):008:0> Kernel.rand(10)
=> 3

It also looks like they expect your random select to return items from
the array, and your method returns a list of array indices, you probably
picked index 0 at random, and although you print out array[x] the each
method on array returns the original array.  For example in irb:

~/tmp ∙ irb
irb(main):001:0> array = [902, 467, 807, 569]
=> [902, 467, 807, 569]
irb(main):002:0> random_indexes = [ 0, 3 ]
=> [0, 3]
irb(main):003:0> random_indexes.each do |x|
irb(main):004:1*   puts array[x]
irb(main):005:1> end
=> [0, 3]

And I guess the site was checking to see if 0 (one of the indexes you
returned) was in the original array.

Often the error messages guide you to a solution, for example they
suggest that they expected shuffle or rand to be called, so I would
probably have relied on Ruby's simplicity and seen what Array#shuffle
does, and how to get the first "n" elements of an Array - is a good place to start.

Hope this helps,


>>>> Hello,
>>>> Makes a call to 'rand' or 'Array#shuffle'
>>> UUqhnvQ4Gt6HO9laOfo3iHQhNydDhwSIa2B4eXhvRwtL3aI/ouw+80G65QKxKFr4
>>> /mvcaU/3imRhPs42q2F6Jxe2QmJhmYHOUyGmiisaJIdhv0dqYEE6J3XAEeaasARA
>>> ovdgzpUyZUcGXMY9qMEUU5F5NeMwlH/gjozWB440lbSO0U3nubjbG9EYw0czfh8=
>>> =WPM1
>>> -----END PGP SIGNATURE-----


Mike Stok <>

The "`Stok' disclaimers" apply.
This topic is locked and can not be replied to.