1

以下のテストをspec/requests/user_pages_spec.rbに追加しました。

require 'spec_helper'

describe "UserPages" do
  subject { page }
  .
  .
  .
  describe "user should be able to update username" do
    before do
      @user = FactoryGirl.create(:user)
      visit new_user_session_path
      fill_in "Email", with: user.email
      fill_in "Password", with: user.password
      click_button "Sign In"
    end

    specify { @user.username.should_not == "New Name" }

    context "after filling in correct details" do
      before do
        visit edit_user_registration_path
        fill_in "Name", with: "New Name"
        fill_in "Current password", with: @user.password
        click_button "Update"
      end

      specify { @user.reload.username.should == "New Name" }
      it { should have_selector('div.alert.alert-notice', text: "You updated your account successfully." ) }
      it { should have_selector('title', text: "Edit account details" ) }
    end
  end

end

最初の指定はユーザー名「Person」を返しますが、リロード後の2番目の指定も同様です。

1) UserPages user should be able to update username after filling in correct details 
   Failure/Error: specify { @user.reload.username.should == "New Name" }
     expected: "New Name"
          got: "Person" (using ==)
   # ./spec/requests/user_pages_spec.rb:83:in `block (4 levels) in <top (required)>'

行を変更するとテストが失敗し、アプリを手動でチェックして更新が機能します。@user.reloadまた、名前を取得する直前に電話をかけてみました。

何が問題なのですか?このコードを別の場所に配置する必要がありますか?

御時間ありがとうございます。

4

1 に答える 1

2

@user次の行でインスタンスを使用する必要があります。

fill_in "Email", with: user.email
fill_in "Password", with: user.password

したがって、次のようになります。

fill_in "Email", with: @user.email
fill_in "Password", with: @user.password
于 2012-06-03T18:32:18.743 に答える