Top Level Namespace
Defined Under Namespace
Modules: Jackal
Instance Method Summary collapse
-
#callback_executed?(payload) ⇒ Boolean
Callback execution status.
-
#payload_for(style, args = {}) ⇒ Hash
Fetch test payload and create new payload.
-
#run_setup(config) ⇒ Thread
Configure using custom configuration JSON within config directory of current test.
- #track_execution(klass) ⇒ Object
-
#transmit_and_wait(actor, payload, wait_time = 1) ⇒ Smash
Payload result.
Instance Method Details
#callback_executed?(payload) ⇒ Boolean
Returns callback execution status.
90 91 92 |
# File 'lib/jackal/utils/spec/helpers.rb', line 90 def callback_executed?(payload) payload.get(:executed) == true end |
#payload_for(style, args = {}) ⇒ Hash
Note:
‘style` is name of test payload without .json extension. Will
Fetch test payload and create new payload
search ‘test/specs/payload’ from CWD first, then fallback to ‘payloads’ directory within the directory of this file
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/jackal/utils/spec/helpers.rb', line 29 def payload_for(style, args={}) file = "#{style}.json" path = [File.join(Dir.pwd, 'test/specs/payloads'), Jackal::Utils::Spec.payload_storage].flatten.compact.map do |dir| if(File.exists?(full_path = File.join(dir, file))) full_path end end.compact.first if(path) if(args[:raw]) MultiJson.load(File.read(path)) else if(args[:nest]) Jackal::Utils.new_payload(:test, args[:nest] => MultiJson.load(File.read(path))) else Jackal::Utils.new_payload(:test, MultiJson.load(File.read(path))) end end else raise "Requested payload path for test does not exist: #{path ? File.(path) : 'no path discovered'}" end end |
#run_setup(config) ⇒ Thread
Configure using custom configuration JSON within config directory of current test
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/jackal/utils/spec/helpers.rb', line 56 def run_setup(config) config_dir = File.join(Dir.pwd, 'test', 'specs', 'config') path = Dir.glob(File.join(config_dir, "#{config}*")).first msg = "No file matching #{config} found in #{config_dir}" raise msg unless path Thread.abort_on_exception = true runner = Thread.new do Jackal::Utils::Spec.system_runner.run!(:config => path) end source_wait(:setup) runner end |
#track_execution(klass) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/jackal/utils/spec/helpers.rb', line 74 def track_execution(klass) alias_name = :execute_orig # Ensure this is called only once within test suite return if klass.method_defined?(alias_name) klass.send(:alias_method, alias_name, :execute) klass.send(:define_method, :execute) do || .args['message']['executed'] = true execute_orig() end end |
#transmit_and_wait(actor, payload, wait_time = 1) ⇒ Smash
Returns payload result.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/jackal/utils/spec/helpers.rb', line 100 def transmit_and_wait(actor, payload, wait_time = 1) actor.callbacks.each do |c_name| callback = actor.callback_supervisor[actor.callback_name(c_name)] if(callback.respond_to?(:test_payload=)) callback.test_payload = Smash.new end end actor.transmit(payload) source_wait(wait_time) { !MessageStore..empty? } actor.callbacks.each do |c_name| callback = actor.callback_supervisor[actor.callback_name(c_name)] if(callback.respond_to?(:test_payload=)) unless(MessageStore..empty?) MessageStore..first.deep_merge!(callback.test_payload) end callback.test_payload = nil end end MessageStore..pop end |