Hi, I''ve got a lot of rspec controller tests. At the beginning of each controller, I have: def authenticate ... end def logout ... end Authenticates creates me a @current_user, logout destroys the @current_user. As I said, this code is at the beginning of each controller, not very DRY :-) Any hints for me, where to put this code and how to integrate it in my tests, to not always rewrite this two methods? Regards sewid -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> I''ve got a lot of rspec controller tests. At the beginning of each controller, I have: > > def authenticate > ... > end > > def logout > ... > end > > Authenticates creates me a @current_user, logout destroys the @current_user. As I said, this code is at the beginning of each controller, not very DRY :-) > > Any hints for me, where to put this code and how to integrate it in my tests, to not always rewrite this two methods?You could create a file in spec/support/current_user.rb (or whatever, doesn''t matter as long as it''s in spec/support/*.rb) and put them in there. Then they''ll be available to all your specs... -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
You can include helper modules in your spec_helper file:
RSpec.configure do |config|
config.include MySpec::SessionsHelper, :type => :controller,
:example_group => {
:file_path => config.escaped_path(%w[spec controllers])
}
end
This will include the MySpec::SessionsHelper in all of your controller
tests automatically. Then you just have to define your module in the
spec/support folder (which should be loaded by RSpec automatically if
you''re using the RSpec generated spec_helper file.)
# spec/support/sessions_helper.rb
module MySpec
module SessionsHelper
def authenticate ...
def logout ...
end
end
S. Widmann wrote in post #981233:> Hi,
>
> I''ve got a lot of rspec controller tests. At the beginning of each
> controller, I have:
>
> def authenticate
> ...
> end
>
> def logout
> ...
> end
>
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
I will try that, thanks! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.