0

コードを分析してきましたが、答えが見つかりません。

次の仕様を実行するとエラーが発生します。

describe 'with valid information' do
  before {
    fill_in 'Name', with: 'Example User'
    fill_in 'Email', with: 'user@example.com'
    fill_in 'Password', with: 'foobar'
    fill_in 'Confirmation', with: 'foobar'
  }

  it 'should create a user' do
    expect {click_button submit}.to change(User, :count).by(1)
  end

  describe "after saving the user" do
    before {click_button submit}
    let(:user) {User.find_by_email('user@example.com')}

    it {should have_selector('title', text:user.name)}
    it {should have_selector('div.alert.alert-success', text: "Welcome")}
  end

end

エラーは「ユーザーを保存した後」の部分にあり、セレクターdiv.alert.alert-successをチェックしています。

Failure/Error: it {should have_selector('div.alert.alert-success', text: "Welcome")}
   expected css "div.alert.alert-success" with text "Welcome" to return something

私の users_controller は、キーの成功を含むフラッシュ ハッシュを送信します。

flash[:succes] = "Welcome"
redirect_to @user

成功したサインアップでも、ページに class="alert alert-success" を含むタグ div が送信されます。

<div class="alert alert-succes">
  Welcome
</div>

何が起こっているのかを確認できるように、テストでclick_button 送信をレンダリングしているものを知る方法はありますか? 結果のHTMLをコンソールで確認する方法

注:テストをshould have_selector('div.alert', text: "Welcome" ( alert-successクラスなし)のみ) に変更すると、合格することは言うまでもありません。

前もって感謝します

4

1 に答える 1