Class: Capybara::Node::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/dmc_kanye/imma_let_you_finish.rb

Instance Method Summary collapse

Instance Method Details

#synchronize(seconds = nil, options = {}) ⇒ Object

new code:



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/dmc_kanye/imma_let_you_finish.rb', line 54

def synchronize(seconds = nil, options = {})
  kanye_in_the_house = session.driver.respond_to?(:kanye_invited?) && session.driver.kanye_invited?
  if seconds
    seconds_to_wait = seconds
  elsif kanye_in_the_house
    seconds_to_wait = DmcKanye::Config.default_wait_time || Capybara.default_max_wait_time
  else
    seconds_to_wait = Capybara.default_max_wait_time
  end
##### STOP PUNCHING DUCKS, BACK TO ORIGINAL CODE
  start_time = Capybara::Helpers.monotonic_time

  if session.synchronized
    yield
  else
    session.synchronized = true
    begin
##### START PUNCHING DUCKS
# orig code:
#            yield
# new code:
      session.driver.send(:imma_let_you_finish) if kanye_in_the_house
      result = yield
      session.driver.send(:imma_let_you_finish) if kanye_in_the_house
      result
##### STOP PUNCHING DUCKS, BACK TO ORIGINAL CODE
    rescue => e
      session.raise_server_error!
      raise e unless driver.wait?
      raise e unless catch_error?(e, options[:errors])
##### START PUNCHING DUCKS
# orig code:
#            raise e if (Capybara::Helpers.monotonic_time - start_time) >= seconds
# new code:
      raise e if (Capybara::Helpers.monotonic_time - start_time) >= seconds_to_wait
##### STOP PUNCHING DUCKS, BACK TO ORIGINAL CODE
      sleep(0.05)
      raise Capybara::FrozenInTime, "time appears to be frozen, Capybara does not work with libraries which freeze time, consider using time travelling instead" if Capybara::Helpers.monotonic_time == start_time
      reload if Capybara.automatic_reload
      retry
    ensure
      session.synchronized = false
    end
  end
end