Top Level Namespace

Defined Under Namespace

Modules: Jackal

Instance Method Summary collapse

Instance Method Details

#callback_executed?(payload) ⇒ Boolean

Returns callback execution status.

Parameters:

  • payload (Smash)

    payload result from callback execution

Returns:

  • (Boolean)

    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

Parameters:

  • style (String, Symbol)

    name of payload

  • args (Hash) (defaults to: {})

Options Hash (args):

  • :raw (TrueClass, FalseClass)

    return loaded payload only

  • :nest (String, Symbol)

    place loaded payload within key namespace in hash

Returns:

  • (Hash)

    new payload



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.expand_path(path) : 'no path discovered'}"
  end
end

#run_setup(config) ⇒ Thread

Configure using custom configuration JSON within config directory of current test

Parameters:

  • config (String, Symbol)

    name of configuration file

Returns:

  • (Thread)

    thread with running source



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 |message|
    message.args['message']['executed'] = true
    execute_orig(message)
  end
end

#transmit_and_wait(actor, payload, wait_time = 1) ⇒ Smash

Returns payload result.

Parameters:

  • actor (Carnivore::Source::Actor)

    actor to receive payload

  • payload (Smash)

    payload to send actor

  • wait_time (Numeric) (defaults to: 1)

    max time to wait for message result (default 1)

Returns:

  • (Smash)

    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.messages.empty? }
  actor.callbacks.each do |c_name|
    callback = actor.callback_supervisor[actor.callback_name(c_name)]
    if(callback.respond_to?(:test_payload=))
      unless(MessageStore.messages.empty?)
        MessageStore.messages.first.deep_merge!(callback.test_payload)
      end
      callback.test_payload = nil
    end
  end
  MessageStore.messages.pop
end