Skip to content

Commit

Permalink
Change how app errors are raised so cause gets set as wanted in JRuby
Browse files Browse the repository at this point in the history
JRuby has an issue with lazy enumerator evaluation - disable Capybara::Result optimization when using JRuby
  See: jruby/jruby#4212
  • Loading branch information
twalpole committed Oct 8, 2016
1 parent 73aa8ce commit ff51c95
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/capybara/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def initialize(elements, query)
@result_cache = []
@results_enum = lazy_select_elements { |node| query.matches_filters?(node) }
@query = query
# JRuby 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'
end

def_delegators :full_results, :size, :length, :last, :values_at, :inspect, :sample
Expand Down
2 changes: 2 additions & 0 deletions lib/capybara/selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,15 @@
end
options.sort == actual.sort
end

filter(:with_options) do |node, options|
finder_settings = { minimum: 0 }
if !node.visible?
finder_settings[:visible] = false
end
options.all? { |option| node.first(:option, option, finder_settings) }
end

filter(:selected) do |node, selected|
actual = node.all(:xpath, './/option', visible: false).select { |option| option.selected? }.map { |option| option.text(:all) }
[selected].flatten.sort == actual.sort
Expand Down
2 changes: 2 additions & 0 deletions lib/capybara/selenium/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require "uri"

class Capybara::Selenium::Driver < Capybara::Driver::Base

DEFAULT_OPTIONS = {
:browser => :firefox
}
Expand Down Expand Up @@ -40,6 +41,7 @@ def initialize(app, options={})
end
end


@app = app
@browser = nil
@exit_status = nil
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def raise_server_error!
begin
raise CapybaraError, "Your application server raised an error - It has been raised in your test code because Capybara.raise_server_errors == true"
rescue CapybaraError
raise @server.error
raise @server.error.class, @server.error.message, @server.error.backtrace
end
end
ensure
Expand Down
1 change: 1 addition & 0 deletions spec/result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@

#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'
#Not processed until accessed
expect(result.instance_variable_get('@result_cache').size).to be 0

Expand Down

0 comments on commit ff51c95

Please sign in to comment.