2017-03-01 2 views
0

RSpecの新機能です。私はRailsアプリケーションの基本的なコントローラテストをしようとしています。 PostsControllerの「作成」アクションを使用すると、ユーザーは投稿パスにリダイレクトされることを確認したいと思います。ここに私の現在のテストがあります。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

あなたはexpect方法toを呼び出すために見逃している:

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正規表現エンジンの

ドキュメント:eqマッチャためhttps://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/be-matchers

ドキュメント:beマッチャため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/equality-matchers