Tag: matcher

是否存在匹配哈希的RSpec2匹配器?

未来读者请注意:认为RSpec不认为您的哈希值相等? 一个可能是OrderedHash,但是从常规RSpec输出你无法分辨。 这是提示这篇文章的问题。 原始问题: 假设我有一个规范,我想测试一个方法生成适当的哈希。 it ‘should generate the Hash correctly’ do expected = {:foo => 1, ‘baz’ => 2} subject.some_method_that_should_generate_the_hash.should == expected end 这通常会失败,因为具有相同键值对的不同哈希可能会以不同的顺序返回它们的对。 结果如下: Failure/Error: subject.some_method_that_should_generate_the_hash.should == expected expected: {:foo => 1, ‘baz’ => 2}, got: {‘baz’ => 2, :foo => 1} 对于数组,使用=〜运算符求解。 但是,这对Hashes不起作用。 现在,我已经诉诸了 it ‘should generate the Hash correctly’ do expected […]