Skip to content

Instantly share code, notes, and snippets.

@cutalion
Created July 13, 2011 14:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cutalion/1080421 to your computer and use it in GitHub Desktop.
Save cutalion/1080421 to your computer and use it in GitHub Desktop.
action helper for rspec
#
# Put this file into spec/support/ folder.
#
# Helper +action+ allows you to write something like
#
# 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
#
# instead of
#
# 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
def action(&block)
before { self.class.before(&block) unless action_added?(&block) }
end
def action_added?(&block)
self.class.hooks[:before][:each].map(&:to_proc).include? block
end
@iosadchiy
Copy link

зачёт, ага

@zealoushacker
Copy link

👍

@cutalion
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment