Created
March 28, 2019 08:58
-
-
Save MaryKuz/b8e1d85e12029d6bafaa6b7a6d3d73b9 to your computer and use it in GitHub Desktop.
Write tests for actions
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
RSpec.describe Api::ProductsController, type: :controller do | |
... | |
describe '#index.json' do | |
before { get :index, format: :json } | |
it { should render_template :index } | |
end | |
describe '#show.json' do | |
before { get :show, id: 1, format: :json } | |
it { should render_template :show } | |
end | |
describe '#collection' do | |
before { expect(Product).to receive(:all) } | |
it { expect { subject.send :collection }.to_not raise_error } | |
end | |
describe '#resource' do | |
before { expect(subject).to receive(:params).and_return({ id: 1 }) } | |
before { expect(Product).to receive(:find).with(1) } | |
it { expect { subject.send :resource }.to_not raise_error } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment