Skip to content

Instantly share code, notes, and snippets.

@dnagir
Created July 31, 2010 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnagir/5839ce80ec96f4d38c84 to your computer and use it in GitHub Desktop.
Save dnagir/5839ce80ec96f4d38c84 to your computer and use it in GitHub Desktop.
def skip_tracks(playlist, skip)
if skip > 0
skip.times { playlist.push playlist.shift }
else
skip.abs.times { playlist.unshift playlist.pop }
end
playlist
end
Feature: Track skipping
In order to ignore some tracks
I want to be able to skip them
Scenario Outline: Skipping forward
Given the playlist "a, b, c, d"
When I skip <skip> track forward
Then I should have the playlist "<result>"
Examples:
| skip | result |
| 1 | b,c,d,a |
| 2 | c,d,a,b |
| 3 | d,a,b,c |
| 4 | a,b,c,d |
| 5 | b,c,d,a |
| 6 | c,d,a,b |
Scenario Outline: Skipping backward
Given the playlist "a, b, c, d"
When I skip <skip> track backward
Then I should have the playlist "<result>"
Examples:
| skip | result |
| 1 | d,a,b,c |
| 2 | c,d,a,b |
| 3 | b,c,d,a |
| 4 | a,b,c,d |
| 5 | d,a,b,c |
| 6 | c,d,a,b |
Given /^the playlist "([^"]*)"$/ do |list|
@playlist = list.split(',').map { |x| x.strip }
end
When /^I skip (\d+) tracks? (\w+)$/ do |count, direction|
skip_count = count.to_i * (direction == 'forward' ? 1 : -1)
@playlist = skip_tracks(@playlist, skip_count)
end
Then /^I should have the playlist "([^"]*)"$/ do |list|
@playlist.should == list.split(',').map { |x| x.strip }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment