0

ここで少し混乱しています。TDD を実行しようとしていますが、問題が発生しました。Rspecは私に次のことを伝えています-

1) Sammiches GET /sammiches display some sammiches
 Failure/Error: visit sammiches_path
 NameError:
   undefined local variable or method `sammiches_path' for #<RSpec::Core::ExampleGroup::Nested_4::Nested_1:0x007fa7afcfed70>
 # ./spec/requests/sammiches_spec.rb:7:in `block (3 levels) in <top (required)>'

2) Sammiches GET /sammiches creates a new sammich
 Failure/Error: visit sammiches_path
 NameError:
   undefined local variable or method `sammiches_path' for #<RSpec::Core::ExampleGroup::Nested_4::Nested_1:0x007fa7ae11e6f0>
 # ./spec/requests/sammiches_spec.rb:12:in `block (3 levels) in <top (required)>'

これは私のspecファイルがどのように見えるかです

require 'spec_helper'

describe "Sammiches" do
describe "GET /sammiches" do
it "display some sammiches" do
    @sammich = Sammich.create :name => 'bacon'
    visit sammiches_path
    page.should have_content 'bacon'
end

it "creates a new sammich" do
    visit sammiches_path
    fill_in 'Sammich', :with => 'lechuga'
    click_button 'add Sammich'

    current_path.should = root_path
    page.should have_content 'lechuga'

    save_and_open_page
end
end
end

私のルートは -

 sammiches_index GET    /sammiches/index(.:format)    sammiches#index
  Sammiches GET    /Sammiches(.:format)          Sammiches#index
            POST   /Sammiches(.:format)          Sammiches#create
 new_Sammich GET    /Sammiches/new(.:format)      Sammiches#new
 edit_Sammich GET    /Sammiches/:id/edit(.:format) Sammiches#edit
    Sammich GET    /Sammiches/:id(.:format)      Sammiches#show
            PUT    /Sammiches/:id(.:format)      Sammiches#update
            DELETE /Sammiches/:id(.:format)      Sammiches#destroy
       root        /                             Sammiches#index

ルート-

Sammiches::Application.routes.draw do
get "Sammiches/index"

resources :sammiches
 root :to => 'Sammiches#index'

新しいエラー-

1) Sammiches GET /sammiches creates a new sammich
 Failure/Error: visit sammiches_path
 ActionView::Template::Error:
   undefined method `sammich' for #<Sammich:0x007fd0007d2f80>
 # ./app/views/sammiches/index.html.erb:4:in `block in _app_views_sammiches_index_html_erb___2703584807867277870_70265660050820'
 # ./app/views/sammiches/index.html.erb:2:in `_app_views_sammiches_index_html_erb___2703584807867277870_70265660050820'
 # ./spec/requests/sammiches_spec.rb:12:in `block (3 levels) in <top (required)>'

2) Sammiches GET /sammiches display some sammiches
 Failure/Error: visit sammiches_path
 ActionView::Template::Error:
   undefined method `sammich' for #<Sammich:0x007fd00006f4f0>
 # ./app/views/sammiches/index.html.erb:4:in `block in _app_views_sammiches_index_html_erb___2703584807867277870_70265660050820'
 # ./app/views/sammiches/index.html.erb:2:in `_app_views_sammiches_index_html_erb___2703584807867277870_70265660050820'
 # ./spec/requests/sammiches_spec.rb:7:in `block (3 levels) in <top (required)>'

私はここで少し途方に暮れています。アドバイスをいただければ幸いです。

ありがとう。

4

1 に答える 1

2

に追加resources :Sammichesしたようですconfig/routes.rb

に変更しresources :sammichesます。慣例に固執すると役立ちます。:)

ルート ファイルは次のようになります。

Sammiches::Application.routes.draw do

resources :sammiches
 root :to => 'sammiches#index'
于 2013-04-28T22:26:37.820 に答える