Sha256: 4dabb89551c160dbd3b5c986dea0be62d0317ec11c5841d221e20fefdcab9f3d

Contents?: true

Size: 501 Bytes

Versions: 7

Compression:

Stored size: 501 Bytes

Contents

# frozen_string_literal: true

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

7 entries across 7 versions & 1 rubygems

Version Path
darthjee-core_ext-1.7.3 spec/support/shared_examples/array/array_random.rb
darthjee-core_ext-1.7.2 spec/support/shared_examples/array/array_random.rb
darthjee-core_ext-1.7.1 spec/support/shared_examples/array/array_random.rb
darthjee-core_ext-1.7.0 spec/support/shared_examples/array/array_random.rb
darthjee-core_ext-1.6.2 spec/support/shared_examples/array/array_random.rb
darthjee-core_ext-1.6.1 spec/support/shared_examples/array/array_random.rb
darthjee-core_ext-1.6.0 spec/support/shared_examples/array/array_random.rb