我尝试使用Minitest模拟来验证对需要关键字参数的方法的调用;但是我得到了这个错误:
ArgumentError: wrong number of arguments (given 4, expected 2..3)
这是我的完整测试:
test ".toggle updates the category" do
mock = Minitest::Mock.new
mock.expect :update!, nil, [], {collapsed: true}
CategoryAnalyzer.toggle_category(mock, true)
mock.verify
end
这是受试方法:
def self.toggle_category(category, collapsed)
category.update!(collapsed: collapsed)
end
我从minitest - mock - expect keyword arguments看到Minitest应该接受关键字参数。我的测试设置是否错误?我是否有一个旧版本的Minitest?(我的Gemfile.lock
列出了minitest (5.18.0)
)我还应该检查什么?
1条答案
按热度按时间3vpjnl9f1#
下面是使用4个参数调用
expect
的方法:这就是它所期望的:
因为 ruby v3.0
{collapsed: true}
是位置参数。要将其转换为关键字,您必须使用**
splat或删除括号:一个简单的演示: