Hey guys,

just wrote a helper for controller specs in the rails. Link to the gist -
https://gist.github.com/1080421 - to view with syntax highlight.

# 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 logged 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 logged 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

What do you think?


- Alex
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to