File: multi_vm_test.rb

package info (click to toggle)
ruby-pluggaloid 1.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 236 kB
  • sloc: ruby: 1,601; sh: 4; makefile: 2
file content (52 lines) | stat: -rw-r--r-- 1,888 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-

require 'minitest/autorun'

require 'pluggaloid'
require_relative 'helper'

describe(Pluggaloid) do
  include PluggaloidTestHelper

  before do
    Delayer.default = Delayer.generate_class(priority: %i<high normal low>, default: :normal)
    Pluggaloid::Plugin.clear!
  end

  it "should take new plugin classes" do
    pluggaloid = Pluggaloid.new(Delayer.default)
    assert_equal Delayer.default, pluggaloid.Delayer, ""
    assert_includes(pluggaloid.Plugin.ancestors, Pluggaloid::Plugin, "Plugin should subbclass of Pluggaloid::Plugin")
    assert_includes(pluggaloid.Event.ancestors, Pluggaloid::Event, "Event should subbclass of Pluggaloid::Event")
    assert_includes(pluggaloid.Listener.ancestors, Pluggaloid::Listener, "Listener should subbclass of Pluggaloid::Listener")
    assert_includes(pluggaloid.Filter.ancestors, Pluggaloid::Filter, "Filter should subbclass of Pluggaloid::Filter")
  end

  it "call event in new vm" do
    vm_a = Pluggaloid.new(Delayer.generate_class(priority: %i<high normal low>, default: :normal))
    vm_b = Pluggaloid.new(Delayer.generate_class(priority: %i<high normal low>, default: :normal))
    foo = bar = false
    vm_a.Plugin.create(:foo_plugin) do
      on_foo do
        foo = true end end
    vm_b.Plugin.create(:bar_plugin) do
      on_bar do
        bar = true end end

    assert_equal(%i<foo_plugin>, vm_a.Plugin.instances_name)
    assert_equal(%i<bar_plugin>, vm_b.Plugin.instances_name)

    eval_all_events(vm_a.Delayer) do
      vm_a.Plugin.call(:foo)
      vm_a.Plugin.call(:bar) end
    assert foo, "Event foo should be called"
    refute bar, "Event bar should not be called"

    foo = bar = false
    eval_all_events(vm_b.Delayer) do
      vm_b.Plugin.call(:foo)
      vm_b.Plugin.call(:bar) end
    refute foo, "Event foo should not be called"
    assert bar, "Event bar should be called"
  end
end