I'm developing a Rails Engine using rails v5.1.0
and rspec-rails 3.5.2
.
I have a simple feature spec:
require "rails_helper"
module MyEngineName
RSpec.feature "Some Feature", type: :feature do
it "user can navigate to page and blah blah", :js do
visit edit_job_path(1)
# .... other stuff
end
end
end
This raises the error
undefined method `edit_job_path' for #<RSpec::ExampleGroups::SomeFeature:0x007fc098a570e8>
because the route helper edit_job_path
can not be found.
Is there something special I need to do in order to allow my feature specs to access my engine routes?
The RSpec documentation mentions that you can specify the engine routes, but that only appears to be for routing specs. When I added it to the feature specs, it fails with undefined method 'routes'
Thanks!
EDIT: Since my routes file was requested, adding it here. It's pretty short -
# config/routes.rb
MyEngineName::Engine.routes.draw do
root to: redirect("/my_engine_name/jobs")
resources :jobs
end
List of all routes from rake
> rake app:routes
....
....
Routes for MyEngineName::Engine:
root GET / redirect(301, /my_engine_name/jobs)
jobs GET /jobs(.:format) my_engine_name/jobs#index
POST /jobs(.:format) my_engine_name/jobs#create
new_job GET /jobs/new(.:format) my_engine_name/jobs#new
edit_job GET /jobs/:id/edit(.:format) my_engine_name/jobs#edit
job GET /jobs/:id(.:format) my_engine_name/jobs#show
PATCH /jobs/:id(.:format) my_engine_name/jobs#update
PUT /jobs/:id(.:format) my_engine_name/jobs#update
DELETE /jobs/:id(.:format) my_engine_name/jobs#destroy
For API request specs, I tried both ways but it doesn't work
routes { MyEngine::Engine.routes }
and
RSpec.configure do |config|
config.before :each, type: :request do
helper.class.include MyEngine::Engine.routes.url_helpers
end
end
If the above solutions doesn't work, try loading helper urls as rspec configs as below:
RSpec.configure do |config|
config.include MyEngine::Engine.routes.url_helpers
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With