mardi 4 décembre 2018

Rspec request spec examine response body

Since rspec 3.5 request specs are used to test controller behaviour plus route testing and the correct rendering of the view with the content. The last part troubles me a bit since i do not understand the thin line of what goes in the view specs to what stays in the request specs.

On relishapp i found this piece:

expect(response.body).to include("Widget was successfully created.")

which tempted me of including the following in my request test:

describe "Index page" do
  ....
  it 'includes a link to cars_parts' do
    get "/car_overview"      
    expect(response.body).to include("car_parts_path")
  end
  ....
end 

This test fails. In the view i use the link_to on the car_parts url_helper. The failing test dumps the whole response.body String and i see the car_parts_path but rspec does not see it. How do i have to change my test to make it pass without the use of capybara since it is only useable with feature specs now. And am i doing it correct after all or should this kind of test go somewhere else?

Aucun commentaire:

Enregistrer un commentaire