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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#!/usr/bin/env rspec
require_relative "spec_helper"
require "dbus"
describe "PropertyTest" do
before(:each) do
session_bus = DBus::ASessionBus.new
@svc = session_bus.service("org.ruby.service")
@obj = @svc.object("/org/ruby/MyInstance")
@iface = @obj["org.ruby.SampleInterface"]
end
it "tests property reading" do
expect(@iface["ReadMe"]).to eq("READ ME")
end
it "tests property reading on a V1 object" do
obj = @svc["/org/ruby/MyInstance"]
iface = obj["org.ruby.SampleInterface"]
expect(iface["ReadMe"]).to eq("READ ME")
end
it "tests property nonreading" do
expect { @iface["WriteMe"] }.to raise_error(DBus::Error, /not readable/)
end
it "tests property writing" do
@iface["ReadOrWriteMe"] = "VALUE"
expect(@iface["ReadOrWriteMe"]).to eq("VALUE")
end
# https://github.com/mvidner/ruby-dbus/pull/19
it "tests service select timeout" do
@iface["ReadOrWriteMe"] = "VALUE"
expect(@iface["ReadOrWriteMe"]).to eq("VALUE")
# wait for the service to become idle
sleep 6
# fail: "Property value changed; perhaps the service died and got restarted"
expect(@iface["ReadOrWriteMe"]).to eq("VALUE")
end
it "tests property nonwriting" do
expect { @iface["ReadMe"] = "WROTE" }.to raise_error(DBus::Error, /not writable/)
end
it "tests get all" do
all = @iface.all_properties
expect(all.keys.sort).to eq(["ReadMe", "ReadOrWriteMe"])
end
it "tests get all on a V1 object" do
obj = @svc["/org/ruby/MyInstance"]
iface = obj["org.ruby.SampleInterface"]
all = iface.all_properties
expect(all.keys.sort).to eq(["ReadMe", "ReadOrWriteMe"])
end
it "tests unknown property reading" do
expect { @iface["Spoon"] }.to raise_error(DBus::Error, /not found/)
end
it "tests unknown property writing" do
expect { @iface["Spoon"] = "FPRK" }.to raise_error(DBus::Error, /not found/)
end
end
|