From 23ca27c613d07665695d9be7c871ace9033dc84f Mon Sep 17 00:00:00 2001 From: "Michael G. Schwern" Date: Thu, 12 Dec 2019 13:40:44 -0800 Subject: [PATCH 1/2] Fix "better" code in RSpec/MessageChain cop The original code results in an error, `receive` takes a single argument of the method name. ``` NoMethodError: undefined method `to_sym' for {:bar=>#}:Hash Did you mean? to_s to_set ``` --- lib/rubocop/cop/rspec/message_chain.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rubocop/cop/rspec/message_chain.rb b/lib/rubocop/cop/rspec/message_chain.rb index eff296d08..0e9c020a2 100644 --- a/lib/rubocop/cop/rspec/message_chain.rb +++ b/lib/rubocop/cop/rspec/message_chain.rb @@ -11,7 +11,7 @@ module RSpec # # # better # thing = Thing.new(baz: 42) - # allow(foo).to receive(bar: thing) + # allow(foo).to receive(:bar).and_return(thing) # class MessageChain < Cop MSG = 'Avoid stubbing using `%s`.' From 5d0b0fc4a5a9a8018e664a75df9c90455e4ed095 Mon Sep 17 00:00:00 2001 From: "Michael G. Schwern" Date: Thu, 12 Dec 2019 13:44:03 -0800 Subject: [PATCH 2/2] Generate the docs. --- manual/cops_rspec.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manual/cops_rspec.md b/manual/cops_rspec.md index 469edf106..6d586c324 100644 --- a/manual/cops_rspec.md +++ b/manual/cops_rspec.md @@ -1846,7 +1846,7 @@ allow(foo).to receive_message_chain(:bar, :baz).and_return(42) # better thing = Thing.new(baz: 42) -allow(foo).to receive(bar: thing) +allow(foo).to receive(:bar).and_return(thing) ``` ### References