It seems that what you are testing is a transformation. I would like to write something like this:
it "transforming something does something" do base_data = { k1: 1, k2: 2 } transformed_data = base_data.each_with_object({}) { |(k, v), t| t[k] = f(v) } expect(transformed_data).to eq( k1: 2, k2: 4, ) end
For me, the description clearly states what we expect. Then from the test you can easily understand what the input and the expected result are. In addition, it uses a hash tag that will provide a good spread of the two hashes on failure:
expected: {:k1=>2, :k2=>4} got: {:k1=>1, :k2=>4} (compared using ==) Diff: @@ -1,3 +1,3 @@ -:k1 => 2, +:k1 => 1, :k2 => 4,
Although I would question the meaning of the relationship of key importance. Are these just test cases you are trying to execute? If so, I will just do each unique test. If there is anything more to this, then I can ask the question why the conversion method does not provide a hash to start with.
Aaron k
source share