Tag: unit testing模拟

unit testingRuby块通过模拟与rr(是flexmock)

我如何对以下单元进行unit testing: 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’ ?