Skip to content

Instantly share code, notes, and snippets.

@okonomi
Created October 1, 2022 06:52
Show Gist options
  • Save okonomi/12fc0efcc3aa07e86f1c0dbd433f7c2c to your computer and use it in GitHub Desktop.
Save okonomi/12fc0efcc3aa07e86f1c0dbd433f7c2c to your computer and use it in GitHub Desktop.
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "rspec"
end
require "rspec/autorun"
RSpec.describe "method double test" do
class App
def foo(*args, **kwargs)
bar(*args, **kwargs)
end
def bar(*args, **kwargs)
p args, kwargs
end
end
it "with kwargs" do
app = App.new
expect(app).to receive(:bar).with("arg", a: :b)
app.foo("arg", a: :b)
end
it "without kwargs" do
app = App.new
# expect(app).to receive(:bar).with("arg")
expect(app).to receive(:bar).with("arg", **{})
app.foo("arg")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment