我如何单元测试如下:单元测试Ruby块与RR惩戒(是flexmock)
def update_config
store = YAML::Store.new('config.yaml')
store.transaction do
store['A'] = 'a'
end
end
这里是我的开始:
def test_yaml_store
mock_store = flexmock('store')
mock_store
.should_receive(:transaction)
.once
flexmock(YAML::Store).should_receive(:new).returns(mock_store)
update_config()
end
如何测试里面是什么的块?
修订
我已经将我的测试规范,切换到让rr嘲讽框架:
describe 'update_config' do
it 'calls transaction' do
stub(YAML::Store).new do |store|
mock(store).transaction
end
update_config
end
end
这将考验该交易被调用。我如何测试块内:store['A'] = 'a'
?
谢谢。这个问题最初是如何测试Flexmock中的块内部的。我改变了rr,因为没有人回答了几个月。 – zhon 2013-10-07 20:26:24