【发布时间】:2016-02-19 12:34:13
【问题描述】:
我想检查一个数组是否只包含特定类的对象,比如说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 版本视为限制。
【问题讨论】: