Skip to content

Instantly share code, notes, and snippets.

@MaryKuz

MaryKuz/Write Tests

Created Mar 28, 2019
Embed
What would you like to do?
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