Created
December 26, 2010 12:11
-
-
Save Atalanta/755377 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
require 'rspec' | |
require 'fileutils' | |
require 'find' | |
class OggFileMover | |
def find_ogg_dirs(path) | |
dirs = Array.new | |
Find.find(path) do |p| | |
dirs << File.dirname(p) if p =~ /.*ogg$/ | |
end | |
dirs | |
end | |
end | |
# Test data: | |
# % tree | |
# . | |
# ├── ogg-mover.rb | |
# └── testdata | |
# └── oggs | |
# ├── arnold | |
# │ └── track1.ogg | |
# ├── bach | |
# │ └── track1.ogg | |
# ├── chopin | |
# │ └── track1.ogg | |
# ├── debussy | |
# │ └── track1.ogg | |
# └── elgar | |
# └── track1.ogg | |
describe "Ogg file mover" do | |
it "should list all directories containing ogg files" do | |
mover = OggFileMover.new | |
dirs = mover.find_ogg_dirs('testdata/oggs') | |
dirs.should == ["arnold", "bach", "chopin", "debussy", "elgar"] | |
FileUtils.mkdir 'testdata/oggs/faure' | |
FileUtils.touch('testdata/oggs/faure/track1.ogg') | |
dirs.should == ["arnold", "bach", 'chopin', 'debussy', 'elgar', 'faure'] | |
FileUtils.rm_f('testdata/oggs/faure') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
% rspec ogg-mover.rb
F
Failures:
Failure/Error: dirs.should == ["arnold", "bach", "chopin", "debussy", "elgar"]
expected: ["arnold", "bach", "chopin", "debussy", "elgar"],
got: ["testdata/oggs/arnold", "testdata/oggs/bach", "testdata/oggs/chopin", "testdata/oggs/debussy", "testdata/oggs/elgar"](using ==)
Diff:
@@ -1,2 +1,6 @@
-["arnold", "bach", "chopin", "debussy", "elgar"]
+["testdata/oggs/arnold",
./ogg-mover.rb:20:in `block (2 levels) in <top (required)>'
Finished in 0.04036 seconds
1 example, 1 failure