如何在页面顶部包含javascript_include_tag的javascript以进行水豚测试

时间:2016-04-17 23:39:10

标签: ruby-on-rails capybara rspec-rails

我正在尝试使用capybara在spec测试中测试一个javascript类。 我有静态页面player.haml,我在其中使用javascript_include_tag加载javascript类定义。它看起来像那样

  .container
    = javascript_include_tag "../player"
    #player

我的测试看起来像那样

  it 'can autoplay a video' do
    visit player_path
    video = Fabricate(:video)
    options = { autoplay: true, ... }
    page.execute_script("var options = '#{options}';
    videoId = '#{video.id}'; var player = new Player(videoId, options);")
    expect(page).to have_content(video.title)
  end

问题是javascript_include_tag包含页面底部的脚本和execute_script调用之后的脚本。 我在访问页面后尝试了睡眠,但结果是一样的。 如何在使用execute_script之前加载类定义? 最终的瓶颈是具有播放器定义的文件是.coffee.erb。我可以更改,因为它使用了应用程序中的一些设置。

0 个答案:

没有答案
相关问题