2013-04-28 2 views
0

여기 약간 혼란 스럽습니다. 나는 TDD를하려고 노력 중이며 문제를 겪고있다. RSpec에 나에게 말하고 다음과 같은 -Rspec-nameError : 정의되지 않은 로컬 변수 또는 메서드`sammiches_path '

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)>' 

내 경로가

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 

Routes-

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)>' 

나는 약간의 손실이 있습니다. 모든 조언을 크게 주시면 감사하겠습니다.

감사합니다.

+0

, 당신은 Sammich''에 대한 총액 불일치가있을 수 있습니다; routes.rb 파일의 내용은 무엇입니까? – rossta

+0

내 경로 파일을 추가했습니다. 리소스 대소 문자를 변경했지만 지금은 새로운 오류가 발생합니다 ... 감사합니다! – DynastySS

+0

새로운 오류는 app/views/sammiches/index.html.erb의 4 행에 있습니다. 정의되지 않은 변수/메소드'sammich'를 사용하려고합니다. – rossta

답변

2

resources :Sammichesconfig/routes.rb에 추가 한 것 같습니다.

resources :sammiches으로 변경하십시오. 컨벤션에 고착하면 도움이됩니다. :)

귀하의 경로 파일과 같아야합니다 언뜻

Sammiches::Application.routes.draw do 

resources :sammiches 
root :to => 'sammiches#index' 
+0

좋은 눈! 감사! 나는 그것을 고정했지만 지금은 ... Sammiches GET/sammiches가 일부 sammiches를 표시합니다. Failure/Error : 방문 sammiches_path ActionView :: Template :: Error : # 에 대한 정의되지 않은 메소드'sammich ' – DynastySS

+0

몇 가지 세부 사항을 추가했습니다. 위의 내 게시물에. 이것은 당신의 route.rb가 어떻게 보일 것인가입니다. – kiddorails

+0

나와 함께 고마워. 나는 새로운 오류를 얻고 있습니다. 그래서 그것은 진전이라고 생각합니다! 원래 게시물의 맨 아래에 추가했습니다. 다시 한번 감사드립니다. – DynastySS

관련 문제