我如何單元測試如下:單元測試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