Skip to content

Instantly share code, notes, and snippets.

@sentientmonkey
Last active December 18, 2015 08:29
Show Gist options
  • Select an option

  • Save sentientmonkey/5754521 to your computer and use it in GitHub Desktop.

Select an option

Save sentientmonkey/5754521 to your computer and use it in GitHub Desktop.
minitest block testing
#!/usr/bin/env rspec
class Foo
def foo!
File.open("foo.txt", "w") do |f|
f.write "hello!"
end
end
end
describe Foo do
let(:foo){ Foo.new }
let(:file){ double(:file) }
it "should call foo" do
File.should_receive(:open).with("foo.txt", "w").and_yield(file)
file.should_receive(:write).with("hello!")
foo.foo!
end
end
#!/usr/bin/env ruby -w
require 'rubygems'
require 'minitest/autorun'
class Foo
def foo!
File.open("foo.txt", "w") do |f|
f.write "hello!"
raise "I'm not tested!!"
end
end
end
describe Foo do
let(:foo){ Foo.new }
let(:file){ Minitest::Mock.new }
it "should call foo" do
File.stub(:open, file) do
foo.foo!
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment