How to test with Rspec that a key exists inside a hash that contains an array of hashes

RSpec allows you to use the have_key predicate matcher to validate the presence of a key via has_key?, like so:

subject { described_class.order_items_by_revenue }

it "includes revenue key" do
  expect(subject.first).to have_key(:revenue)
end

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)