[Rails] Re: DRY in rspec tests
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home