Created
          March 1, 2012 21:11 
        
      - 
      
- 
        Save lucassus/1953255 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def shuffled_users | |
| shuffled = users.sort_by { rand } | |
| while shuffled == users | |
| shuffled = users.sort_by { rand } | |
| end | |
| shuffled | |
| end | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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