RSpec / RSpec Rails / Docs / Matchers
ActiveRecord::Relation match array
The =~ 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.
Scenario: example spec with relation =~ matcher
- Given a file named "
spec/models/widget_spec.rb" with:rubyrequire "spec_helper" describe Widget do let!(:widgets) { Array.new(3) { Widget.create } } subject { Widget.scoped } it { should =~ widgets } end - When I run `rspec spec/models/widget_spec.rb`
- Then the examples should all pass
Source: features/matchers/relation_match_array.feature at v2.7.0, RSpec Rails (MIT license).