Last active
August 29, 2015 14:23
-
-
Save sometimesfood/7f17a020d3935da6fef4 to your computer and use it in GitHub Desktop.
Ruby Kernel methods: stubless stubs
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 | |
require 'minitest/autorun' | |
class SystemRunner | |
def ls | |
system 'ls' | |
end | |
end | |
class TestSystemRunner < SystemRunner | |
def initialize(mock_kernel) | |
@kernel = mock_kernel | |
super() | |
end | |
def system(*args) | |
@kernel.system(*args) | |
end | |
end | |
describe SystemRunner do | |
before :each do | |
@mock_kernel = Minitest::Mock.new | |
@runner = TestSystemRunner.new(@mock_kernel) | |
end | |
it 'should do something' do | |
@mock_kernel.expect(:system, true, ['ls']) | |
@runner.ls | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment