Skip to content

Commit

Permalink
Fix specs to test better
Browse files Browse the repository at this point in the history
  • Loading branch information
iain committed Feb 12, 2012
1 parent 162d125 commit b6d4406
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
15 changes: 7 additions & 8 deletions spec/running_spec.rb
Expand Up @@ -3,7 +3,11 @@
describe Metrical, "running" do

before do
FileUtils.rm_f("tmp/metric_fu")
FileUtils.rm_rf("tmp/metric_fu")
end

it "has a clean start" do
File.exist?("tmp/metric_fu").should be_false
end

it "loads the .metrics file" do
Expand All @@ -30,13 +34,8 @@
end

def metrical(command = "--no-open")
$cache ||= {}
if $cache[command]
$cache[command]
else
stdin, stdout, stderr = Open3.popen3("metrical #{command}")
$cache[command] = [ stdout.read.strip, stderr.read.strip ]
end
stdin, stdout, stderr = Open3.popen3("metrical #{command}")
[ stdout.read.strip, stderr.read.strip ]
end

end
11 changes: 9 additions & 2 deletions spec/spec_helper.rb
Expand Up @@ -3,8 +3,15 @@

RSpec::Matchers.define :create_file do |expected|

match do |actual|
File.exist?(expected)
match do |block|
fail "The file #{expected} was already present before the block" if File.exist?(expected)
block.call
if File.exist?(expected)
true
else
system "ls #{File.dirname(expected)}"
false
end
end

end

0 comments on commit b6d4406

Please sign in to comment.