Sha256: 02db67862588a283117cfd4dd49f27c82d415ee6fdcf72f91ea0cbba87d71e83

Contents?: true

Size: 461 Bytes

Versions: 16

Compression:

Stored size: 461 Bytes

Contents

shared_examples 'a method that returns a random element' do |method|
  let(:array) { [ 7, 5, 3 ] }

  (0..2).each do |index|
    context "when random returns #{index}" do
      let!(:expected) { array[index] }
      before do
        allow_any_instance_of(Array).to receive(:rand).with(array.size) { index }
      end

      it 'returns the randomized index of the array' do
        expect(array.public_send(method)).to eq(expected)
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
darthjee-core_ext-1.5.6 spec/support/shared_examples/array_random.rb
darthjee-core_ext-1.5.5 spec/support/shared_examples/array_random.rb
darthjee-core_ext-1.5.4 spec/support/shared_examples/array_random.rb
darthjee-core_ext-1.5.3 spec/support/shared_examples/array_random.rb
darthjee-core_ext-1.5.2 spec/support/shared_examples/array_random.rb
darthjee-core_ext-1.5.1 spec/support/shared_examples/array_random.rb
darthjee-core_ext-1.5.0 spec/support/shared_examples/array_random.rb
darthjee-core_ext-1.4.1 spec/support/shared_examples/array_random.rb
darthjee-core_ext-1.4.0 spec/support/shared_examples/array_random.rb
darthjee-core_ext-1.3.1 spec/support/shared_examples/array_random.rb
darthjee-core_ext-1.3.0 spec/support/shared_examples/array_random.rb
darthjee-core_ext-1.2.6 spec/support/shared_examples/array_random.rb
bidu-core_ext-1.2.5 spec/support/shared_examples/array_random.rb
bidu-core_ext-1.2.4 spec/support/shared_examples/array_random.rb
bidu-core_ext-1.2.3 spec/support/shared_examples/array_random.rb
bidu-core_ext-1.2.2 spec/support/shared_examples/array_random.rb