diff --git a/lib/capybara/result.rb b/lib/capybara/result.rb index 4f94cccb..5d17fc28 100644 --- a/lib/capybara/result.rb +++ b/lib/capybara/result.rb @@ -28,11 +28,6 @@ module Capybara @result_cache = [] @results_enum = lazy_select_elements { |node| query.matches_filters?(node) } @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 def_delegators :full_results, :size, :length, :last, :values_at, :inspect, :sample @@ -138,7 +133,12 @@ module Capybara end 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) else Enumerator.new do |yielder| diff --git a/spec/result_spec.rb b/spec/result_spec.rb index 02cc9f28..8c2fc3e4 100644 --- a/spec/result_spec.rb +++ b/spec/result_spec.rb @@ -73,7 +73,7 @@ RSpec.describe Capybara::Result do #Not a great test but it indirectly tests what is needed 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 expect(result.instance_variable_get('@result_cache').size).to be 0 @@ -95,7 +95,7 @@ RSpec.describe Capybara::Result do context '#each' 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=[] result.each do |el| results << el @@ -111,7 +111,7 @@ RSpec.describe Capybara::Result do end 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| expect(result.instance_variable_get('@result_cache').size).to eq(idx+1) # 0 indexing end