Hi ! I'm building a plugin, and I'd like to add tests, following Jamis Buck's suggestion. This is my whole Rakefile: require 'rake' require 'rake/testtask' require 'rake/rdoctask' task :default => :test_units desc "Run the unit tests in test/unit" Rake::TestTask.new("test_units") do |t| t.pattern = 'test/unit/**/*_test.rb' t.verbose = true end I copied bits and pieces from the Rails 0.14.2 and Rails 0.13.1 Rakefiles, but when I run the test_units task, my tests don't run. For example, this is one of my tests: require 'test/unit/testcase' require 'francois_beausoleil/flash_plugin_helper/application' class ApplicationTest < Test::Unit::TestCase def test_nothing flunk end end puts "ApplicationTest finishing..." Even though I flunk the test, nothing happens. The rake test_units task finishes happily. So, what am I missing ? I know this is not Rails specific, but since this is for a plugin... Thanks ! -- François Beausoleil http://blog.teksol.info/ _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
I''d like to read more information about this same topic. Hopefully some more plugin development documentation will appear soon. Right now I''m testing my plugin using the main unit tests for my Rails application because it is so convienent. However the results of rails script/generate plugin acts_as_fox hints that testing the plugin directly is the right way to go. Still seems like a struggle for me. -Peter On 11/4/05, Francois Beausoleil <francois.beausoleil-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi ! > > I''m building a plugin, and I''d like to add tests, following Jamis > Buck''s suggestion. > > This is my whole Rakefile: > require ''rake'' > require ''rake/testtask'' > require ''rake/rdoctask'' > > task :default => :test_units > > desc "Run the unit tests in test/unit" > Rake::TestTask.new("test_units") do |t| > t.pattern = ''test/unit/**/*_test.rb'' > t.verbose = true > end > > I copied bits and pieces from the Rails 0.14.2 and Rails 0.13.1 > Rakefiles, but when I run the test_units task, my tests don''t run. > For example, this is one of my tests: > require ''test/unit/testcase'' > require ''francois_beausoleil/flash_plugin_helper/application'' > > class ApplicationTest < Test::Unit::TestCase > def test_nothing > flunk > end > end > > puts "ApplicationTest finishing..." > > Even though I flunk the test, nothing happens. The rake test_units > task finishes happily. > > So, what am I missing ? I know this is not Rails specific, but since > this is for a plugin... > > Thanks ! > -- > François Beausoleil > http://blog.teksol.info/ > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Julian ''Julik'' Tarkhanov
2005-Nov-09 14:55 UTC
Re: [OT - slightly] How to run plugin tests ?
Maybe it could be possible to allow plugin tests to be run in the same context where Rails'' tests run? So that the plugin would get access to the sample data (with customers etc.) as well as controllers. -- Julian "Julik" Tarkhanov
There is a task in 0.14.3 which does this, sort of: rake test_plugins Your plugin should have a test/ directory as normal, and it might be a good idea to set up a test_helper in there to point to the right fixtures, etc. For the LoginEngine (which is still a plugin, mind), I''ve got the following: require File.dirname(__FILE__) + ''/../../../../test/test_helper'' # the default rails helper # TODO: Add check for database-specific sql files instead load(File.dirname(__FILE__) + "/../db/schema.rb") Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/" $LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path) require File.dirname(__FILE__) + ''/mocks/time'' require File.dirname(__FILE__) + ''/mocks/mail'' ... and each test_ file having: require File.dirname(__FILE__) + ''/../test_helper'' # the plugin''s own test_helper That might be a reasonable starting point.... - james On 11/9/05, Julian ''Julik'' Tarkhanov <listbox-RY+snkucC20@public.gmane.org> wrote:> Maybe it could be possible to allow plugin tests to be run in the > same context where Rails'' tests run? So that the plugin would get > access to the sample data (with customers etc.) as well as controllers. > > > -- > Julian "Julik" Tarkhanov > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Hi ! 2005/11/9, James Adam <james.adam@gmail.com>:> rake test_plugins > > Your plugin should have a test/ directory as normal, and it might be a > good idea to set up a test_helper in there to point to the right > fixtures, etc.Yes, but what about plugins that don't have models, yada ? Such as the FlashHelperPlugin ? I don't need a full Rails environment to test the plugin. That's overkill. Mind you, if that's the only way I'll be able to test, I'll do it that way. Anyway, thanks for the input ! François _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
If you don''t need models, chances are you don''t need to load the Rails environment. Have a look at the tests in the Engines plugin for an example.... - james On 11/9/05, Francois Beausoleil <francois.beausoleil-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi ! > > 2005/11/9, James Adam <james.adam-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > rake test_plugins > > > > Your plugin should have a test/ directory as normal, and it might be a > > good idea to set up a test_helper in there to point to the right > > fixtures, etc. > > Yes, but what about plugins that don''t have models, yada ? Such as > the FlashHelperPlugin ? I don''t need a full Rails environment to test > the plugin. That''s overkill. Mind you, if that''s the only way I''ll > be able to test, I''ll do it that way. > > Anyway, thanks for the input ! > François > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
What about plugins that interact with things in the Controller like the Flash hash (I''m trying to write an extension to the FlashHelper plugin and I''m having no luck running the tests at all!). Cheers Luke On 11/9/05, James Adam <james.adam-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > If you don''t need models, chances are you don''t need to load the Rails > environment. Have a look at the tests in the Engines plugin for an > example...._______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails