Created
July 13, 2011 14:40
-
-
Save cutalion/1080421 to your computer and use it in GitHub Desktop.
action helper for rspec
This file contains hidden or 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
# | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍