ruby - Why does my rspec-rails generated spec fail due to a routing exception? -


i generated scaffold rails (4.1.16) , rspec (3.5.1).

it generated test:

describe "get #show"   "assigns requested team @team"     team = team.create! valid_attributes     :show, params: {id: team.to_param}, session: valid_session     expect(assigns(:team)).to eq(team)   end end 

which outputs error:

teamscontroller #show assigns requested team @team  failure/error: :show, params: {id: team.to_param}, session: valid_session   actioncontroller::urlgenerationerror:    no route matches {:action=>"show", :controller=>"teams", :params=>{:id=>"82"}, :session=>{}} 

if remove keys parameters get, i.e.:

get :show, {id: team.to_param}, valid_session 

the test passes fine.

not sure gem defines generator template (rspec-rails?) , why error. appreciated understanding issue. thanks.

the generator (rspec:scaffold, comes rspec-rails) generating tests the syntax required rails 5 (see last section of blog post), not compatible rails 4. think bug in rspec-rails, since rspec-rails 3.5 otherwise compatible rails 4. (i'm using versions myself; haven't used generator.)

rspec-rails changed use rails 5 syntax in rspec-rails 3.5.0.beta4, 1 workaround use rspec , rspec-rails 3.4 — not nice since newer versions have features , fixes useful rails 4 rails 5. workaround manually fix output of generator did.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -