-
-
Save dnagir/5839ce80ec96f4d38c84 to your computer and use it in GitHub Desktop.
This file contains 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 skip_tracks(playlist, skip) | |
if skip > 0 | |
skip.times { playlist.push playlist.shift } | |
else | |
skip.abs.times { playlist.unshift playlist.pop } | |
end | |
playlist | |
end |
This file contains 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
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 | |
This file contains 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
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