Joshua Muheim
2007-Mar-26 21:57 UTC
Testing a plugin: Having to require plugin files manually?
Hi all
I have written the following small plugin:
# init.rb
require File.dirname(__FILE__) + ''/lib/hash''
# lib/hash.rb
class Hash
def except(*keys)
self.reject { |k,v|
keys.include? k.to_sym
}
end
def only(*keys)
self.dup.reject { |k,v|
!keys.include? k.to_sym
}
end
end
Then I wanted to add a test:
# test/hash_test.rb
require ''test/unit''
class HashTest < Test::Unit::TestCase
def test_hash_should_respond_to_except
assert({}.respond_to?(:except))
end
def test_hash_should_respond_to_only
assert({}.respond_to?(:only))
end
end
When running it from the plugin directory I get the following errors:
Loaded suite
/usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake/rake_test_loader
Started
FF
Finished in 0.034015 seconds.
1) Failure:
test_hash_should_respond_to_except(HashTest) [./test/hash_test.rb:5]:
<false> is not true.
2) Failure:
test_hash_should_respond_to_only(HashTest) [./test/hash_test.rb:9]:
<false> is not true.
2 tests, 2 assertions, 2 failures, 0 errors
rake aborted!
Command failed with status (1): [/usr/bin/ruby -Ilib:lib
"/usr/lib/ruby/gem...]
(See full trace by running task with --trace)
This seems like the plugins files are *not* automatically required by
the testing framework. Do I have to require them myself within the test
file?
Thanks
Josh
--
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
-~----------~----~----~----~------~----~------~--~---
Raymond O''Connor
2007-Aug-16 03:54 UTC
Re: Testing a plugin: Having to require plugin files manuall
Im curious about this too. If you do have to require them manually, is there an easy way to do it? I''ve tried requiring just the init.rb file and it doesn''t seem to do the trick -- 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 -~----------~----~----~----~------~----~------~--~---
James Adam
2007-Aug-16 10:56 UTC
Re: Testing a plugin: Having to require plugin files manuall
On Aug 16, 4:54 am, Raymond O''Connor <rails-mailing-l...@andreas- s.net> wrote:> Im curious about this too. If you do have to require them manually, is > there an easy way to do it? I''ve tried requiring just the init.rb file > and it doesn''t seem to do the trick > -- > Posted viahttp://www.ruby-forum.com/.Plugins are normally loaded in the test environment, so there''s something more subtle going on here. To help understand what''s going on, it might be worth your while adding a "puts ''loading my hash plugin" at the top of your init.rb, and noting whether or not (or indeed, when) it gets loaded. Additionally, how are you running the plugin tests? Via "rake test:plugins"? However you are doing it, you need to be sure that the Rails environment is being loaded first. Try adding the following line to your plugin''s "test/hash_test.rb" file: require File.join(File.dirname(__FILE__), "..", "..", "..", "test", "test_helper") I might''ve got the number of ".."''s wrong there, but basically the idea is to load Rails'' test/test_helper.rb file. This will then ensure that the Rails environment is loaded, and your plugin will get loaded as you''d expect. HTH, -- James --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---