2017-01-04 5 views
0

私はRSpec機能テストで私のレールアプリをテストしようとしています。私はリッチテキストのためにQuilljsを使用しており、単に投稿を作成する能力をテストしたいと思っています。Quilljsとcapybara-webkitによるCapybaraテスト

# erb view 
<div id="post-form-container"> 
    <%= form_for :post, url: posts_path, html: {id: 'post-form'} do |f| %> 
    <div class="form-group"> 
     <%= f.hidden_field :discussion_id, value: discussion.id %> 
     <%= f.hidden_field :content, class: 'form-control', id: 'post-content-input' %> 
     <div id="editor-container"></div> 
    <%= f.button 'Post', class: 'btn btn-primary', id: 'post-button' %> 
     </div> 
    <% end %> 
</div> 

# spec 
scenario 'can post in discussion', :js do 
    login_as user 
    visit community_group_path(community_group) 
    within('form#post-form') do 
    find('div[contenteditable="true"].ql-editor').send_keys 'This is a new post.' 
    click_on 'Post' 
    end 
    expect(page).to have_content 'This is a new post.' 
end 

This questionは、上記をしようとする私を導いそれでも:jsタグでこのシナリオを実行するときクイルはのcontentEditableのdivを作成しているようにそれはいないようです。

Capybara::ElementNotFound: 
    Unable to find css "div[contenteditable]" 

更新: 私は以下のようなクイルのための外部URLを許可する必要が実現するために来ているが、それはまだ働いていません。

Capybara::Webkit.configure do |config| 
    config.allow_url("https://cdn.quilljs.com/*") 
end 

アップデート2:私は自分のアプリケーションJSローディング非同期を持っていたし、それが問題を引き起こしていました。それを変えることがトリックでした!

<%= javascript_include_tag 'application', 'data-turbolinks-track' => true, async: Rails.env.production? %> 

答えて

0

2つのことは、私の問題を修正:

は、負荷アプリケーションJSに

# spec/support/capybara.rb 
Capybara::Webkit.configure do |config| 
    config.allow_url("https://cdn.quilljs.com/*") 
end 

外部クイルのURLを許可する同期テスト

<%# app/views/layouts/application.html.erb %> 
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true, async: Rails.env.production? %> 
中に
関連する問題