Permalink
Browse files

Ensuring newlines get stripped as unix seems to add trailing chars li…

…ke that.
  • Loading branch information...
1 parent 6621823 commit 4cede8411d1822c99ff4ef0deb64809a3629f4fc @jnunemaker committed Mar 8, 2010
Showing with 13 additions and 1 deletion.
  1. +1 −0 Rakefile
  2. +6 −1 lib/wand.rb
  3. +1 −0 test/helper.rb
  4. +5 −0 test/test_wand.rb
View
1 Rakefile
@@ -16,6 +16,7 @@ begin
gem.add_dependency 'mime-types'
gem.add_development_dependency 'shoulda'
gem.add_development_dependency 'yard'
+ gem.add_development_dependency 'mocha'
end
Jeweler::GemcutterTasks.new
rescue LoadError
View
7 lib/wand.rb
@@ -5,7 +5,7 @@ module Wand
def self.wave(path)
type = MIME::Types.type_for(path)[0].to_s
- type = `#{executable} --mime --brief #{path}`.split(';')[0] if type.nil? || type == ''
+ type = from_executable(path).split(';')[0].strip if type.nil? || type == ''
type = nil if type =~ /cannot\sopen/
type
end
@@ -18,4 +18,9 @@ def self.executable
def self.executable=(path)
@executable = path
end
+
+ private
+ def self.from_executable(path)
+ `#{executable} --mime --brief #{path}`
+ end
end
View
1 test/helper.rb
@@ -1,6 +1,7 @@
require 'rubygems'
require 'test/unit'
require 'shoulda'
+require 'mocha'
require 'pathname'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
View
5 test/test_wand.rb
@@ -44,5 +44,10 @@ class TestWand < Test::Unit::TestCase
Wand.executable = '/usr/local/bin/file'
assert_equal '/usr/local/bin/file', Wand.executable
end
+
+ should "strip newlines and such" do
+ Wand.expects(:from_executable).returns("image/jpeg\n")
+ assert_equal "image/jpeg", Wand.wave(FilePath.join(name).expand_path.to_s)
+ end
end
end

0 comments on commit 4cede84

Please sign in to comment.