UJS Rails的在我的網頁我有:測試與水豚,硒和RSpec
- >是擦傷另一個網站與UJS提出了Ajax請求內容的形式(遠程:真):
<%= simple_form_for @listing, :url => listings_fetch_url, remote: true do |f| %>
<%= f.input :url %>
<%= f.button :submit, id: 'import_button' %>
<% end %>
- >由從形式刮結果填入上述
手動將其作品的另一種形式......
然而W¯¯母雞我試圖自動測試它,它不。 水豚發現提交按鈕,點擊它,但然後它留在空白頁。
下面是測試代碼:有以下幾種
feature "Listing import" do
scenario "fills in the form fields", js: true do
visit new_search_path
fill_in 'Url', :with => 'www.google.fr'
find('input#import_button').click
expect(page.body).to have_content 'query was'
end
end
的控制器操作:
def fetch
url = listing_params[:url]
@query = Query.new(ScraperService.new({url: url}).perform)
render :fill
end
# Renders an js.erb file
def fill
end
好像硒無法呈現js.erb rspec的文件?
任何幫助表示讚賞!
EDIT由於@ThomasWalpole,我固定一個錯誤500,其是防止機械化刮網絡。內容現在被正確地刮取,但問題仍然存在:點擊提交按鈕後的頁面變爲空白,測試結束。 在日誌中我有一個漫長的消息:
Could not log "render_template.action_view" event. NoMethodError: undefined method
example_group' for nil:NilClass ["/Users/Greg/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rspec-rails-3.6.0/lib/rspec/rails/view_rendering.rb:67:in
current_example_group'"
水豚用硒絕對可以渲染的js。 erb文件。看看你的測試。日誌文件並查看正在做什麼請求,請求什麼格式以及響應代碼是什麼。是否有任何'Query.new(ScraperService.new({url:url})。perform'嚮應用程序發出另一個請求,在不同的線程中運行等等?如果是,你使用:puma作爲你的Capybara服務器(Capybara.server =:puma)? –
感謝提示@ThomasWalpole!日誌顯示500個服務器錯誤,這是由'require'webmock/rspec''導致的,它阻止了機械化訪問web。 'Query.new ...'沒有嚮應用程序發出另一個請求,也沒有在單獨的線程中運行。使用Puma並沒有改變任何可悲的事情。 請參閱我的更新問題。 – Greg
嘗試降級到rspec 3.5.x。 - 可能是一個錯誤在3.6 –