Skip to content

Commit

Permalink
use "native" fakefs paths in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcisme committed Jun 26, 2012
1 parent 3709c5e commit f8bbda5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
6 changes: 3 additions & 3 deletions spec/guard/copy/target_spec.rb
Expand Up @@ -81,7 +81,7 @@ module Guard
dir('target')
target = Copy::Target.new('target')
target.resolve
target.paths.should == ['target']
target.paths.should == [ffs('target')]
end
end

Expand All @@ -91,7 +91,7 @@ module Guard
dir('t2')
target = Copy::Target.new('t*')
target.resolve
target.paths.should == ['t1', 't2']
target.paths.should == [ffs('t1'), ffs('t2')]
end
end

Expand All @@ -101,7 +101,7 @@ module Guard
dir('target_new', 2012)
target = Copy::Target.new('t*', :glob => :newest)
target.resolve
target.paths.should == ['target_new']
target.paths.should == [ffs('target_new')]
end
end

Expand Down
20 changes: 10 additions & 10 deletions spec/guard/copy_spec.rb
Expand Up @@ -156,8 +156,8 @@ module Guard
UI.should_receive(:info).with("Guard::Copy will copy files from:")
UI.should_receive(:info).with(" source")
UI.should_receive(:info).with("to:")
UI.should_receive(:info).with(" t1")
UI.should_receive(:info).with(" t2")
UI.should_receive(:info).with(" #{ffs('t1')}")
UI.should_receive(:info).with(" #{ffs('t2')}")
guard.start
end

Expand All @@ -170,8 +170,8 @@ module Guard
UI.should_receive(:info).with("Guard::Copy will delete files removed from:")
UI.should_receive(:info).with(" source")
UI.should_receive(:info).with("from:")
UI.should_receive(:info).with(" t1")
UI.should_receive(:info).with(" t2")
UI.should_receive(:info).with(" #{ffs('t1')}")
UI.should_receive(:info).with(" #{ffs('t2')}")
UI.should_receive(:info).any_number_of_times # don't worry about unrelated info
guard.start
end
Expand All @@ -194,7 +194,7 @@ module Guard
dir('target')
guard = Copy.new([], :from => 'source', :to => 'target')
UI.should_receive(:error).with('Guard::Copy - cannot copy, directory path does not exist:')
UI.should_receive(:error).with(' target/some/path/to/some')
UI.should_receive(:error).with(" #{ffs('target/some/path/to/some')}")
guard.start
expect {
guard.run_on_changes(['source/some/path/to/some/file'])
Expand Down Expand Up @@ -233,8 +233,8 @@ module Guard
dir('t2')
guard = Copy.new([], :from => 'source', :to => ['t1', 't2'], :verbose => true)
guard.start
UI.should_receive(:info).with('copying to t1/foo')
UI.should_receive(:info).with('copying to t2/foo')
UI.should_receive(:info).with("copying to #{ffs('t1/foo')}")
UI.should_receive(:info).with("copying to #{ffs('t2/foo')}")

guard.run_on_changes(['source/foo'])
end
Expand All @@ -260,7 +260,7 @@ module Guard
dir('target')
guard = Copy.new([], :from => 'source', :to => 'target', :delete => true)
UI.should_receive(:error).with("Guard::Copy - cannot delete, file does not exist:")
UI.should_receive(:error).with(" target/foo")
UI.should_receive(:error).with(" #{ffs('target/foo')}")
guard.start
expect { guard.run_on_removals(['source/foo']) }.to throw_symbol(:task_has_failed)
end
Expand Down Expand Up @@ -315,8 +315,8 @@ module Guard
file('t2/foo')
guard = Copy.new([], :from => 'source', :to => ['t1', 't2'], :delete => true, :verbose => true)
guard.start
UI.should_receive(:info).with('deleting t1/foo')
UI.should_receive(:info).with('deleting t2/foo')
UI.should_receive(:info).with("deleting #{ffs('t1/foo')}")
UI.should_receive(:info).with("deleting #{ffs('t2/foo')}")

guard.run_on_removals(['source/foo'])
end
Expand Down
9 changes: 5 additions & 4 deletions spec/spec_helper.rb
Expand Up @@ -10,14 +10,15 @@
# we need to be able to set mtime for newest directory tests
attr_accessor :mtime

# fakefs returns full paths, which is inconsistent with real globs
def to_s
name
end
end

module FileHelpers

# convert the path to the fakefs path
def ffs(path)
File.join(File.expand_path(File.join('..', '..'), __FILE__), path)
end

def file(f)
dir(File.dirname(f))
FileUtils.touch(f)
Expand Down

0 comments on commit f8bbda5

Please sign in to comment.