[rspec-users] Gem tutorials / setting up rspec in a gem

aslak hellesoy aslak.hellesoy at gmail.com
Tue Mar 30 07:09:21 EDT 2010


On Tue, Mar 30, 2010 at 12:17 PM, Ramon Tayag <ramon.tayag at gmail.com> wrote:

> Hey everyone!
>
> A few days ago, I tried my hand at creating a gem. I've been putting it off
> for a long time because of the lack of documentation (or the lack of my
> Googling skills). When I search how to create gems with RSpec, I get pages
> that talk about gem templates with the rspec option, as if that would solve
> it all.
>
>
Have you tried jeweler? Try this:

gem install jeweler
jeweler --help
jeweler --rspec --summary "My awesome gem, which solves problems"
--description "The awesome gem" awesome
cd awesome
rake -T
rake spec # write a real spec
rake version:write
rake install

See the Jeweler docs for more:
http://wiki.github.com/technicalpickles/jeweler/

If there are no tutorials, maybe I could ask for your help in setting it up
> for a gem:
>
> Backgrounder
> I'm asking because it's a bit frustrating doing things by trial and error.
> A lot of the problems I've come across were that the files that rspec-rails
> loads for me aren't automatically available in the gem, so I have to
> manually include it. It became a problem when I had to test an ActiveRecord
> model, and worse when I had to test a controller. Currently, I'm stuck at
> the point where "get", "put", "post", "delete" aren't available in the spec.
> I asked about it in StackOverflow and got the answer<http://stackoverflow.com/questions/2543885/why-dont-rspecs-methods-get-post-put-delete-work-in-a-controller-sp>,
> but it doesn't explain what I have to do to basically replicate those
> methods.
>
> What did I do?
> As part of my trial and error process, I started including what rspec-rails
> includes
> http://github.com/dchelimsky/rspec-rails/blob/master/lib/spec/rails.rb,
> and the REST actions don't seem to trigger an undefined error anymore, but
> now there's another "uninitialized constant Rails". So.. before I go
> further, maybe I'm approaching this wrong since I'm having such a difficult
> time.
>
> What's the best way to go about this? Is there a way to maybe include Rails
> and everything it has, for testing purposes? I know that you're supposed to
> make gems framework agnostic but for brevity's sake (and for my own sanity)
> I'm willing to make it very plugin-like for now. I've been reading and
> researching for 3 days you see :)
>
>
I'm not sure what your gem does, but if it has dependencies on Rails, the
easiest way to develop it (in my experience) is to have a separate Rails app
that _uses_ your gem, and that is not part of the gem's source code. Then
that Rails app could have specs (and maybe Cucumber features) that rely on
the correct implementation of your gem.

Maybe you could say a little more about what your gem does?

Aslak


> Thanks, and I apologize for the novel!
> Ramon Tayag
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100330/2313d7bc/attachment-0001.html>


More information about the rspec-users mailing list