File: async_spec.rb

package info (click to toggle)
ruby-dbus 0.16.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 520 kB
  • sloc: ruby: 3,786; sh: 53; makefile: 8
file content (45 lines) | stat: -rwxr-xr-x 1,045 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env rspec
# Test the binding of dbus concepts to ruby concepts
require_relative "spec_helper"
require "dbus"

describe "AsyncTest" do
  before(:each) do
    @bus = DBus::ASessionBus.new
    @svc = @bus.service("org.ruby.service")
    @obj = @svc.object "/org/ruby/MyInstance"
    @obj.default_iface = "org.ruby.SampleInterface"
  end

  # https://github.com/mvidner/ruby-dbus/issues/13
  it "tests async_call_to_default_interface" do
    loop = DBus::Main.new
    loop << @bus

    immediate_answer = @obj.the_answer do |_msg, retval|
      expect(retval).to eq(42)
      loop.quit
    end

    expect(immediate_answer).to be_nil

    # wait for the async reply
    loop.run
  end

  it "tests async_call_to_explicit_interface" do
    loop = DBus::Main.new
    loop << @bus

    ifc = @obj["org.ruby.AnotherInterface"]
    immediate_answer = ifc.Reverse("abcd") do |_msg, retval|
      expect(retval).to eq("dcba")
      loop.quit
    end

    expect(immediate_answer).to be_nil

    # wait for the async reply
    loop.run
  end
end