Peter Michaux
2006-Dec-03 00:23 UTC
Can''t get view helper plugin tests to include the correct Rails core code
Hi,
I have a plugin that adds some view helpers to generate html. The
plugin is small and seems to work fine but I''d like to add some tests.
I''ve tried following some tutorials on the web for making plugin tests
and also looked in some of technoweenie''s plugins to try and figure
this out but I keep getting errors. The problem seems to be trying to
include the correct code from the Rails core.
I''ve tried two version with two similar errors which are listed below.
Any ideas?
Thanks,
Peter
------------------------------------------
The first follows the nubyonrails tutorial[1]
require ''rubygems''
require ''test/unit''
require File.dirname(__FILE__) + ''/../lib/fork_helper''
require ''action_view/helpers/url_helper''
require ''action_view/helpers/javascript_helper''
class ForkTest < Test::Unit::TestCase
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::JavaScriptHelper
include ForkHelper
def test_form_remote_tag
output = fork_form_remote_tag(:url=>''/foo/bar'')
assert_equal ''<form action="/foo/bar"
method="post"
onsubmit="FORK.Ajax.request(\''POST\'',
\''/foo/bar\'');return false;">'',
output
end
end
I see the following error
Error:
test_form_remote_tag(ForkTest):
NoMethodError: undefined method `url_for'' for nil:NilClass
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/helpers/url_helper.rb:27:in
`send''
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/helpers/url_helper.rb:27:in
`url_for''
./test/../lib/fork_helper.rb:32:in `fork_remote_function''
./test/../lib/fork_helper.rb:10:in `fork_form_remote_tag''
./test/fork_test.rb:14:in `test_form_remote_tag''
------------------------------------------
The second version I''ve tried follows what seems to be
technoweenie''s
favorite approach[2]. This technique looks like it loads more than
necessary but that is ok if it is easier to work with.
$:.unshift(File.dirname(__FILE__) + ''/../lib'')
require File.dirname(__FILE__) +
''/../../../../config/environment''
require ''test/unit''
require ''rubygems''
require ''breakpoint''
require ''action_controller/test_process''
ActionController::Base.logger = nil
ActionController::Base.ignore_missing_templates = false
ActionController::Routing::Routes.reload rescue nil
class ForkTest < Test::Unit::TestCase
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::JavaScriptHelper
include ForkHelper
def test_form_remote_tag
output = fork_form_remote_tag(:url=>''/foo/bar'')
assert_equal ''<form action="/foo/bar"
method="post"
onsubmit="FORK.Ajax.request(\''POST\'',
\''/foo/bar\'');return false;">'',
output
end
end
I see the following error
Error:
test_form_remote_tag(ForkTest):
NoMethodError: You have a nil object when you didn''t expect it!
The error occured while evaluating nil.url_for
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/helpers/url_helper.rb:27:in
`url_for''
test/../../../../config/../vendor/plugins/fork/lib/fork_helper.rb:32:in
`fork_remote_function''
test/../../../../config/../vendor/plugins/fork/lib/fork_helper.rb:10:in
`fork_form_remote_tag''
./test/fork_test.rb:28:in `test_form_remote_tag''
----------------------------
[1]
http://nubyonrails.com/articles/2006/05/09/the-complete-guide-to-rails-plugins-part-ii
[2]
http://svn.techno-weenie.net/projects/plugins/labeled_form_helper/test/labeled_form_helper_test.rb
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---