0

我在rails中有点大一新生,所以请多多包涵。我的测试出现路由错误。测试如下:

require 'spec_helper'

describe "ProducerPages" do

  subject { page }

  describe "profile page" do
    @producer = Producer.create(name:"Example Producer", 
                             email: "producer@example.com", password: "foobar",
                             password_confirmation: "foobar")
    before { visit producer_path(@producer) }

    it { should have_selector('h1',    text: producer.name) }
    it { should have_selector('title', text: producer.name) }
  end
end

产生的故障是:

Failures:

  1) ProducerPages profile page
     Failure/Error: before { visit producer_path(@producer) }
     ActionController::RoutingError:
       No route matches {:action=>"show", :controller=>"producers", :id=>nil}
     # ./spec/requests/producer_pages_spec.rb:14:in `block (3 levels) in <top (required)>'

看起来,我在创建生产者实例变量时做错了。我试图将其设为正常变量,但随后出现此错误:

  1) ProducerPages profile page
     Failure/Error: before { visit producer_path(producer) }
     ActionController::RoutingError:
       No route matches {:action=>"show", :controller=>"producers", 
     :id=>#<Producer id: nil, name: "Example Producer", 
     email: "producer@example.com", created_at: nil, updated_at: nil, 
     password_digest: "$2a$04$pXAEklj4nzYe48ojR5Ps/Oh8Ea9.QqKOajYBD2Rv0mQ9...", 
     remember_token: nil, admin: false, oid: nil, contact_name: nil, 
     street: nil, postal_code: nil, city: nil, country: nil, url: nil, 
     telephone: nil, cellular: nil, type: "Producer", producer_id: nil, 
     client_key: nil, product_count: 0>}
     # ./spec/requests/producer_pages_spec.rb:14:in `block (3 levels) in <top (required)>'

routes.rb 文件包含

  resources :producers

我究竟做错了什么?

4

0 回答 0