在rspec上使用render_views方法时,路线问题

时间:2019-01-06 00:11:45

标签: ruby-on-rails rspec routing tdd rendering

我开始学习Ruby on Rails上的TDD,遇到了我无法解决的问题,当我使用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

这是spec / 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 :(得分:0)

迭代缺少PicassoTargetableTextView.load(left, top, right, bottom)

end