Ошибка маршрута при использовании метода render_views в rspec - PullRequest
0 голосов
/ 06 января 2019

Я начинаю изучать TDD в Ruby on Rails, и у меня возникают эти проблемы, которые я не могу решить, я получаю эту проблему маршрутизации, когда использую метод render_views, чтобы проверить, есть ли данные в представлении. (Он работает без проблем с методом render_views)

Failures:

  1) CachorrosController GET index ter a variável de classe @cachorros
 Failure/Error: get :index

 SyntaxError:
   /vagrant/Aulas - Torne-se um programador/app_gem/app/views/cachorros/index.html.erb:7: syntax error, unexpected keyword_ensure, expecting keyword_end
   /vagrant/Aulas - Torne-se um programador/app_gem/app/views/cachorros/index.html.erb:9: syntax error, unexpected end-of-input, expecting keyword_end
 # /home/vagrant/.rvm/gems/ruby-2.3.7/gems/rails-controller-testing-1.0.4/lib/rails/controller/testing/template_assertions.rb:61:in `process'
 # /home/vagrant/.rvm/gems/ruby-2.3.7/gems/rails-controller-testing-1.0.4/lib/rails/controller/testing/integration.rb:13:in `block (2 levels) in <module:Integration>'
 # ./spec/controllers/cachorros_controller_spec.rb:10:in `block (3 levels) in <top (required)>'

  2) CachorrosController GET index esta rota precisa renderizar o template index
 Failure/Error: get :index

 SyntaxError:
   /vagrant/Aulas - Torne-se um programador/app_gem/app/views/cachorros/index.html.erb:7: syntax error, unexpected keyword_ensure, expecting keyword_end
   /vagrant/Aulas - Torne-se um programador/app_gem/app/views/cachorros/index.html.erb:9: syntax error, unexpected end-of-input, expecting keyword_end
 # /home/vagrant/.rvm/gems/ruby-2.3.7/gems/rails-controller-testing-1.0.4/lib/rails/controller/testing/template_assertions.rb:61:in `process'
 # /home/vagrant/.rvm/gems/ruby-2.3.7/gems/rails-controller-testing-1.0.4/lib/rails/controller/testing/integration.rb:13:in `block (2 levels) in <module:Integration>'
 # ./spec/controllers/cachorros_controller_spec.rb:16:in `block (3 levels) in <top (required)>'

  3) CachorrosController GET index verifica se o código foi inserido na página
 Failure/Error: get :index

 SyntaxError:
   /vagrant/Aulas - Torne-se um programador/app_gem/app/views/cachorros/index.html.erb:7: syntax error, unexpected keyword_ensure, expecting keyword_end
   /vagrant/Aulas - Torne-se um programador/app_gem/app/views/cachorros/index.html.erb:9: syntax error, unexpected end-of-input, expecting keyword_end
 # /home/vagrant/.rvm/gems/ruby-2.3.7/gems/rails-controller-testing-1.0.4/lib/rails/controller/testing/template_assertions.rb:61:in `process'
 # /home/vagrant/.rvm/gems/ruby-2.3.7/gems/rails-controller-testing-1.0.4/lib/rails/controller/testing/integration.rb:13:in `block (2 levels) in <module:Integration>'
 # ./spec/controllers/cachorros_controller_spec.rb:23:in `block (3 levels) in <top (required)>'

Finished in 0.28037 seconds (files took 5.17 seconds to load)
10 examples, 3 failures

Failed examples:

rspec ./spec/controllers/cachorros_controller_spec.rb:7 # CachorrosController GET index ter a variável de classe @cachorros
rspec ./spec/controllers/cachorros_controller_spec.rb:15 # CachorrosController GET index esta rota precisa renderizar o template index
rspec ./spec/controllers/cachorros_controller_spec.rb:20 # CachorrosController GET index verifica se o código foi inserido na página

Это спецификация / controllers / cachorros_controller_spec.rb:

require 'rails_helper'

RSpec.describe CachorrosController, type: :controller do
  describe "GET index" do
    render_views

    it "ter a variável de classe @cachorros" do
      Cachorro.destroy_all
      cachorro = Cachorro.create(nome: "Boomer", raca: "Beagle")
      get :index
      expect(assigns(:cachorros)).to eq([cachorro])
      expect(response.status).to eq(200)
    end

    it "esta rota precisa renderizar o template index" do
      get :index
      expect(response).to render_template("index")
    end

    it "verifica se o código foi inserido na página" do
      Cachorro.destroy_all
      cachorro = Cachorro.create(nome: "Boomer", raca: "Beagle")
      get :index
      expect(response.body).to match /<ul>.?*<li>/im
    end
  end
end

Это views / cachorros / index.html.erb:

<ul>
  <% @cachorros.each do |cachorro| %>
  <li> <%= @cachorro.nome %></li>
</ul>

1 Ответ

0 голосов
/ 09 января 2019

Отсутствует end для итерации

<ul>
  <% @cachorros.each do |cachorro| %>
    <li> <%= @cachorro.nome %></li>
  <% end %>
</ul>
...