Skip to content

Instantly share code, notes, and snippets.

@MaryKuz
Created March 28, 2019 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaryKuz/b9802f374d8daf82a1a7a7f073192a49 to your computer and use it in GitHub Desktop.
Save MaryKuz/b9802f374d8daf82a1a7a7f073192a49 to your computer and use it in GitHub Desktop.
Write tests
require 'rails_helper'
RSpec.describe Product, type: :model do
describe '.search_by' do
let(:relation) { double }
before { expect(Product).to receive(:all).and_return(relation) }
context do
it { expect { Product.search_by }.to_not raise_error }
end
context do
before { expect(relation).to receive(:where).with('name ILIKE ?', 'abc%') }
it { expect { Product.search_by 'term' => 'abc' }.to_not raise_error }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment