Skip to content

Instantly share code, notes, and snippets.

@lucassus
Created March 1, 2012 21:11
Show Gist options
  • Save lucassus/1953255 to your computer and use it in GitHub Desktop.
Save lucassus/1953255 to your computer and use it in GitHub Desktop.
def shuffled_users
shuffled = users.sort_by { rand }
while shuffled == users
shuffled = users.sort_by { rand }
end
shuffled
end
describe "#shuffled_users" do
subject { described_class.new(users) }
it 'should return users in random order' do
rand_sequence = [2, 1, 3]
subject.should_receive(:rand).and_return(*rand_sequence)
subject.shuffled_users.should_not == subject.users
end
it 'should continue shuffling' do
first_run = [1, 2, 3]
rand_sequence = first_run += [2, 1, 3]
subject.should_receive(:rand).and_return(*rand_sequence)
subject.shuffled_users.should_not == subject.users
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment