ActiveRecord::Relation 匹配数组
match_array
匹配器可与 ActiveRecord::Relation
(作用域) 一起使用。如果作用域返回右侧数组中指定的所有元素,则断言将通过。
具有关系 match_array 匹配器的示例规范
给定一个名为“spec/models/widget_spec.rb”的文件,其中包含
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
当我运行 rspec spec/models/widget_spec.rb
那么示例应该全部通过。