Ruby:如何使用assert_nothing_raised?
assert_nothing_raised do
@board.make_move(0,0,Board::HUMAN)
end
文档说:
Passes if block does not throw anything.
Example:
assert_nothing_thrown do
[1, 2].uniq
end
我的 make_move 方法:
def make_move(x, y, player)
return false
end
我收到错误:
test_can_make_valid_move_in_the_first_row(BoardTest):
ArgumentError: wrong number of arguments (1 for 2)
assert_nothing_raised do
@board.make_move(0,0,Board::HUMAN)
end
and the docs say:
Passes if block does not throw anything.
Example:
assert_nothing_thrown do
[1, 2].uniq
end
my make_move method:
def make_move(x, y, player)
return false
end
I get the error:
test_can_make_valid_move_in_the_first_row(BoardTest):
ArgumentError: wrong number of arguments (1 for 2)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下面的代码对我有用。它对你有用吗?
我认为您正确使用了assert_nothing_raised。尝试
用更简单的东西替换,看看
是否有效。还可以尝试注释掉测试中的所有其他代码。
This following code works for me. Does it work for you?
I think you are using assert_nothing_raised correctly. Try replacing
with something more simple, like
and see if that works. Also try commenting out all the other code in your test.
可以说,您永远不应该使用
assert_nothing_raised
,因为它实际上不会测试任何内容。请参阅:http://blog.zenspider.com/blog/2012/01/ assert_nothing_tested.html
我在这里发布了一些进一步的想法:
为什么 MiniTest::Spec 没有 wont_raise 断言?
It can be argued that you should never use
assert_nothing_raised
, as it does not actually test anything. See:http://blog.zenspider.com/blog/2012/01/assert_nothing_tested.html
I've posted some further thoughts here:
Why doesn't MiniTest::Spec have a wont_raise assertion?