Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion undefined method `matches_method?' for nil:NilClass

Received: by 10.180.90.40 with SMTP id bt8mr1006857wib.2.1336982307776;
        Mon, 14 May 2012 00:58:27 -0700 (PDT)
X-BeenThere: mocha-developer@googlegroups.com
Received: by 10.216.72.65 with SMTP id s43ls1350003wed.9.gmail; Mon, 14 May
 2012 00:58:26 -0700 (PDT)
Received: by 10.180.14.69 with SMTP id n5mr775367wic.4.1336982306378;
        Mon, 14 May 2012 00:58:26 -0700 (PDT)
Received: by 10.180.14.69 with SMTP id n5mr775366wic.4.1336982306344;
        Mon, 14 May 2012 00:58:26 -0700 (PDT)
Return-Path: <floehop...@gmail.com>
Received: from mail-wi0-f182.google.com (mail-wi0-f182.google.com [209.85.212.182])
        by gmr-mx.google.com with ESMTPS id ei10si5274964wid.0.2012.05.14.00.58.26
        (version=TLSv1/SSLv3 cipher=OTHER);
        Mon, 14 May 2012 00:58:26 -0700 (PDT)
Received-SPF: pass (google.com: domain of floehop...@gmail.com designates 209.85.212.182 as permitted sender) client-ip=209.85.212.182;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of floehop...@gmail.com designates 209.85.212.182 as permitted sender) smtp.mail=floehop...@gmail.com; dkim=pass header...@gmail.com
Received: by wibhm6 with SMTP id hm6so1269113wib.17
        for <mocha-developer@googlegroups.com>; Mon, 14 May 2012 00:58:26 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=subject:mime-version:content-type:from:in-reply-to:date:message-id
         :references:to:x-mailer;
        bh=DPD2VYRUqeu9HPEoem/IEeM78f+eLqps2Eq37OYHRaA=;
        b=E/K/5dzzoSLaXsd9Xwko1uE8gvM+gHUE+HSbDoXl0CbbmKdOe7NxA9hExAsKNnrA18
         NBGd2cbqnajUiYqw8/qCEnsPITJbWh/scY3zkjQF691R/HAVoUhyYkbYwNYzsZYRIVpU
         bFfjleeCZFmBbOBV12vK/FhXI3UDO8zHGlQ0jQmdHA20cNejF2QAUQ40lVsk5a49FZSh
         VrWSIgxY5vLAC30ALp214x9aROFJjHBAxjUEIhhsFGLj4Tcl+yHE1g1LsBLn8T63lQCH
         v/M2sA6kB6iV+cQOi36J1vvvi2Vv7JiSepvEB3xjkJzhWcIIkIV/i136o+EtvswvEd/j
         2sUg==
Received: by 10.181.11.137 with SMTP id ei9mr6214494wid.21.1336982306170;
        Mon, 14 May 2012 00:58:26 -0700 (PDT)
Return-Path: <floehop...@gmail.com>
Received: from [10.91.112.182] ([82.132.139.230])
        by mx.google.com with ESMTPS id k6sm33758198wiy.7.2012.05.14.00.58.22
        (version=TLSv1/SSLv3 cipher=OTHER);
        Mon, 14 May 2012 00:58:25 -0700 (PDT)
Subject: Re: undefined method `matches_method?' for nil:NilClass
Mime-Version: 1.0 (Apple Message framework v1257)
Content-Type: multipart/alternative; boundary="Apple-Mail=_F7D84A51-81FC-4451-B2CA-B55C4CD9E32F"
From: James Mead <floehop...@gmail.com>
In-Reply-To: <a6dac7ca-c03b-47c3-a227-0578dd36c...@t2g2000pbg.googlegroups.com>
Date: Mon, 14 May 2012 08:58:16 +0100
Message-Id: <04FFBC39-E83A-48F8-85E1-B37C25B5F...@gmail.com>
References: <da7dfe61-c2c0-4978-a696-6dffe5319...@2g2000yqk.googlegroups.com> <25137949.393.1335865640809.JavaMail.geo-discussion-forums@vbqq1> <4eea69eb-cee1-4614-9f37-bf1d4746c...@m13g2000yqc.googlegroups.com> <0C75698A-562E-420D-9BB5-07BF7118E...@gmail.com> <d7b435f7-7b4f-466e-84f8-abfeced39...@n4g2000vbz.googlegroups.com> <a6dac7ca-c03b-47c3-a227-0578dd36c...@t2g2000pbg.googlegroups.com>
To: mocha-developer@googlegroups.com
X-Mailer: Apple Mail (2.1257)


--Apple-Mail=_F7D84A51-81FC-4451-B2CA-B55C4CD9E32F
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=iso-8859-1

Hi Patrick,

I'm sorry I haven't had a chance to look into this any further. I've =
created a pull request [1] to provide a place to discuss the issue =
further.

Out of interest, did you try using the version of Mocha in the =
"stub-serialization" branch [2] that I mentioned? It would be useful to =
know whether this solved your problem.

Regards, James.

[1] https://github.com/freerange/mocha/pull/81
[2] https://github.com/freerange/mocha/tree/stub-serialization


On 10 May 2012, at 01:42, patrick99e99 wrote:

> BTW, my current workaround was to simply do in my test's before block:
>=20
> 30     Purchase.class_eval do
> 31       attr_accessor :txn
> 32     end
>=20
> That way, it skips storing it in the db, and I didn't really need to
> test anything to do with retrieving that object.
>=20
> -patrick
>=20
> On May 9, 3:47 pm, patrick99e99 <patrick99...@gmail.com> wrote:
>> Hi James,
>>=20
>> Well...  So I have a purchase model that integrates with a 3rd party
>> payment service.  The model has a before_create callback which
>> contacts the 3rd party service and gets a transaction object from
>> them, this object is serialized and stored in the model.  This
>> transaction object responds to methods "success?" and "capture"...
>> So, I have some state_machine stuff in the purchase model that does
>> various things IF that object is success? and if capture returns true
>> etc..  So when I was writing specs, I obviously don't really want to
>> be hitting the API of the 3rd party service, so I stubbed that out =
and
>> wanted it to just return a fake transaction object that has success
>> and capture methods that I could make true/false depending on what I
>> was testing.  So that's why...  I am open to alternative approaches/
>> ideas if you have any.
>>=20
>> -patrick
>>=20
>> On May 2, 2:42 am, James Mead <floehop...@gmail.com> wrote:
>>=20
>>=20
>>=20
>>=20
>>=20
>>=20
>>=20
>>> On 1 May 2012, at 20:06, patrick99e99 wrote:
>>=20
>>>> Hi James,
>>=20
>>>> Here is my gemfile...
>>>> https://gist.github.com/2570515
>>=20
>>>> I just did some experimenting and narrowed the problem down to
>>>> serialization...
>>=20
>>>> If I do:
>>=20
>>>> class Purchase < ActiveRecord::Base
>>>>  serialize :txn
>>>> end
>>=20
>>>> And then from the context of my rspec tests, launch pry as a =
debugger:
>>=20
>>>> [1] pry(#<RSpec::Core::ExampleGroup::Nested_1::Nested_1>)> p =3D
>>>> Purchase.create!
>>>> =3D> #<Purchase id: 1, created_at: "2012-05-01 19:03:44", =
updated_at:
>>>> "2012-05-01 19:03:44", txn: nil>
>>>> [2] pry(#<RSpec::Core::ExampleGroup::Nested_1::Nested_1>)> p.save
>>>> =3D> true
>>>> [3] pry(#<RSpec::Core::ExampleGroup::Nested_1::Nested_1>)> p.txn =3D
>>>> stub("lol")
>>>> =3D> #<Mock:lol>
>>>> [4] pry(#<RSpec::Core::ExampleGroup::Nested_1::Nested_1>)> p.save
>>>> NoMethodError: undefined method `matches_method?' for nil:NilClass
>>>> from /Users/bountybuy/.rvm/gems/ruby-1.9.3-p125@bountybuy/gems/
>>>> mocha-0.10.5/lib/mocha/mock.rb:185:in `respond_to?'
>>>> [5] pry(#<RSpec::Core::ExampleGroup::Nested_1::Nested_1>)>
>>=20
>>>> -patrick
>>=20
>>> Hi Patrick,
>>=20
>>> I have managed to reproduce the problem you are seeing. The problem =
is that when you save your instance of Purchase with the stub set on the =
txn attribute, you are trying to serialize & deserialize the stub =
object. Unfortunately in the process of de-serializing =
Mocha#Mock#respond_to? is called before the instance has been properly =
re-hydrated (i.e. no instance variables have been set) and so you see =
the NoMethodError exception.
>>=20
>>> I've pushed up a potential fix [1] into a branch, but I want to have =
a think about whether this is actually a sensible solution. As I mention =
in the commit note, I'm not at all sure it's sensible to allow mock =
objects to be serialized and deserialized at all. If I can find a way to =
hook into serialization in a sensible way, I may just change Mocha to =
fail-fast when a mock object is serialized.
>>=20
>>> Can you explain a bit more why you want to stub the Purchase#txn =
attribute and in particular why you want to persist this stub object to =
the database? I'm sure there is a better way to achieve what you want, =
but I'm not sure we have enough details to go on.
>>=20
>>> Regards, James.
>>=20
>>> =
[1]https://github.com/floehopper/mocha/commit/d0569869da15fa9d3d86b18047..=
.
>=20
> --=20
> You received this message because you are subscribed to the Google =
Groups "mocha-developer" group.
> To post to this group, send email to mocha-developer@googlegroups.com.
> To unsubscribe from this group, send email to =
mocha-developer+unsubscribe@googlegroups.com.
> For more options, visit this group at =
http://groups.google.com/group/mocha-developer?hl=3Den.
>=20


--Apple-Mail=_F7D84A51-81FC-4451-B2CA-B55C4CD9E32F
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=iso-8859-1

<html><head></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: after-white-space; =
"><div>Hi Patrick,</div><div><br></div>I'm sorry I haven't had a chance =
to look into this any further. I've created a pull request [1] to =
provide a place to discuss the issue further.<div><br></div><div>Out of =
interest, did you try using the version of Mocha in the =
"stub-serialization" branch [2] that I mentioned? It would be useful to =
know whether this solved your problem.<div><br></div><div>Regards, =
James.</div><div><br></div><div>[1]&nbsp;<a =
href=3D"https://github.com/freerange/mocha/pull/81">https://github.com/fre=
erange/mocha/pull/81</a></div><div>[2]&nbsp;<a =
href=3D"https://github.com/freerange/mocha/tree/stub-serialization">https:=
//github.com/freerange/mocha/tree/stub-serialization</a></div><div><br></d=
iv><div><br><div><div>On 10 May 2012, at 01:42, patrick99e99 =
wrote:</div><br class=3D"Apple-interchange-newline"><blockquote =
type=3D"cite"><div>BTW, my current workaround was to simply do in my =
test's before block:<br><br> 30 =
&nbsp;&nbsp;&nbsp;&nbsp;Purchase.class_eval do<br> 31 =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;attr_accessor :txn<br> 32 =
&nbsp;&nbsp;&nbsp;&nbsp;end<br><br>That way, it skips storing it in the =
db, and I didn't really need to<br>test anything to do with retrieving =
that object.<br><br>-patrick<br><br>On May 9, 3:47&nbsp;pm, patrick99e99 =
&lt;patrick99...@gmail.com&gt; wrote:<br><blockquote type=3D"cite">Hi =
James,<br></blockquote><blockquote =
type=3D"cite"><br></blockquote><blockquote type=3D"cite">Well... =
&nbsp;So I have a purchase model that integrates with a 3rd =
party<br></blockquote><blockquote type=3D"cite">payment service. =
&nbsp;The model has a before_create callback =
which<br></blockquote><blockquote type=3D"cite">contacts the 3rd party =
service and gets a transaction object from<br></blockquote><blockquote =
type=3D"cite">them, this object is serialized and stored in the model. =
&nbsp;This<br></blockquote><blockquote type=3D"cite">transaction object =
responds to methods "success?" and =
"capture"...<br></blockquote><blockquote type=3D"cite">So, I have some =
state_machine stuff in the purchase model that =
does<br></blockquote><blockquote type=3D"cite">various things IF that =
object is success? and if capture returns =
true<br></blockquote><blockquote type=3D"cite">etc.. &nbsp;So when I was =
writing specs, I obviously don't really want =
to<br></blockquote><blockquote type=3D"cite">be hitting the API of the =
3rd party service, so I stubbed that out and<br></blockquote><blockquote =
type=3D"cite">wanted it to just return a fake transaction object that =
has success<br></blockquote><blockquote type=3D"cite">and capture =
methods that I could make true/false depending on what =
I<br></blockquote><blockquote type=3D"cite">was testing. &nbsp;So that's =
why... &nbsp;I am open to alternative =
approaches/<br></blockquote><blockquote type=3D"cite">ideas if you have =
any.<br></blockquote><blockquote =
type=3D"cite"><br></blockquote><blockquote =
type=3D"cite">-patrick<br></blockquote><blockquote =
type=3D"cite"><br></blockquote><blockquote type=3D"cite">On May 2, =
2:42&nbsp;am, James Mead &lt;floehop...@gmail.com&gt; =
wrote:<br></blockquote><blockquote =
type=3D"cite"><br></blockquote><blockquote =
type=3D"cite"><br></blockquote><blockquote =
type=3D"cite"><br></blockquote><blockquote =
type=3D"cite"><br></blockquote><blockquote =
type=3D"cite"><br></blockquote><blockquote =
type=3D"cite"><br></blockquote><blockquote =
type=3D"cite"><br></blockquote><blockquote type=3D"cite"><blockquote =
type=3D"cite">On 1 May 2012, at 20:06, patrick99e99 =
wrote:<br></blockquote></blockquote><blockquote =
type=3D"cite"><br></blockquote><blockquote type=3D"cite"><blockquote =
type=3D"cite"><blockquote type=3D"cite">Hi =
James,<br></blockquote></blockquote></blockquote><blockquote =
type=3D"cite"><br></blockquote><blockquote type=3D"cite"><blockquote =
type=3D"cite"><blockquote type=3D"cite">Here is my =
gemfile...<br></blockquote></blockquote></blockquote><blockquote =
type=3D"cite"><blockquote type=3D"cite"><blockquote type=3D"cite"><a =
href=3D"https://gist.github.com/2570515">https://gist.github.com/2570515</=
a><br></blockquote></blockquote></blockquote><blockquote =
type=3D"cite"><br></blockquote><blockquote type=3D"cite"><blockquote =
type=3D"cite"><blockquote type=3D"cite">I just did some experimenting =
and narrowed the problem down =
to<br></blockquote></blockquote></blockquote><blockquote =
type=3D"cite"><blockquote type=3D"cite"><blockquote =
type=3D"cite">serialization...<br></blockquote></blockquote></blockquote><=
blockquote type=3D"cite"><br></blockquote><blockquote =
type=3D"cite"><blockquote type=3D"cite"><blockquote type=3D"cite">If I =
do:<br></blockquote></blockquote></blockquote><blockquote =
type=3D"cite"><br></blockquote><blockquote type=3D"cite"><blockquote =
type=3D"cite"><blockquote type=3D"cite">class Purchase &lt; =
ActiveRecord::Base<br></blockquote></blockquote></blockquote><blockquote =
type=3D"cite"><blockquote type=3D"cite"><blockquote =
type=3D"cite">&nbsp;serialize =
:txn<br></blockquote></blockquote></blockquote><blockquote =
type=3D"cite"><blockquote type=3D"cite"><blockquote =
type=3D"cite">end<br></blockquote></blockquote></blockquote><blockquote =
type=3D"cite"><br></blockquote><blockquote type=3D"cite"><blockquote =
type=3D"cite"><blockquote type=3D"cite">And then from the context of my =
rspec tests, launch pry as a =
debugger:<br></blockquote></blockquote></blockquote><blockquote =
type=3D"cite"><br></blockquote><blockquote type=3D"cite"><blockquote =
type=3D"cite"><blockquote type=3D"cite">[1] =
pry(#&lt;RSpec::Core::ExampleGroup::Nested_1::Nested_1&gt;)&gt; p =
=3D<br></blockquote></blockquote></blockquote><blockquote =
type=3D"cite"><blockquote type=3D"cite"><blockquote =
type=3D"cite">Purchase.create!<br></blockquote></blockquote></blockquote><=
blockquote type=3D"cite"><blockquote type=3D"cite"><blockquote =
type=3D"cite">=3D&gt; #&lt;Purchase id: 1, created_at: "2012-05-01 =
19:03:44", =
updated_at:<br></blockquote></blockquote></blockquote><blockquote =
type=3D"cite"><blockquote type=3D"cite"><blockquote =
type=3D"cite">"2012-05-01 19:03:44", txn: =
nil&gt;<br></blockquote></blockquote></blockquote><blockquote =
type=3D"cite"><blockquote type=3D"cite"><blockquote type=3D"cite">[2] =
pry(#&lt;RSpec::Core::ExampleGroup::Nested_1::Nested_1&gt;)&gt; =
p.save<br></blockquote></blockquote></blockquote><blockquote =
type=3D"cite"><blockquote type=3D"cite"><blockquote type=3D"cite">=3D&gt; =
true<br></blockquote></blockquote></blockquote><blockquote =
type=3D"cite"><blockquote type=3D"cite"><blockquote type=3D"cite">[3] =
pry(#&lt;RSpec::Core::ExampleGroup::Nested_1::Nested_1&gt;)&gt; p.txn =
=3D<br></blockquote></blockquote></blockquote><blockquote =
type=3D"cite"><blockquote type=3D"cite"><blockquote =
type=3D"cite">stub("lol")<br></blockquote></blockquote></blockquote><block=
quote type=3D"cite"><blockquote type=3D"cite"><blockquote =
type=3D"cite">=3D&gt; =
#&lt;Mock:lol&gt;<br></blockquote></blockquote></blockquote><blockquote =
type=3D"cite"><blockquote type=3D"cite"><blockquote type=3D"cite">[4] =
pry(#&lt;RSpec::Core::ExampleGroup::Nested_1::Nested_1&gt;)&gt; =
p.save<br></blockquote></blockquote></blockquote><blockquote =
type=3D"cite"><blockquote type=3D"cite"><blockquote =
type=3D"cite">NoMethodError: undefined method `matches_method?' for =
nil:NilClass<br></blockquote></blockquote></blockquote><blockquote =
type=3D"cite"><blockquote type=3D"cite"><blockquote type=3D"cite">from =
/Users/bountybuy/.rvm/gems/ruby-1.9.3-p125@bountybuy/gems/<br></blockquote=
></blockquote></blockquote><blockquote type=3D"cite"><blockquote =
type=3D"cite"><blockquote =
type=3D"cite">mocha-0.10.5/lib/mocha/mock.rb:185:in =
`respond_to?'<br></blockquote></blockquote></blockquote><blockquote =
type=3D"cite"><blockquote type=3D"cite"><blockquote type=3D"cite">[5] =
pry(#&lt;RSpec::Core::ExampleGroup::Nested_1::Nested_1&gt;)&gt;<br></block=
quote></blockquote></blockquote><blockquote =
type=3D"cite"><br></blockquote><blockquote type=3D"cite"><blockquote =
type=3D"cite"><blockquote =
type=3D"cite">-patrick<br></blockquote></blockquote></blockquote><blockquo=
te type=3D"cite"><br></blockquote><blockquote type=3D"cite"><blockquote =
type=3D"cite">Hi Patrick,<br></blockquote></blockquote><blockquote =
type=3D"cite"><br></blockquote><blockquote type=3D"cite"><blockquote =
type=3D"cite">I have managed to reproduce the problem you are seeing. =
The problem is that when you save your instance of Purchase with the =
stub set on the txn attribute, you are trying to serialize &amp; =
deserialize the stub object. Unfortunately in the process of =
de-serializing Mocha#Mock#respond_to? is called before the instance has =
been properly re-hydrated (i.e. no instance variables have been set) and =
so you see the NoMethodError =
exception.<br></blockquote></blockquote><blockquote =
type=3D"cite"><br></blockquote><blockquote type=3D"cite"><blockquote =
type=3D"cite">I've pushed up a potential fix [1] into a branch, but I =
want to have a think about whether this is actually a sensible solution. =
As I mention in the commit note, I'm not at all sure it's sensible to =
allow mock objects to be serialized and deserialized at all. If I can =
find a way to hook into serialization in a sensible way, I may just =
change Mocha to fail-fast when a mock object is =
serialized.<br></blockquote></blockquote><blockquote =
type=3D"cite"><br></blockquote><blockquote type=3D"cite"><blockquote =
type=3D"cite">Can you explain a bit more why you want to stub the =
Purchase#txn attribute and in particular why you want to persist this =
stub object to the database? I'm sure there is a better way to achieve =
what you want, but I'm not sure we have enough details to go =
on.<br></blockquote></blockquote><blockquote =
type=3D"cite"><br></blockquote><blockquote type=3D"cite"><blockquote =
type=3D"cite">Regards, James.<br></blockquote></blockquote><blockquote =
type=3D"cite"><br></blockquote><blockquote type=3D"cite"><blockquote =
type=3D"cite">[1]<a =
href=3D"https://github.com/floehopper/mocha/commit/d0569869da15fa9d3d86b18=
047">https://github.com/floehopper/mocha/commit/d0569869da15fa9d3d86b18047=
</a>...<br></blockquote></blockquote><br>-- <br>You received this =
message because you are subscribed to the Google Groups =
"mocha-developer" group.<br>To post to this group, send email to <a =
href=3D"mailto:mocha-developer@googlegroups.com">mocha-developer@googlegro=
ups.com</a>.<br>To unsubscribe from this group, send email to <a =
href=3D"mailto:mocha-developer+unsubscribe@googlegroups.com">mocha-develop=
er+unsubscribe@googlegroups.com</a>.<br>For more options, visit this =
group at <a =
href=3D"http://groups.google.com/group/mocha-developer?hl=3Den">http://gro=
ups.google.com/group/mocha-developer?hl=3Den</a>.<br><br></div></blockquot=
e></div><br></div></div></body></html>=

--Apple-Mail=_F7D84A51-81FC-4451-B2CA-B55C4CD9E32F--