Any rails experts able to offer some advice?

Hello all.

#1 I am working on a rails3 gem called Yarder (https://github.com/rurounijones/yarder). The goal of this gem is to replace the rails logging system with one that is JSON based rather than string based.

#2 To this end I also recently asked this list about making the LogSubscribers subscriptions to ActiveRecord::Notifications configurable and am looking at submitting a patch request.

However for both of these I have rather run into a brick wall.

#1 Yarder works (mostly, I have not finished or refactored and there are probably bugs) but it has no tests. The reasons for this is that I cannot get my head around how to test it (and how to set up the tests in the first place ) and there aren't examples of this kind of stuff online that I can see (rails own LogSubscriber tests use a lot of support files specific to the rails gems which makes using them as a base less than obvious)

#2 For this I am just not exactly sure how to start (Both dev and test)

I have spent the last week or so looking through the rails code-base and testing setup to try and grok how to do the above but it is beyond me at the moment.

I don't suppose there is a altruistic rails expert out there who is willing to spare some time (email, skype, whatever suits you best) to help me get my head around the rails internals (mainly the boot process and what to change for #2 plus setting up the tests) and how to test #1.

Regards,

Jeff Jones

I am not an expert here, but maybe these instrumentation tests give
some directions:
https://github.com/roidrage/lograge/blob/master/spec/lograge_logsubscriber_spec.rb

BR,

Patrick

Not an expert, but since I have been kind of slack on testing recently, I’ll try to get some karma by trying to help. First, you may want to ask on this list instead/too:
https://groups.google.com/forum/?fromgroups=#!forum/rubyonrails-talk
(Stackoverflow is also a good place to get Rails stuff answered for more specific questions.)

This was the thing for Rails 3.0:
https://github.com/josevalim/enginex

After that it became:
rails plugin new

In: http://guides.rubyonrails.org/plugins.html

1.2 Or generate a gemified plugin.
Writing your Rails plugin as a gem, rather than as a vendored plugin, lets you share your plugin across different rails applications using RubyGems and Bundler.
Rails 3.1 ships with a rails plugin new command which creates a skeleton for developing any kind of Rails extension with the ability to run integration tests using a dummy Rails application. See usage and options by asking for help:
$ rails plugin --help

This looks like it might help:
http://namick.tumblr.com/post/17663752365/how-to-create-a-gemified-plugin-with-rails-3-2-rspec

Rails initialization guide since you mentioned wanting to know the boot process, but sounds like you don’t need it:
http://guides.rubyonrails.org/initialization.html

Hi Patrick

That is very useful because it shows another way of testing things. I am not entirely sure I like it because it is faking the creation of the events rather than using the actual rails code to create the, but it is certainly something worth considering if I cannot break the wall.

Cheers

Jeff

Ahoi Gary

Thanks for the info but the gem has already been created and the

testing I want to do is not obvious (to my mind anyway) so online
“Getting started” style stuff that I have found is not that useful…

This is why I was asking if an expert can offer some time to answer

specific questions I have and help my get my head around it.

On a site-note by hacking around I seem to have got the

LogSubscriber tests working, still no idea on how to do the rack
logger tests though.

Cheers

Jeff

When I have problems isolating behavior in tests, sometimes it can be useful to test more rather than less. If you are testing log output, use a dummy rails app inside of your test suite with dummy controller actions and hit it as a user would with capybara. Then you could route logs to stdout or a custom log object, or simply parse the log file in log/ to verify the correct strings are being written. While not as helpful for development as unit tests, this type of end-to-end testing is great for protecting against regressions and bugs.

Hello Richard.

That makes sense, and it is the route I am looking at, but how does

one boot the dummy app and access it using (for example) capybara?

Most information and repositories I have seen online do unit testing

against the dummy app; I have not found any information on how to do
full integration tests against the dummy app.

I am suer I must be missing something obvious or have managed to

miss an obvious example repository to look at but I am not sure what
(Hence the missing it in the first place)

cheer

Jeff

Check out https://github.com/schneems/wicked all of the tests are integration tests with capybara. If something is going to break it is going to break in a way the user would see it. You can see a variety of mixed unit/controller/integration tests in my OAuth provider gem https://github.com/opro/opro.

You get a dummy Rails app for free when you initialize a new project using https://github.com/josevalim/enginex, I haven’t tried with rails plugin new but I would expect you get something similar. This article should have some info on testing for you: http://coding.smashingmagazine.com/2011/06/23/a-guide-to-starting-your-own-rails-engine-gem/ but it is a bit dated.

You can just run “rails plugin new” which gives you a dummy app and them install cucumber on the dummy app as you would on a normal app, and go from there. The dummy app should behave exactly as a normal app which loads your engine/gem.

Hi Richard (and Luis in the reply below),

Excellent, I knew there must have been a reopsitory out there with

good samples to work off. that looks fantastic.

Thank you very much

Jeff