2017-03-01 4 views
0

RSpec을 처음 사용했습니다. Rails 앱에 대한 기본 컨트롤러 테스트를 수행하려고합니다. 나는 PostsController의 "create"액션을 사용할 때, 사용자가 posts 경로로 리다이렉트되는지 확인하고 싶다. 여기에 현재 테스트가 있습니다.RSpec 컨트롤러 테스트 오류

describe "POST #create" do 
    it "returns http success" do 
    post :create, {'post' => { :title => "My first post", :author => 'Jack Seabolt'} } 
    expect(response). to have_http_status(:success) 
    end 

    it "redirects to 'index' template" do 
    post :create , {'post' => {:title => "my first post", :author => 'Jack Seabolt'} } 
    expect(response) redirect_to(posts_path) 
    end 
end 

이 코드는이 오류에 이르게 : 나는 추가 단지 '게시물'을 시도했습니다

/Users/johnseabolt/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1435:in `load':  
/Users/johnseabolt/Desktop/projects/tdd/spec/controllers/posts_controller_spec.rb:49: syntax error, unexpected tIDENTIFIER, expecting keyword_end (SyntaxError) 
    expect(response) redirect_to(posts_path) 
          ^

. 나는 '색인'을 시도했다. 일하지 않았어. 누군가가 올바른 방향으로 나를 가리킬 수 있다면, 나는 그것을 감사 할 것입니다. 감사.

+0

해결책을 찾는 데 모든 행운 t 그의? –

답변

0

당신은 방법 toexpect에 전화를 놓친 :

expect(response).to redirect_to(posts_path) 
0

일반적으로 기대에 대한 공식은 다음과 같은 :에서

expect(something).to eq another_thing 
expect(something).to be another_thing 

또는

expect(something).to_not eq another_thing 
expect(something).to_not be another_thing 

당신의 이 경우 be 또는은 필요하지 않습니다.redirect_to 일치 프로그램의 원인.

expect(response).to redirect_to(posts_path) 

DOCS : redirect_to 정규

문서 : be 매처 (matcher)에 대한 https://www.relishapp.com/rspec/rspec-rails/v/3-5/docs/matchers/redirect-to-matcher

문서 : https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/be-matchers

문서 eq 매처 (matcher)에 대한 : https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/equality-matchers

관련 문제