【发布时间】:2018-07-28 09:44:53
【问题描述】:
我在使用 minitest 测试与此类似的方法时遇到问题,其中对象引用了其他对象:
def drive num
old_place = @current_place.name
if num == 0
road = @current_place.first_place_road
@current_place = @current_place.first_place
else
road = @current_place.second_place_road
@current_place = @current_place.second_place
end
print_drive(old_place, road)
end
我正在尝试通过创建 2 个模拟对象进行测试,并将它们的方法存根以返回另一个模拟对象。
def test_drive_to_first_place
start_place = Minitest::Mock.new
end_place = Minitest::Mock.new
def start_place.name; "first place"; end
def start_place.first_place; end_place; end
def start_place.first_place_road; "road"; end
def end_place.name; "end place"; end
def end_place.first_place; nil; end
def start_place.first_place_road; nil; end
driver = Driver::new "driver", start_place
driver.drive(0)
assert_output(stdout = ......
end
我收到此错误,我不知道如何处理它。正在测试的对象没有任何属性或方法:end_place,它只是用作测试中的名称。
1) Error:
DriverTest#test_drive_to_first_place:
NoMethodError: unmocked method :end_place, expected one of []
【问题讨论】:
标签: ruby oop reference minitest