Skip to content

Instantly share code, notes, and snippets.

@vjdhama
Last active September 27, 2015 15:57
Show Gist options
  • Save vjdhama/c1a0fc972e38c8dd04db to your computer and use it in GitHub Desktop.
Save vjdhama/c1a0fc972e38c8dd04db to your computer and use it in GitHub Desktop.
# Code
if Dir.exists?(name) || File.exists?(name)
STDERR.puts "file or directory #{name} already exists"
puts opts
exit 1
end
# Spec
module Init
def exit(status=0)
puts "my exit running"
end
end
describe Init do
it "prints error to STDERR" do
Dir.mkdir_p("#{__DIR__}/tmp")
stderr = File.open("/dev/null")
stderr.reopen(STDERR)
STDERR.reopen(File.open("#{__DIR__}/test_stderr", "w"))
Crystal::Init.run(["lib", "#{__DIR__}/tmp"])
puts "Spec Check"
File.read("#{__DIR__}/test_stderr").should eq("file or directory #{__DIR__}/tmp already exists")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment