Last active
March 9, 2017 14:23
-
-
Save kriskhaira/5c2b4d99aff6921d9e528fc7e3810ad0 to your computer and use it in GitHub Desktop.
testing scopes in RSpec
This file contains 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
# PATTERN 1: describe > let + before + specify > expect | |
describe 'scopes' do | |
let(:offers) { create_list(:offer, 3, :available, :published, :shown) } | |
before do | |
offers.first.update(is_published: false) | |
offers.second.update(is_shown: false) | |
end | |
specify '.shown returns correct number of offers' do | |
expect(Offer.shown).not_to be_empty | |
end | |
specify '.usable returns correct number of offers' do | |
expect(Offer.usable).not_to be_empty | |
end | |
end | |
# PATTERN 2: describe > let + before + describe > subject + it > expect | |
describe 'scopes' do | |
let(:offers) { create_list(:offer, 3, :available, :published, :shown) } | |
before do | |
offers.first.update(is_published: false) | |
offers.second.update(is_shown: false) | |
end | |
describe '.shown' do | |
subject { Offer.shown } | |
it { expect(subject).not_to be_empty } | |
end | |
describe '.usable' do | |
subject { Offer.usable } | |
it { expect(subject).not_to be_empty } | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment