2013-05-22 3 views
0

Rails 3.2 애플리케이션을 테스트 범위로 개발 중이지만 어떤 이유로 내 테스트가 실패하고 있습니다. 동일한 사양이 다른 모델에도 적용됩니다.Stange Rspec 테스트가 실패했습니다.

사양은 Rspec, FactoryGirl, Shoulda-Matchers와 함께 실행됩니다.

Failures: 

    1) PlacesController POST create when user is logged in with valid params redirects to the created place 
    Failure/Error: response.should redirect_to(Place.last) 
     Expected response to be a <:redirect>, but was <200> 
    # ./spec/controllers/places_controller_spec.rb:109:in `block (5 levels) in <top (required)>' 

    2) PlacesController POST create when user is logged in with valid params assigns a newly created place as @place 
    Failure/Error: assigns(:place).should be_persisted 
     expected persisted? to return true, got false 
    # ./spec/controllers/places_controller_spec.rb:104:in `block (5 levels) in <top (required)>' 

    3) PlacesController POST create when user is logged in with valid params creates a new Place 
    Failure/Error: expect { 
     count should have been changed by 1, but was changed by 0 
    # ./spec/controllers/places_controller_spec.rb:96:in `block (5 levels) in <top (required)>' 

Finished in 4.63 seconds 
21 examples, 3 failures 

Failed examples: 

rspec ./spec/controllers/places_controller_spec.rb:107 # PlacesController POST create when user is logged in with valid params redirects to the created place 
rspec ./spec/controllers/places_controller_spec.rb:101 # PlacesController POST create when user is logged in with valid params assigns a newly created place as @place 
rspec ./spec/controllers/places_controller_spec.rb:95 # PlacesController POST create when user is logged in with valid params creates a new Place 

꽤 같은 사양이 다른 파일, http://pastebin.com/r8HtAwSR에 존재하고 정확하게 문제없이 통과됩니다 http://pastebin.com/8VWCAv79

오류는 다음과 같습니다

은 실패 사양입니다.

컨트롤러 파일입니다

사람이 어떻게이 문제를 해결하는 날을 제안 할 수 있습니까?

답변

0

글쎄, 그것은 새로운 장소가 어떤 이유로 든 생성되지 않은 것처럼 보입니다. (제 추측에 따르면, 검증을 통과하지 못합니다).

테스트 디버그를 시도하십시오. 나는 pry을 사용합니다. 그냥 gem 'pry' gemfile에 추가하고 번들을 실행 한 다음 실행시 중단 점을 설정할 수 있습니다.

it "redirects to the created place" do 
    post :create, {:place => valid_attributes} 
    binding.pry 
    response.should redirect_to(Place.last) 
end 

실행하면 'binding.pry'를 삽입 지점에서 정지하고 당신은 당신의 터미널의 마지막 장소입니다 확인할 수 있습니다 :

예를 들어이 시도.

+0

불행히도이 문제를 해결하는 데 도움이되지 않았습니다 ... 이상한 점은 모델이 컨트롤러에서 사용되는 것과 동일한 팩토리를 사용하여 실행되는 모든 유효성 검사 테스트를 통과하므로 속성이 동일하다는 것입니다. – endorama

+0

@ endorama 단지 'binding.pry'퍼팅은 문제를 해결하지 않을 것입니다. 요점은 일단 당신이 binding.pry 거기에 무슨 일이 일어나고 있는지, 당신은 개체의 'cd'수, 방법의 소스를 보여줄 수있는 프로그램을 찾아 볼 수있는 코드를 실행하는 등 당신은 모든 액세스 권한이 있습니다. 그 시점에서 전체 프로그램의 상태에 도달하면 문제의 근원을 찾을 수있는 위치가 훨씬 더 좋습니다. – horseyguy

+0

@endorama 문제를 해결할 수있는 방법이 아닙니다. 무엇이 잘못되었는지 찾아내는 데 도움이 될 것입니다. 'binding pry'를 테스트에두고 테스트 스위트를 실행하고 바인드를 삽입 한 지점에서 실행이 중지되고 터미널에 (서버가 실행중인 위치로) 변경된 다음 'Place.last'를 시도하십시오. 그것은 당신이 기대 한 것입니까? valid_attributes를 확인하지 않으면. 그들은 정말로 유효한가? 'place = Place.new (valid_attributes);와 같은 것을하면 무엇이 반환 될까요? place.valid ?; '. false 인 경우 유효성 검사 오류 'place.errors'를 확인하십시오. 문제가 다른 곳에있는 경우 ... –