我想检查一个数组只包含特定类的对象,比如说Float
。期望所有的数组元素是同一类
目前工作的示例:
it "tests array_to_test class of elements" do
expect(array_to_test.count).to eq(2)
expect(array_to_test[0]).to be_a(Float)
expect(array_to_test[1]).to be_a(Float)
end
有没有办法来验证如果array_to_test
只包含Float
实例?
样品不工作的伪代码:
it "tests array_to_test class of elements" do
expect(array_to_test).to be_a(Array[Float])
end
不考虑Ruby和Rspec的版本作为限制。
是的,这就是它!看来我在文档中找不到它... 感谢您的快速回复! –