1

コンテキスト: Cucumber/Capybara/PhantomJS/Poltergeist で Rails アプリをテストしています。キュウリのステップ定義ファイルの 1 つに click_link 呼び出しがあります。この click_link 呼び出しにより、Rails はコントローラーの show メソッドを呼び出します。コントローラーは特定の ID でオブジェクトを見つけ、javascript 形式 (format.js) で応答します。show.js.erb ファイルによって提供される応答は、Twitter Bootstrap モーダル ダイアログ ボックスでテキスト文字列置換を実行して、ボックスにカスタム ステータス メッセージを表示します。モーダル ダイアログ ボックスが表示されます。

これはすべて本番環境で機能します。しかし、テストでは機能しないようです。「値、ID、テキスト '閉じる' のボタンが見つかりません (Capybara::ElementNotFound)」というエラー メッセージが表示されます。また、page.html を配置すると、次のように表示されます。

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">

モーダルダイアログボックスがまったく表示されていないと思います。誰が何が起こっているかについて何か考えがありますか?

cucumber_steps.rb

When /^I click this link$/ do

  click_link "Some link to call show method"

  puts page.html

end

And /^I click close button in the modal box$/ do

   click_button 'Close'

end

Twitter Bootstrap のモーダル ボックスのページ内の HTML:

<ul>
  <li><a href="/kites/24" data-remote="true">Some link to call show method</a></li>
</ul>
 :
 :
    <form>

<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

  <div class="modal-header">

    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>

    <h3 id="myModalLabel">Modal header</h3>

  </div>

  <div class="modal-body">

    <p>One fine body…&lt;/p>

  </div>

  <div class="modal-footer">

    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>

    <button class="btn btn-primary">Save changes</button>

  </div>

</div>

</form>

Rails show メソッド

def show

    @kite = Kite.find(params[:id])

    respond_to do |format|

      format.js

    end

  end
4

1 に答える 1

2

閉じるボタン エラー

click_button "Close"を使用していて、クリック ボタンが ID またはテキストに「閉じる」を使用していない ため、エラーが発生しています。<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>

エラーを回避するには、次のようにします。

close_button = page.find('button.close')
click_button close_button

一般的な問題

実装に関する多くの詳細を省略しているため、どこが間違っているかを特定するのは困難です。最初に確認することは、ファイルにポルターガイストが設定されていることを確認することですenv.rb

于 2013-02-16T23:26:28.900 に答える