Advertisement
Guest User

Untitled

a guest
Aug 13th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.09 KB | None | 0 0
  1. describe "product search by price and name" 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.         search_hash = { keyword: "Fiat" }
  10.         expect(Product.search(search_hash)).to be_empty
  11.       end
  12.     end
  13.  
  14.     context "when price '10'" do
  15.       it "returns an empty array" do
  16.         search_hash = { price: 10 }
  17.         expect(Product.search(search_hash)).to be_empty
  18.       end
  19.     end
  20.  
  21.     context "when name 'Acura'" do
  22.       it "returns the product1" do
  23.         search_hash = { keyword: "Acura" }
  24.         expect(Product.search(search_hash)).to match_array([@product1])
  25.       end
  26.     end
  27.  
  28.     context "when price '150'" do
  29.       it "returns the product3" do
  30.         search_hash = { price: 150 }
  31.         expect(Product.search(search_hash)).to match_array([@product3])
  32.       end
  33.     end
  34.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement