Last Updated: February 25, 2016
·
463
· cutalion

Remove duplicated "before"s from your specs

Take a look at rspec-action gem.

Compare 1 and 2:

1.

describe "GET index" do
  context 'if user signed in' do
    before { sign_in user }
    before { get :index }
    it { should respond_with :success }
  end

  context 'if user signed out' do
    before { get :index }
    it { should redirect_to sign_in_path }
  end
end

2.

describe "GET index" do
  action { get :index }

  context 'if user signed in' do
    before { sign_in user }
    it { should respond_with :success }
  end

  context 'if user signed out' do
    it { should redirect_to sign_in_path }
  end
end