mocking with cucumber, rspec and rails

273 views
Skip to first unread message

Florent2

unread,
Jun 29, 2010, 4:18:38 PM6/29/10
to Cukes
Hello,

I need mocking in a feature for code interacting with a third party
service, in a Rails3beta4 application, with cucumber 0.8.3, cucumber-
rails 0.3.2 and rSpec 2.0.0.beta.14.

I try to add require 'spec/stubs/cucumber' in env.rb but without
success, I get a "no such file to load -- spec/stubs/cucumber
(LoadError)" error.

When trying the solution proposed in
http://groups.google.com/group/cukes/browse_thread/thread/522dc6323b2d34b9/dbce8743b017a17a
and running my feature scenario (having 5 steps), I got failed initial
and final steps: F-----F, saying my scenario 5 steps were skipped.

That's the first time I need mocking in Cucumber, maybe I miss
something.

Any help appreciated :)

Florent

Matt Wynne

unread,
Jun 29, 2010, 4:58:24 PM6/29/10
to cu...@googlegroups.com

On 29 Jun 2010, at 21:18, Florent2 wrote:

> Hello,
>
> I need mocking in a feature for code interacting with a third party
> service, in a Rails3beta4 application, with cucumber 0.8.3, cucumber-
> rails 0.3.2 and rSpec 2.0.0.beta.14.
>
> I try to add require 'spec/stubs/cucumber' in env.rb but without
> success, I get a "no such file to load -- spec/stubs/cucumber
> (LoadError)" error.
>
> When trying the solution proposed in
> http://groups.google.com/group/cukes/browse_thread/thread/522dc6323b2d34b9/dbce8743b017a17a
> and running my feature scenario (having 5 steps), I got failed initial
> and final steps: F-----F, saying my scenario 5 steps were skipped.

Your hooks have probably failed. Try running with -f pretty to see details about the error. I suspect the hack in that thread using $rspec_mocks.verify_all might not work in rspec 2.0 but I don't know that.

Have you considered using the adapter pattern and building your own fake substitute for the service instead of using mock objects?

> That's the first time I need mocking in Cucumber, maybe I miss
> something.
>
> Any help appreciated :)
>
> Florent
>

> --
> You received this message because you are subscribed to the Google Groups "Cukes" group.
> To post to this group, send email to cu...@googlegroups.com.
> To unsubscribe from this group, send email to cukes+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
>

Jonas Nicklas

unread,
Jun 30, 2010, 4:14:53 AM6/30/10
to cu...@googlegroups.com
Isn't 'spec/stubs/cucumber' part of rspec? I'd be surprised if that's
still there on RSpec 2.

/Jonas

Florent2

unread,
Jul 1, 2010, 11:00:20 AM7/1/10
to Cukes
Thanks Jonas. You're right, I've just searched in rSpec2 code
something similar to spec/stubs/cucumber and could not anything. I'll
ask in the rSpec list, if there is a plan to support it again.

On 30 juin, 03:14, Jonas Nicklas <jonas.nick...@gmail.com> wrote:
> Isn't 'spec/stubs/cucumber' part of rspec? I'd be surprised if that's
> still there on RSpec 2.
>
> /Jonas
>
>
>
> On Tue, Jun 29, 2010 at 10:58 PM, Matt Wynne <m...@mattwynne.net> wrote:
>
> > On 29 Jun 2010, at 21:18, Florent2 wrote:
>
> >> Hello,
>
> >> I need mocking in a feature for code interacting with a third party
> >> service, in a Rails3beta4 application, with cucumber 0.8.3, cucumber-
> >> rails 0.3.2 and rSpec 2.0.0.beta.14.
>
> >> I try to add require 'spec/stubs/cucumber' in env.rb but without
> >> success, I get a "no such file to load -- spec/stubs/cucumber
> >> (LoadError)" error.
>
> >> When trying the solution proposed in
> >>http://groups.google.com/group/cukes/browse_thread/thread/522dc6323b2...
> >> and running my feature scenario (having 5 steps), I got failed initial
> >> and final steps: F-----F, saying my scenario 5 steps were skipped.
>
> > Your hooks have probably failed. Try running with -f pretty to see details about the error. I suspect the hack in that thread using $rspec_mocks.verify_all might not work in rspec 2.0 but I don't know that.
>
> > Have you considered using the adapter pattern and building your own fake substitute for the service instead of using mock objects?
>
> >> That's the first time I need mocking in Cucumber, maybe I miss
> >> something.
>
> >> Any help appreciated :)
>
> >> Florent
>
> >> --
> >> You received this message because you are subscribed to the Google Groups "Cukes" group.
> >> To post to this group, send email to cu...@googlegroups.com.
> >> To unsubscribe from this group, send email to cukes+un...@googlegroups.com.
> >> For more options, visit this group athttp://groups.google.com/group/cukes?hl=en.

Florent2

unread,
Jul 1, 2010, 11:13:43 AM7/1/10
to Cukes
On 29 juin, 15:58, Matt Wynne <m...@mattwynne.net> wrote:
> On 29 Jun 2010, at 21:18, Florent2 wrote:
>
> > Hello,
>
> > I need mocking in a feature for code interacting with a third party
> > service, in a Rails3beta4 application, with cucumber 0.8.3, cucumber-
> > rails 0.3.2 and rSpec 2.0.0.beta.14.
>
> > I try to add require 'spec/stubs/cucumber' in env.rb but without
> > success, I get a "no such file to load -- spec/stubs/cucumber
> > (LoadError)" error.
>
> > When trying the solution proposed in
> >http://groups.google.com/group/cukes/browse_thread/thread/522dc6323b2...
> > and running my feature scenario (having 5 steps), I got failed initial
> > and final steps: F-----F, saying my scenario 5 steps were skipped.
>
> Your hooks have probably failed. Try running with -f pretty to see details about the error. I suspect the hack in that thread using $rspec_mocks.verify_all might not work in rspec 2.0 but I don't know that.

Thanks Matt. You're right, with -f pretty I can see the following
errors:

uninitialized constant Spec::Mocks (NameError)
/Users/Florent/myapp/features/support/env.rb:61:in `Before'
=> corresponds to $rspec_mocks ||= Spec::Mocks::Space.new

undefined method `reset_all' for nil:NilClass (NoMethodError)
/Users/Florent/.rvm/gems/ree-1.8.7-2010.01/gems/
activesupport-3.0.0.beta4/lib/active_support/whiny_nil.rb:48:in
`method_missing'
/Users/Florent/Programmation/myapp/features/support/env.rb:67:in
`After'
=> corresponds to $rspec_mocks.reset_all

> Have you considered using the adapter pattern and building your own fake substitute for the service instead of using mock objects?

I hadn't considered that. I'll read about the adapter pattern and try
to make use of it. Thanks.

With the absence of rSpec stubbing in Cucumber with rSpec2 (AFAIW) is
this the recommended way to build Cucumber features dealing with third
party services?

aslak hellesoy

unread,
Jul 1, 2010, 11:19:30 AM7/1/10
to cu...@googlegroups.com

Cucumber never had special support for RSpec stubbing.
Just refactor the code in env.rb to use the RSpec2 API.

Where did you take your stubbing code from btw?

Aslak

> this the recommended way to build Cucumber features dealing with third
> party services?
>

Florent2

unread,
Jul 1, 2010, 11:34:09 AM7/1/10
to Cukes
On 1 juil, 10:19, aslak hellesoy <aslak.helle...@gmail.com> wrote:
Sorry Alask, I'm not sure I understand your message. I initially tried
to follow those instructions to stub with Cucumber:
http://wiki.github.com/aslakhellesoy/cucumber/mocking-and-stubbing-with-cucumber

and then this solution:
http://www.google.com/url?sa=D&q=http://groups.google.com/group/cukes/browse_thread/thread/522dc6323b2d34b9/dbce8743b017a17a&usg=AFQjCNGt48AaOsJdZ9SwcPWlym_uqppcVw

I'll have a look at the Rspec2 API to figure out how it differs from
Rspec when used to stub in Cucumber. Thanks.

aslak hellesoy

unread,
Jul 1, 2010, 12:00:42 PM7/1/10
to cu...@googlegroups.com

Ok, I see.

> and then this solution:
> http://www.google.com/url?sa=D&q=http://groups.google.com/group/cukes/browse_thread/thread/522dc6323b2d34b9/dbce8743b017a17a&usg=AFQjCNGt48AaOsJdZ9SwcPWlym_uqppcVw
>
> I'll have a look at the Rspec2 API to figure out how it differs from
> Rspec when used to stub in Cucumber. Thanks.
>

It would be nice if RSpec2 had something similar to what RSpec1 had -
maybe you can convince David to add it.

Aslak

aslak hellesoy

unread,
Jul 1, 2010, 6:05:48 PM7/1/10
to cu...@googlegroups.com

Never mind - I added that support to Cucumber instead:

http://github.com/aslakhellesoy/cucumber/commit/4cf06933fd7aa8964299bb2dfa56256a0c2a0035
http://wiki.github.com/aslakhellesoy/cucumber/mocking-and-stubbing-with-cucumber

There is something wrong with the Github wiki. It seems like they are
not ivalidating the wiki page caches properly. Hit edit on the page to
see the updates I just made.

Aslak

Florent2

unread,
Jul 2, 2010, 12:49:39 AM7/2/10
to Cukes
On 1 juil, 17:05, aslak hellesoy <aslak.helle...@gmail.com> wrote:
> On Thu, Jul 1, 2010 at 6:00 PM, aslak hellesoy <aslak.helle...@gmail.com> wrote:
> >>http://wiki.github.com/aslakhellesoy/cucumber/mocking-and-stubbing-wi...
>
> > Ok, I see.
>
> >> and then this solution:
> >>http://www.google.com/url?sa=D&q=http://groups.google.com/group/cukes...
>
> >> I'll have a look at the Rspec2 API to figure out how it differs from
> >> Rspec when used to stub in Cucumber. Thanks.
>
> > It would be nice if RSpec2 had something similar to what RSpec1 had -
> > maybe you can convince David to add it.
>
> Never mind - I added that support to Cucumber instead:
>
> http://github.com/aslakhellesoy/cucumber/commit/4cf06933fd7aa8964299b...http://wiki.github.com/aslakhellesoy/cucumber/mocking-and-stubbing-wi...

Thanks a lot Alask! I am very grateful. Thanks to your instructions, I
could use RSpec2 doubles :) (I just corrected a typo in the wiki, 's'
was missing at the end of double in the require command)
Reply all
Reply to author
Forward
0 new messages