Last active
July 16, 2019 06:45
-
-
Save yihyang/95dd01c1ba94c93c6c8438525782f837 to your computer and use it in GitHub Desktop.
Writing tests / specs on Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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