So I am having trouble passing these specs in a ruby on rails application:
require 'rails/all'
RSpec.describe WikisController, type: :controller do
let(:user) { User.create!(email: "[email protected]", password: "password") }
let(:wiki) { Wiki.create!(title: "New Wiki Title", body: "New Wiki Body", private: false, user: user) }
describe "GET show" do
it "returns http success" do
get :show
expect(response).to have_http_status(:success)
end
end
describe "GET edit" do
it "returns http success" do
get :edit
expect(response).to have_http_status(:success)
end
end
end
when I run these specs, i get these errors:
Failures:
1) WikisController GET show returns http success
Failure/Error: get :show
ActionController::UrlGenerationError:
No route matches {:action=>"show", :controller=>"wikis"}
# ./spec/controllers/wikis_controller_spec.rb:16:in `block (3 levels) in <top (required)>'
2) WikisController GET edit returns http success
Failure/Error: get :edit
ActionController::UrlGenerationError:
No route matches {:action=>"edit", :controller=>"wikis"}
# ./spec/controllers/wikis_controller_spec.rb:23:in `block (3 levels) in <top (required)>'
the reason i am confused is because they work fine in the browser. Also, when i run rake routes, i get this:
root GET / wikis#index
wikis GET /wikis(.:format) wikis#index
POST /wikis(.:format) wikis#create
new_wiki GET /wikis/new(.:format) wikis#new
edit_wiki GET /wikis/:id/edit(.:format) wikis#edit
wiki GET /wikis/:id(.:format) wikis#show
PATCH /wikis/:id(.:format) wikis#update
PUT /wikis/:id(.:format) wikis#update
DELETE /wikis/:id(.:format) wikis#destroy
So, these errors don't make sense to me because clearly i do have those routes with those controllers. Can someone provide me some insight as to what's going on here?
Your rspec includes show, edit
actions which require id
as your results from rake routes
.
Try get :show, id: 1