Ruby、Rails、および TDD の初心者。Capybara と Capybara Webkit で RSpec を使用しています。
ページに div 要素が存在するかどうかをテストしようとしています。
テストコード:
require 'spec_helper'
describe "Login module" do
before do
visit root_path
end
it "should have a module container with id mLogin" do
page.should have_css('div#mLogin')
end
it "should have a module container with id mLogin", :js => true do
page.evaluate_script('$("div#mLogin").attr("id")').should eq "mLogin"
end
end
最初のテストはパスしますが、2 番目のテストは次のように失敗します。
Login module should have a module container with id mLogin
Failure/Error: page.evaluate_script('$("div#mLogin").attr("id")').should eq "mLogin"
expected: "mLogin"
got: nil
ブラウザー開発ツールで JS を実行し、nil ではなく "mLogin" を取得します。
何か案は?ありがとう。