secret
Last active

  • Download Gist
cycle_tracks.rb
Ruby
1 2 3 4 5 6 7 8
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
skipping.feature
Cucumber
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
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 |
skipping_steps.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.