Guys, I''ve created a plugin, i wanna put my automated test there. However, I got bad file descriptor error when i run the test like normal unit test file: "ruby plugins/acts_as_fox/test/acts_as_fox_test.rb" How to test a plugin? Also, is it right to say that I should only put my unit tests (but not functional test for example) for the plugin in the plugin test folder? <code for acts_as_fox_test.rb> require File.join(File.dirname(__FILE__), ''test_helper'') require ''test/unit'' class ActsAsTripTest < Test::Unit::TestCase # Replace this with your real tests. def test_this_plugin flunk end end </code> <code for test_helper.rb> plugin_test_dir = File.dirname(__FILE__) require File.join(plugin_test_dir, ''/test_helper'') # Load the Rails environment require File.join(plugin_test_dir, ''../../../../config/environment'') require ''active_record/fixtures'' # Load up out database & create our logger databases = YAML::load(IO.read(plugin_test_dir + ''/database.yml'')) ActiveRecord::Base.logger = Logger.new(plugin_test_dir + "/debug.log") # Connect to our plugin test database ActiveRecord::Base.establish_connection(databases[ENV[''DB''] || ''mysql'']) # Load the test schema into the database load(File.join(plugin_test_dir, ''schema.rb'')) # Load fixtures for the plugin Test::Unit::TestCase.fixture_path = File.join(plugin_test_dir, ''fixtures/'') </code> Thanks much! Arthur -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 3, 9:13 am, Arthur Chan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Guys, > > I''ve created a plugin, i wanna put my automated test there. > > However, I got bad file descriptor error when i run the test like normal > unit test file: > "ruby plugins/acts_as_fox/test/acts_as_fox_test.rb" > > How to test a plugin? >Well what I do is based on a skeleton plugin I have here: http://github.com/fcheung/ar_plugin_skeleton/tree/master It doesn''t do functional tests but that''s basically a case of adding require ''action_controller/test_case'' require ''action_controller/test_process'' ActionController::Routing::Routes.draw do |map| # Install the default route as the lowest priority. map.connect '':controller/:action/:id'' end ActionController::Base.view_paths = [Test::Unit::TestCase.fixture_path + ''views/''] to the test helper file Fred> Also, is it right to say that I should only put my unit tests (but not > functional test for example) for the plugin in the plugin test folder? > > <code for acts_as_fox_test.rb> > > require File.join(File.dirname(__FILE__), ''test_helper'') > > require ''test/unit'' > > class ActsAsTripTest < Test::Unit::TestCase > # Replace this with your real tests. > def test_this_plugin > flunk > end > end > > </code> > > <code for test_helper.rb> > plugin_test_dir = File.dirname(__FILE__) > require File.join(plugin_test_dir, ''/test_helper'') > > # Load the Rails environment > require File.join(plugin_test_dir, ''../../../../config/environment'') > require ''active_record/fixtures'' > > # Load up out database & create our logger > databases = YAML::load(IO.read(plugin_test_dir + ''/database.yml'')) > ActiveRecord::Base.logger = Logger.new(plugin_test_dir + "/debug.log") > > # Connect to our plugin test database > ActiveRecord::Base.establish_connection(databases[ENV[''DB''] || ''mysql'']) > > # Load the test schema into the database > load(File.join(plugin_test_dir, ''schema.rb'')) > > # Load fixtures for the plugin > Test::Unit::TestCase.fixture_path = File.join(plugin_test_dir, > ''fixtures/'') > </code> > > Thanks much! > > Arthur > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks Fred. It seems that the ar_plugin_skeleton is what I needed. Thanks, Arthur Frederick Cheung wrote:> On Dec 3, 9:13�am, Arthur Chan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> Guys, >> >> I''ve created a plugin, i wanna put my automated test there. >> >> However, I got bad file descriptor error when i run the test like normal >> unit test file: >> "ruby plugins/acts_as_fox/test/acts_as_fox_test.rb" >> >> How to test a plugin? >> > Well what I do is based on a skeleton plugin I have here: > http://github.com/fcheung/ar_plugin_skeleton/tree/master > > It doesn''t do functional tests but that''s basically a case of adding > > require ''action_controller/test_case'' > require ''action_controller/test_process'' > > ActionController::Routing::Routes.draw do |map| > # Install the default route as the lowest priority. > map.connect '':controller/:action/:id'' > end > ActionController::Base.view_paths = [Test::Unit::TestCase.fixture_path > + ''views/''] > > to the test helper file > > Fred-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I can run functional test now, thanks!! A problem I found in running the test is that it does not load the route.rb so that it fails in some action --- e.g. assets_path/_url not defined. Any clue to it is appreciated. Arthur Arthur Chan wrote:> Thanks Fred. > > It seems that the ar_plugin_skeleton is what I needed. > > Thanks, > Arthur > > Frederick Cheung wrote: >> On Dec 3, 9:13�am, Arthur Chan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> >> wrote: >>> Guys, >>> >>> I''ve created a plugin, i wanna put my automated test there. >>> >>> However, I got bad file descriptor error when i run the test like normal >>> unit test file: >>> "ruby plugins/acts_as_fox/test/acts_as_fox_test.rb" >>> >>> How to test a plugin? >>> >> Well what I do is based on a skeleton plugin I have here: >> http://github.com/fcheung/ar_plugin_skeleton/tree/master >> >> It doesn''t do functional tests but that''s basically a case of adding >> >> require ''action_controller/test_case'' >> require ''action_controller/test_process'' >> >> ActionController::Routing::Routes.draw do |map| >> # Install the default route as the lowest priority. >> map.connect '':controller/:action/:id'' >> end >> ActionController::Base.view_paths = [Test::Unit::TestCase.fixture_path >> + ''views/''] >> >> to the test helper file >> >> Fred-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 6, 7:41 am, Arthur Chan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I can run functional test now, thanks!! > > A problem I found in running the test is that it does not load the > route.rb so that it fails in some action --- e.g. assets_path/_url not > defined. > > Any clue to it is appreciated. >You need to define any routes needed in the ActionController::Routing::Routes.draw block in test_helper.rb Fred> Arthur > > > > Arthur Chan wrote: > > Thanks Fred. > > > It seems that the ar_plugin_skeleton is what I needed. > > > Thanks, > > Arthur > > > Frederick Cheung wrote: > >> On Dec 3, 9:13 am, Arthur Chan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > >> wrote: > >>> Guys, > > >>> I''ve created a plugin, i wanna put my automated test there. > > >>> However, I got bad file descriptor error when i run the test like normal > >>> unit test file: > >>> "ruby plugins/acts_as_fox/test/acts_as_fox_test.rb" > > >>> How to test a plugin? > > >> Well what I do is based on a skeleton plugin I have here: > >>http://github.com/fcheung/ar_plugin_skeleton/tree/master > > >> It doesn''t do functional tests but that''s basically a case of adding > > >> require ''action_controller/test_case'' > >> require ''action_controller/test_process'' > > >> ActionController::Routing::Routes.draw do |map| > >> # Install the default route as the lowest priority. > >> map.connect '':controller/:action/:id'' > >> end > >> ActionController::Base.view_paths = [Test::Unit::TestCase.fixture_path > >> + ''views/''] > > >> to the test helper file > > >> Fred > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Wow, Awesome, it works now. Thanks for the quick and useful help. Arthur Frederick Cheung wrote:> On Jan 6, 7:41�am, Arthur Chan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> I can run functional test now, thanks!! >> >> A problem I found in running the test is that it does not load the >> route.rb so that it fails in some action --- e.g. assets_path/_url not >> defined. >> >> Any clue to it is appreciated. >> > You need to define any routes needed in the > ActionController::Routing::Routes.draw block in test_helper.rb > > Fred-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---