Hi Don, This is a very good question. In theory you should be able to mock all dependencies and write a test that checks your logic in isolation. Or load some Hobo classes and use them to test your code against. In practice, I believe this is going to take a long time.
I suggest you include a complete Hobo test app in your gem's source code, and add the sqlite file to the gitignore. Then in the gemspec exclude this directory (I think the "files" attribute should help you with that). This way: * People using the gem don't have to download all the innecesary files. * Other developers who want to edit the gem will clone the repository inclusing the test app, run "rake db:setup" and the execute the tests easily. Hobo's integration tests also depend on a Rails app. It's not perfect, but it works :). Warm regards, Ignacio El 13/09/14 a las #4, Donald Ziesig escribió: > Hi All, > > In my last post (about hobo generate controller) I mentioned that I am > trying to write the tests for a gem that I would like to publish. This > gem requires a hobo controller with an associated model to work. The > gem itself is not very big (approximately 100 loc for the gem-specific > code) but uses a lot of the hobo environment. > > I need to test that: > > 1) It works as advertised (with many options and possible errors) > 2) It works with subsites (e.g.,admin) as well as the base site. > 3) it detects if the controller does not have an associated model > 4) it detects if the controller is not a hobo controller. > > I have tested all of these conditions from within a test app (and a git > branch of one of the eventual production apps) and they pass with flying > colors. > > Now I want to include these tests in the gem itself, but it looks like I > have to include virtually a full hobo app as a part of the gem. The > additional code and data will make the gem hundreds of times bigger. > Does anyone know of a better way than copying most of the test app > (including its sqlite db) into the gem? > > The test environment has several controllers that look something like this: > > class HoboController < ApplicationController > > hobo_model_controller > > auto_actions :all > > include TheGem > > def index > > # needs a set of test values in params and session and > # a pre-populated data set (fixture) which will be > # set up prior to calling index from the test framework. > > invoke_the_gem( self, # needs the controller as modified by > hobo_model_controller. > # this is the hard part. > arg1, # a number > 0 (easy) > arg2, # a string with one or more column names, > or an array of strings > # or an array of symbols (not hard, but many possible > variations) > arg3, # same as arg2 > :column_name, :another_column, ... :last_column ) > > # check the rendered data for various conditions such as presence or > absence of certain rows > # and columns, the order of the data in the columns, the number of rows > displayed on the page. > # which will be checked after index returns to the test framework. > > end > > end > > > Thanks, > > Don Ziesig > -- You received this message because you are subscribed to the Google Groups "Hobo Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/hobousers. For more options, visit https://groups.google.com/d/optout.
