Skip to content

Instantly share code, notes, and snippets.

@yihyang
Last active July 16, 2019 06:45
Show Gist options
  • Select an option

  • Save yihyang/95dd01c1ba94c93c6c8438525782f837 to your computer and use it in GitHub Desktop.

Select an option

Save yihyang/95dd01c1ba94c93c6c8438525782f837 to your computer and use it in GitHub Desktop.
Writing tests / specs on Ruby
require 'rails_helper'
describe CarModelAPIService do
shared_examples_for 'fetch method' do
it { is_expected.to eq(result) }
end
describe '#fetch' do
subject { CarModelAPIService.new(params).fetch }
context 'when params is xxx' do
let(:params) { { year_made: '2000', price_min: 10_000, price_max: 100_000 } }
let(:result) { [{ make: 'Honda', model: 'Accord'}] }
it_behaves_like 'fetch method'
end
context 'when params is yyy' do
let(:params) { { year_made: '2009', price_min: 30_000, price_max: 50_000 } }
let(:result) { [{ make: 'Honda', model: 'Civic'}] }
it_behaves_like 'fetch method'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment