Skip to content

Instantly share code, notes, and snippets.

@Atalanta
Created December 26, 2010 12:11
Show Gist options
  • Save Atalanta/755377 to your computer and use it in GitHub Desktop.
Save Atalanta/755377 to your computer and use it in GitHub Desktop.
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
@Atalanta
Copy link
Author

% rspec ogg-mover.rb
F

Failures:

  1. Ogg file mover should list all directories containing ogg files
    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",
    • "testdata/oggs/bach",
    • "testdata/oggs/chopin",
    • "testdata/oggs/debussy",
    • "testdata/oggs/elgar"]

    ./ogg-mover.rb:20:in `block (2 levels) in <top (required)>'

Finished in 0.04036 seconds
1 example, 1 failure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment