You need to use the mocha yields method . In addition, it is quite interesting to record the expectations for the reverse method. You need to do the following:
expects("`")
? , .
, :
module MyMethod
def self.mymethod
Dir.chdir('/tmp') do
`ls`
end
end
end
:
class MyMethodTest < Test::Unit::TestCase
def test_my_method
mock_block = mock
mock_directory_contents = mock
MyMethod.expects("`").with('ls').returns(mock_directory_contents)
Dir.expects(:chdir).yields(mock_block).returns(mock_directory_contents)
assert_equal mock_directory_contents, MyMethod.mymethod
end
end
, , backtick. - self, . MyMethod, , mymethod, .