Class: Scarpe::TestPromise

Inherits:
Promise
  • Object
show all
Defined in:
lib/scarpe/wv/control_interface_test.rb

Overview

A Promise but with helper functions for Webview testing.

Instance Method Summary collapse

Constructor Details

#initialize(iface:, state: nil, wait_for: [], &scheduler) ⇒ TestPromise

Returns a new instance of TestPromise.



208
209
210
211
# File 'lib/scarpe/wv/control_interface_test.rb', line 208

def initialize(iface:, state: nil, wait_for: [], &scheduler)
  @iface = iface
  super(state: state, parents: wait_for, &scheduler)
end

Instance Method Details

#inspectObject



213
214
215
# File 'lib/scarpe/wv/control_interface_test.rb', line 213

def inspect
  "<#TestPromise::#{object_id} state=#{state.inspect} parents=#{parents.inspect} value=#{returned_value.inspect} reason=#{reason.inspect}>"
end

#then_ruby_promise(wait_for: [], &block) ⇒ Object

This method expects to wait for the parent TestPromise and then run a block of Ruby that returns another promise. This is useful for wrapping Promises like those from replace() that don't have the test DSL built in. The block will execute when this outer promise is scheduled -- so we don't do a replace() too early, for instance. And then the outer promise will fulfill when the inner one does.



221
222
223
224
225
226
227
228
# File 'lib/scarpe/wv/control_interface_test.rb', line 221

def then_ruby_promise(wait_for: [], &block)
  ruby_wrapper_promise = TestPromise.new iface: @iface, wait_for: ([self] + wait_for)

  ruby_wrapper_promise.on_scheduled do
    inner_ruby_promise = block.call
    inner_ruby_promise.on_fulfilled { ruby_wrapper_promise.fulfilled!(inner_ruby_promise.returned_value) }
  end
end

#then_with_js_dom_html(wait_for: [], timeout: DEFAULT_ASSERTION_TIMEOUT, &block) ⇒ Object



234
235
236
# File 'lib/scarpe/wv/control_interface_test.rb', line 234

def then_with_js_dom_html(wait_for: [], timeout: DEFAULT_ASSERTION_TIMEOUT, &block)
  @iface.with_js_dom_html(wait_for: (wait_for + [self]), timeout:, &block)
end

#then_with_js_value(js_code, wait_for: [], timeout: DEFAULT_ASSERTION_TIMEOUT, &block) ⇒ Object



230
231
232
# File 'lib/scarpe/wv/control_interface_test.rb', line 230

def then_with_js_value(js_code, wait_for: [], timeout: DEFAULT_ASSERTION_TIMEOUT, &block)
  @iface.with_js_value(js_code, wait_for: (wait_for + [self]), timeout:, &block)
end