Skip to content

Commit

Permalink
Fix path to String coercion
Browse files Browse the repository at this point in the history
  • Loading branch information
lwoggardner committed Feb 6, 2014
1 parent 729c7dd commit 1a091c7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/ffi-xattr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class Xattr
# Create a new Xattr instance with path.
# Use <tt>:no_follow => true</tt> in options to work on symlink itself instead of following it.
def initialize(path, options = {})
raise Errno::ENOENT, path unless File.exist?(path)
@path = path.to_str
raise Errno::ENOENT, @path unless File.exist?(@path)
@no_follow = !!options[:no_follow]
end

Expand Down
17 changes: 5 additions & 12 deletions spec/xattr_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,13 @@
lambda{ Xattr.new(1) }.should raise_error(TypeError)
end

class SuperPath
def initialize(path)
@path = path
end

def to_str
@path.dup
end
end
it "should work with object that can be converted to string" do
super_path = double("super_path")
super_path.should_receive(:to_str).and_return(path)

it "should work with object that can be directly converted to string" do
super_path = SuperPath.new(path)
Xattr.new(super_path).set('user.foo', 'bar')
Xattr.new(super_path).get('user.foo').should == 'bar'

Xattr.new(path).get('user.foo').should == 'bar'
end

describe "respecting :no_follow option" do
Expand Down

0 comments on commit 1a091c7

Please sign in to comment.