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

Ramon Tayag ramon.tayag at gmail.com
Tue Mar 30 11:22:39 EDT 2010

Thanks for your reply aslak. Since then I've tried another approach - having
a sample Rails application in the spec folder, much like
Still haven't gotten it to work, but I'll try anyway.

If I have a separate Rails app (which sounds MUCH easier to do - thank you),
won't it be slow doing TDD because I'd have to publish my gem, update it in
the Rails app, run tests, then back to the gem source code to make changes?

I wasn't too ambitious with my first gem. It allows subscriptions. The name
"acts_as_subscribable" should be descriptive enough :)

Ramon Tayag

On Tue, Mar 30, 2010 at 7:09 PM, aslak hellesoy <aslak.hellesoy at gmail.com>wrote:

> 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
> _______________________________________________
> 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/cfc0bc43/attachment.html>

More information about the rspec-users mailing list