I have been trying to test my index route using RSpec.
I have this code but the error doesn't make sense because I have this route I tried it on the browser and curl, I'm still getting a response.
require 'rails_helper'
RSpec.describe Spree::Admin::OfficeAddressesController, type: :controller do
describe "GET index" do
it "render view index template" do
get :index, params: {use_route: 'spree/admin/office_addresses'}
# expect(response).to render_template('index')
expect(response).to eq(200)
end
end
end
error msg:
Failures:
1) Spree::Admin::OfficeAddressesController GET index render view index template
Failure/Error: get :index, params: {use_route: 'spree/admin/office_addresses'}
ActionController::UrlGenerationError:
No route matches {:action=>"index", :controller=>"spree/admin/office_addresses", :params=>{:use_route=>"spree/admin/office_addresses"}}
# ./spec/controllers/office_addresses_controller_spec.rb:8:in `block (3 levels) in <top (required)>'
Finished in 18.54 seconds (files took 7.55 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/controllers/office_addresses_controller_spec.rb:7 # Spree::Admin::OfficeAddressesController GET index render view index template
I have tried this SO answers still no luck
I tried it with curl I get a 200
ok response.
here are my routes
bin/rake routes | grep office_addresses
admin_office_addresses GET
/admin/office_addresses(.:format)
spree/admin/office_addresses#index
rails -v
Rails 4.2.6
ruby -v
ruby 2.3.6
Curl Response:
curl --verbose localhost:3000/spree/admin/office_addresses | grep HTTP
* TCP_NODELAY set
* Connected to localhost (::1) port 3000 (#0)
> GET /spree/admin/office_addresses HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.61.0
> Accept: */*
< HTTP/1.1 200 OK
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< Content-Type: text/html; charset=utf-8
< Cache-Control: max-age=0, private, must-revalidate
< X-Runtime: 1.124812
< Vary: Origin
< X-Rack-CORS: miss; no-origin
< Content-Length: 29482
This is my first time to use Rspec btw and the documentation is nevermind...
Aucun commentaire:
Enregistrer un commentaire