A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://rspec.info/features/7-1/rspec-rails/matchers/relation-match-array below:

ActiveRecord::Relation match array

The match_array matcher can be used with an ActiveRecord::Relation (scope). The assertion will pass if the scope would return all of the elements specified in the array on the right hand side.

An example spec with relation match_array matcher

Given a file named “spec/models/widget_spec.rb” with:

require "rails_helper"

RSpec.describe Widget do
  let!(:widgets) { Array.new(3) { Widget.create } }

  subject { Widget.all }

  it "returns all widgets in any order" do
    expect(subject).to match_array(widgets)
  end
end

When I run rspec spec/models/widget_spec.rb

Then the examples should all pass.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4