On Jun 21, 2014, at 12:14 PM, Roelof W. [email protected] 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
irb(main):006:0> X.new.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
902
569
=> [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 -
Class: Array (Ruby 2.1.2) is a good place to start.
Hope this helps,
Mike
Hello,
Makes a call to ‘rand’ or ‘Array#shuffle’
UUqhnvQ4Gt6HO9laOfo3iHQhNydDhwSIa2B4eXhvRwtL3aI/ouw+80G65QKxKFr4
/mvcaU/3imRhPs42q2F6Jxe2QmJhmYHOUyGmiisaJIdhv0dqYEE6J3XAEeaasARA
ovdgzpUyZUcGXMY9qMEUU5F5NeMwlH/gjozWB440lbSO0U3nubjbG9EYw0czfh8=
=WPM1
-----END PGP SIGNATURE-----
–
Mike S. [email protected]
http://www.stok.ca/~mike/
The “`Stok’ disclaimers” apply.