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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
require "notiffany/notifier/libnotify"
module Notiffany
RSpec.describe Notifier::Libnotify do
let(:options) { {} }
let(:os) { "solaris" }
subject { described_class.new(options) }
before do
stub_const "Libnotify", double
allow(Kernel).to receive(:require)
allow(RbConfig::CONFIG).to receive(:[]).with("host_os") { os }
end
describe "#initialize" do
let(:os) { "mswin" }
context "with unsupported host" do
it "does not require libnotify" do
expect(Kernel).to_not receive(:require)
expect { subject }.to raise_error(Notifier::Base::UnsupportedPlatform)
end
end
context "host is supported" do
let(:os) { "linux" }
it "requires libnotify" do
expect(Kernel).to receive(:require).and_return(true)
subject
end
end
end
describe "#notify" do
context "with options passed at initialization" do
let(:options) { { title: "Hello", silent: true } }
it "uses these options by default" do
expect(::Libnotify).to receive(:show).with(
hash_including(
transient: false,
append: true,
timeout: 3,
urgency: :low,
summary: "Hello",
body: "Welcome to Guard",
icon_path: "/tmp/welcome.png"
)
)
subject.notify("Welcome to Guard", image: "/tmp/welcome.png")
end
it "overwrites object options with passed options" do
expect(::Libnotify).to receive(:show).with(
hash_including(
transient: false,
append: true,
timeout: 3,
urgency: :low,
summary: "Welcome",
body: "Welcome to Guard",
icon_path: "/tmp/welcome.png"
)
)
subject.notify("Welcome to Guard",
title: "Welcome",
image: "/tmp/welcome.png")
end
end
context "without additional options" do
it "shows the notification with the default options" do
expect(::Libnotify).to receive(:show).with(
hash_including(
transient: false,
append: true,
timeout: 3,
urgency: :low,
summary: "Welcome",
body: "Welcome to Guard",
icon_path: "/tmp/welcome.png"
)
)
subject.notify("Welcome to Guard",
title: "Welcome",
image: "/tmp/welcome.png")
end
end
context "with additional options" do
it "can override the default options" do
expect(::Libnotify).to receive(:show).with(
hash_including(
transient: true,
append: false,
timeout: 5,
urgency: :critical,
summary: "Waiting",
body: "Waiting for something",
icon_path: "/tmp/wait.png"
)
)
subject.notify("Waiting for something",
type: :pending,
title: "Waiting",
image: "/tmp/wait.png",
transient: true,
append: false,
timeout: 5,
urgency: :critical
)
end
end
end
end
end
|