これが以前に尋ねられた場合はお詫び申し上げます。
簡単なクラス:
class AskSO
def initialize( filehandle )
@filehandle = filehandle
end
def library_start
@filehandle << '<plist version="1.0">'
end
end
Flexモックを使用した簡単な単体テスト
require 'rubygems'
require 'flexmock/test_unit'
require 'AskSO'
require 'test/unit'
class AskSOTest < Test::Unit::TestCase
def setup
@filehandle = flexmock( "filehandle", "<<" => "" )
end
def test_library_start
@filehandle.should_receive( "<<" ).with( '<plist version="1.0">' ).once
@AskSOInstance = AskSO.new( @filehandle )
@AskSOInstance.library_start
end
end
ruby AskSO-test.rb
一緒に実行すると
1) Failure:
test_library_start(AskSOTest)
[/Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/validators.rb:40:in `validate'
/Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/expectation.rb:123:in `flexmock_verify'
/Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/expectation.rb:122:in `each'
/Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/expectation.rb:122:in `flexmock_verify'
/Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/expectation_director.rb:64:in `flexmock_verify'
/Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/expectation_director.rb:63:in `each'
/Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/expectation_director.rb:63:in `flexmock_verify'
/Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/core.rb:76:in `flexmock_verify'
/Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/core.rb:75:in `each'
/Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/core.rb:75:in `flexmock_verify'
/Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/core.rb:191:in `flexmock_wrap'
/Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/core.rb:74:in `flexmock_verify'
/Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/mock_container.rb:40:in `flexmock_verify'
/Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/mock_container.rb:39:in `each'
/Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/mock_container.rb:39:in `flexmock_verify'
/Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/mock_container.rb:32:in `flexmock_teardown'
/Library/Ruby/Gems/1.8/gems/flexmock-0.9.0/lib/flexmock/test_unit.rb:26:in `teardown']:
in mock 'filehandle': method '<<("<plist version=\"1.0\">")' called incorrect number of times.
<1> expected but was
<0>.
私は何が間違っているのですか?前もって感謝します