0

現在のパスをテストして、オンになっていることを確認しようとしていpost_path(post)ます。テストに合格するはずです。しかし、私は得てgot: #<Capybara::Session> (using ==)います。私はこれが何であるかを本当に理解していません。

これはテストコードです

require 'spec_helper'

describe PostsController do
  subject { page }

  let(:first_user_is_admin) { FactoryGirl.create(:user) }

  describe "Not signed in user cannot see any kind of edit view for a post:" do

    describe "Post is anonymous without user_id" do
      let(:post) {FactoryGirl.create(:anonymous_post)}
      before do
        visit edit_post_path(post)
      end
      it { should == post_path(post) }
    end

  end
end

これがテスト結果です。

1) PostsController Not signed in user cannot see any kind of edit view for a post: Post is anonymous without user_id 
   Failure/Error: it { should == post_path(post) }
     expected: "/posts/1"
          got: #<Capybara::Session> (using ==)
     Diff:
     @@ -1,2 +1,2 @@
     -"/posts/1"
     +#<Capybara::Session>
4

1 に答える 1

2

このセクションのページに対してテストを実行しています

subject { page }

このセクションでテストしている変数を具体的に参照する必要があります

it { should == post_path(post) }

すなわち

it { variable.should == post_path(post) }

現在のテストが行​​っていることはこれです

it { page.should == post_path(post) }

そのため、テストするオブジェクトを明示的に指定する必要があります。Capybara は以下をサポートしています (使用しているバージョンによって異なります)。

it { current_path.should == post_past(post) }

または代わりに

  it { current_url.should == post_past(post) }
于 2013-03-19T05:13:24.570 に答える