Skip to content

Commit

Permalink
Fix hash argument matching with rspec-mocks 3.10.3 and Ruby 3+.
Browse files Browse the repository at this point in the history
Passing hash and keyword values as function parameters
breaks test suite when using rspec-mocks >= v3.10.3.
  • Loading branch information
jackorp committed Feb 25, 2022
1 parent c726a05 commit 374d1af
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 47 deletions.
2 changes: 1 addition & 1 deletion spec/lib/notiffany/notifier/detected_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Notifier
context "when not available" do
before do
allow(foo_mod).to receive(:new).
with(foo: :bar).
with({ foo: :bar }).
and_raise(Notifier::Base::UnavailableError, "something failed")
allow(logger).to receive(:warning)
end
Expand Down
66 changes: 36 additions & 30 deletions spec/lib/notiffany/notifier/rb_notifu_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,18 @@ class Notifier
context "with options passed at initialization" do
it "uses these options by default" do
expect(::Notifu).to receive(:show).with(
time: 3,
icon: false,
baloon: false,
nosound: false,
noquiet: false,
xp: false,
title: "Hello",
type: :info,
image: "/tmp/welcome.png",
message: "Welcome to Guard"
{
time: 3,
icon: false,
baloon: false,
nosound: false,
noquiet: false,
xp: false,
title: "Hello",
type: :info,
image: "/tmp/welcome.png",
message: "Welcome to Guard"
}
)

subject.notify("Welcome to Guard", image: "/tmp/welcome.png")
Expand Down Expand Up @@ -79,16 +81,18 @@ class Notifier
context "without additional options" do
it "shows the notification with the default options" do
expect(::Notifu).to receive(:show).with(
time: 3,
icon: false,
baloon: false,
nosound: false,
noquiet: false,
xp: false,
title: "Welcome",
type: :info,
image: "/tmp/welcome.png",
message: "Welcome to Guard"
{
time: 3,
icon: false,
baloon: false,
nosound: false,
noquiet: false,
xp: false,
title: "Welcome",
type: :info,
image: "/tmp/welcome.png",
message: "Welcome to Guard"
}
)

subject.notify("Welcome to Guard",
Expand All @@ -100,16 +104,18 @@ class Notifier
context "with additional options" do
it "can override the default options" do
expect(::Notifu).to receive(:show).with(
time: 5,
icon: true,
baloon: true,
nosound: true,
noquiet: true,
xp: true,
title: "Waiting",
type: :warn,
image: "/tmp/wait.png",
message: "Waiting for something"
{
time: 5,
icon: true,
baloon: true,
nosound: true,
noquiet: true,
xp: true,
title: "Waiting",
type: :warn,
image: "/tmp/wait.png",
message: "Waiting for something"
}
)

subject.notify("Waiting for something",
Expand Down
47 changes: 31 additions & 16 deletions spec/lib/notiffany/notifier/terminal_notifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module Notiffany

it "uses these options by default" do
expect(TerminalNotifier::Guard).to receive(:execute).
with(false, title: "Hello", type: :success, message: "any message")
with(false, { title: "Hello", type: :success, message: "any message" })

subject.notify("any message")
end
Expand All @@ -46,41 +46,56 @@ module Notiffany
expect(::TerminalNotifier::Guard).to receive(:execute).
with(
false,
title: "Welcome",
type: :success,
message: "any message")
{
title: "Welcome",
type: :success,
message: "any message"
}
)

subject.notify("any message", title: "Welcome")
end
end

it "should call the notifier." do
expect(::TerminalNotifier::Guard).to receive(:execute).
with(false,
title: "any title",
type: :success,
message: "any message")
with(
false,
{
title: "any title",
type: :success,
message: "any message"
}
)

subject.notify("any message", title: "any title")
end

it "should allow the title to be customized" do
expect(::TerminalNotifier::Guard).to receive(:execute).
with(false,
title: "any title",
message: "any message",
type: :error)
with(
false,
{
title: "any title",
message: "any message",
type: :error
}
)

subject.notify("any message", type: :error, title: "any title")
end

context "without a title set" do
it "should show the app name in the title" do
expect(::TerminalNotifier::Guard).to receive(:execute).
with(false,
title: "FooBar Success",
type: :success,
message: "any message")
with(
false,
{
title: "FooBar Success",
type: :success,
message: "any message"
}
)

# TODO: why would anyone set the title explicitly to nil? and also
# expect it to be set to a default value?
Expand Down

0 comments on commit 374d1af

Please sign in to comment.