rspec2 - Rspec parameters to shared context -


i want test if user logged in, in each of controller actions.

what's best practice dry out can repeat actions, i.e. get,show, new, edit.

it require passing in :index, :new, etc. , passing in parameter show , edit.

here's non-dry version 1 action:

rspec.shared_context 'when user not logged in'   before     sign_out :user    end    'get#index redirects sign in page'          :index              expect(response).to redirect_to new_user_session_path   end 

i want each of controller actions without having copy/paste code.

i hope clear! in advance!

i'm not sure exactly, think should work:

rspec.shared_examples 'when user not logged in' |actions|   before { sign_out :user }    actions.each |action|     "get##{action} redirects sign in page"          action       expect(response).to redirect_to new_user_session_path     end   end end  it_should_behave_like 'when user not logged in', %i(new index) 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -