I need to create some methods that are available both to my application (models, views and controllers) and to RSpec.
Specifically I need to create some path_helper
the Rspec-rails gem seems to support helper testing
the gem can make helpers available in any of your specs : "Writing specs for your helpers is a snap. Just tell the Example Group the name of the helper and the Example Group will expose an object that includes the helper".
Haven't tried it, but this looks like an interesting approach to the problem: Adding rspec test for library module doesn't seem to pickup Expectations and Matchers
A model we often use when testing Modules is to include the module in either a class created for the test (inside the spec file) or included inside the spec itself.
You can make RSpec include a module by (in spec/spec_helper.rb):
RSpec.configure do |config|
config.include YourModule
end
If you want to use routing path helpers, you can include them like this:
RSpec.configure do |config|
config.include Rails.application.routes.url_helpers
end