Skip to content

Instantly share code, notes, and snippets.

@MaryKuz
Created March 28, 2019 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaryKuz/b8e1d85e12029d6bafaa6b7a6d3d73b9 to your computer and use it in GitHub Desktop.
Save MaryKuz/b8e1d85e12029d6bafaa6b7a6d3d73b9 to your computer and use it in GitHub Desktop.
Write tests for actions
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