Chapter 3 : Model specs - Testing class methods and scopes
File - spec/models/contact_spec.rb
Test case :
Context - context "matching letters" do
it "returns a sorted array of results that match" do
expect(Contact.by_letter("J")).to eq [@johnson, @jones]
end
end
Contact.by_letter("J") returns Active record relation object and not an array.
Hence we have to change Contact.by_letter("J") to Contact.by_letter("J") .pluck(:lastname) in the test case or change the model code.
Chapter 3 : Model specs - Testing class methods and scopes
File - spec/models/contact_spec.rb
Test case : Context - context "matching letters" do it "returns a sorted array of results that match" do expect(Contact.by_letter("J")).to eq [@johnson, @jones] end end
Contact.by_letter("J") returns Active record relation object and not an array. Hence we have to change Contact.by_letter("J") to Contact.by_letter("J") .pluck(:lastname) in the test case or change the model code.