1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Disable jruby lazy results evaluation again

This commit is contained in:
Thomas Walpole 2017-02-16 12:31:33 -08:00
parent 2c357e35ce
commit 047098ad3f
2 changed files with 9 additions and 9 deletions

View file

@ -28,11 +28,6 @@ module Capybara
@result_cache = [] @result_cache = []
@results_enum = lazy_select_elements { |node| query.matches_filters?(node) } @results_enum = lazy_select_elements { |node| query.matches_filters?(node) }
@query = query @query = query
# JRuby < 9.1.6.0 has an issue with eagerly finding next in lazy enumerators which
# causes a concurrency issue with network requests here
# https://github.com/jruby/jruby/issues/4212
# Just force all the results to be evaluated
full_results if RUBY_PLATFORM == 'java' && (Gem::Version.new(JRUBY_VERSION) < Gem::Version.new('9.1.6.0'))
end end
def_delegators :full_results, :size, :length, :last, :values_at, :inspect, :sample def_delegators :full_results, :size, :length, :last, :values_at, :inspect, :sample
@ -138,7 +133,12 @@ module Capybara
end end
def lazy_select_elements(&block) def lazy_select_elements(&block)
if @elements.respond_to? :lazy #Ruby 2.0+ # JRuby has an issue with lazy enumerators which
# causes a concurrency issue with network requests here
# https://github.com/jruby/jruby/issues/4212
if RUBY_PLATFORM == 'java'
@elements.select(&block).to_enum # non-lazy evaluation
elsif @elements.respond_to? :lazy #Ruby 2.0+
@elements.lazy.select(&block) @elements.lazy.select(&block)
else else
Enumerator.new do |yielder| Enumerator.new do |yielder|

View file

@ -73,7 +73,7 @@ RSpec.describe Capybara::Result do
#Not a great test but it indirectly tests what is needed #Not a great test but it indirectly tests what is needed
it "should evaluate filters lazily" do it "should evaluate filters lazily" do
skip 'JRuby has an issue with lazy enumerator next evaluation' if RUBY_PLATFORM == 'java' && (Gem::Version.new(JRUBY_VERSION) < Gem::Version.new('9.1.6.0')) skip 'JRuby has an issue with lazy enumerator evaluation' if RUBY_PLATFORM == 'java'
#Not processed until accessed #Not processed until accessed
expect(result.instance_variable_get('@result_cache').size).to be 0 expect(result.instance_variable_get('@result_cache').size).to be 0
@ -95,7 +95,7 @@ RSpec.describe Capybara::Result do
context '#each' do context '#each' do
it 'lazily evaluates' do it 'lazily evaluates' do
skip 'JRuby has an issue with lazy enumerator next evaluation' if RUBY_PLATFORM == 'java' && (Gem::Version.new(JRUBY_VERSION) < Gem::Version.new('9.1.6.0')) skip 'JRuby has an issue with lazy enumerator evaluation' if RUBY_PLATFORM == 'java'
results=[] results=[]
result.each do |el| result.each do |el|
results << el results << el
@ -111,7 +111,7 @@ RSpec.describe Capybara::Result do
end end
it 'lazily evaluates' do it 'lazily evaluates' do
skip 'JRuby has an issue with lazy enumerator next evaluation' if RUBY_PLATFORM == 'java' && (Gem::Version.new(JRUBY_VERSION) < Gem::Version.new('9.1.6.0')) skip 'JRuby has an issue with lazy enumerator evaluation' if RUBY_PLATFORM == 'java'
result.each.with_index do |el, idx| result.each.with_index do |el, idx|
expect(result.instance_variable_get('@result_cache').size).to eq(idx+1) # 0 indexing expect(result.instance_variable_get('@result_cache').size).to eq(idx+1) # 0 indexing
end end