Advertisement
Guest User

Untitled

a guest
Aug 13th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.88 KB | None | 0 0
  1. describe ".search" do
  2.     before(:each) do
  3.       @product1 = Product.create(name: "Acura", price: 100, category_id: 1)
  4.       @product2 = Product.create(name: "BMV", price: 50, category_id: 2)
  5.       @product3 = Product.create(name: "Ferrari", price: 150, category_id: 3)
  6.     end
  7.     context "when name 'Fiat'" do
  8.       it "returns an empty array" do
  9.         expect(Product.search('Fiat')).to be_empty
  10.       end
  11.     end
  12.  
  13.     context "when price '10'" do
  14.       it "returns an empty array" do
  15.         expect(Product.search(10)).to be_empty
  16.       end
  17.     end
  18.  
  19.     context "when name 'Acura'" do
  20.       it "returns the product1" do
  21.         expect(Product.search('Acura')).to match_array([@product1])
  22.       end
  23.     end
  24.  
  25.     context "when price '150'" do
  26.       it "returns the product3" do
  27.         expect(Product.search(150)).to match_array([@product3])
  28.       end
  29.     end
  30.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement