{"id":266,"date":"2013-04-29T17:36:15","date_gmt":"2013-04-29T23:36:15","guid":{"rendered":"http:\/\/sha.nnoncarey.com\/blog\/?p=266"},"modified":"2013-04-29T17:38:56","modified_gmt":"2013-04-29T23:38:56","slug":"rspec-mock-withhash-expects-an-array","status":"publish","type":"post","link":"https:\/\/sha.nnoncarey.com\/blog\/archives\/266","title":{"rendered":"RSpec mock.with(Hash) expects an Array"},"content":{"rendered":"<p>The following problem, where RSpec would erroneously fail mock parameter checks in specs, has been fixed in either RSpec 2.13.0 or 2.13.1<\/p>\n<p>RSpec was misinterpreting hash argument expections as arrays. If your expectation was &#8220;mock.with(a: 1, b: 2)&#8221;, you&#8217;d get:<\/p>\n<pre class=\"brush: ruby; title: ; notranslate\" title=\"\">\r\nRSpec::Mocks::MockExpectationError: &lt;MyClass (class)&gt; received :my_method with unexpected arguments\r\n  expected: ({:a =&gt; 1, :b =&gt; 2})\r\n       got: (&#x5B;:a, 1], &#x5B;:b, 2])\r\n<\/pre>\n<p>If you tried wrapping your arguments in a hash &#8220;mock.with({a: 1, b: 2})&#8221; you&#8217;d get the very confusing:<\/p>\n<pre class=\"brush: ruby; title: ; notranslate\" title=\"\">\r\n  expected: (&#x5B;:a, 1], &#x5B;:b, 2])\r\n       got: (&#x5B;:a, 1], &#x5B;:b, 2])\r\n<\/pre>\n<p>Luckly, as mentioned, this is fixed in the latest version. Update if possible!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The following problem, where RSpec would erroneously fail mock parameter checks in specs, has been fixed in either RSpec 2.13.0 or 2.13.1 RSpec was misinterpreting hash argument expections as arrays. If your expectation was &#8220;mock.with(a: 1, b: 2)&#8221;, you&#8217;d get: RSpec::Mocks::MockExpectationError: &lt;MyClass (class)&gt; received :my_method with unexpected arguments expected: ({:a =&gt; 1, :b =&gt; 2}) &hellip; <a href=\"https:\/\/sha.nnoncarey.com\/blog\/archives\/266\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;RSpec mock.with(Hash) expects an Array&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-266","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/posts\/266","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/comments?post=266"}],"version-history":[{"count":4,"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/posts\/266\/revisions"}],"predecessor-version":[{"id":298,"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/posts\/266\/revisions\/298"}],"wp:attachment":[{"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/media?parent=266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/categories?post=266"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sha.nnoncarey.com\/blog\/wp-json\/wp\/v2\/tags?post=266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}