Last active
December 18, 2015 08:29
-
-
Save sentientmonkey/5754521 to your computer and use it in GitHub Desktop.
minitest block testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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