Hello list, I''m having problems with the following integration test (tests for the authentication aspects of the application): require "#{File.dirname(__FILE__)}/../test_helper" class AuthenticationTest < ActionController::IntegrationTest # fixtures :your, :models def test_successful_login george = enter_site(:george) end module BrowsingTestDSL include ERB::Util attr_writer :name def tries_to_go_to_admin get "/admin/book/new" assert_response :redirect assert_redirected_to "/account/login" end def enter_site(name) open_session do |session| session.extend(BrowsingTestDSL) session.name = name yield session if block_given? end end end end When I run this test, rails tell me test_site() is undefined, however, I''ve declared it inside the private module (I''m using the module to implement this test''s DSL, as seen in the book Beginning Ruby on Rails E-Commerce from Apress). Here''s the output: "Loaded suite test/integration/authentication_test Started E Finished in 0.312 seconds. 1) Error: test_successful_login(AuthenticationTest): NoMethodError: undefined method `enter_site'' for #<ActionController::Integration::Session:0x4751620> c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/test_process.rb:452:in `meod_missing'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/integration.rb:547:in `sen c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/integration.rb:547:in `metd_missing'' test/integration/authentication_test.rb:7:in `test_successful_login'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/integration.rb:453:in `run 1 tests, 0 assertions, 0 failures, 1 errors" What am I doing wrong ? Thanks in advance, Marcelo. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2007-Aug-19 18:16 UTC
Re: method undefined in integration test
Hi -- On Sun, 19 Aug 2007, Marcelo de Moraes Serpa wrote:> Hello list, > > I''m having problems with the following integration test (tests for the > authentication aspects of the application): > > require "#{File.dirname(__FILE__)}/../test_helper" > > class AuthenticationTest < ActionController::IntegrationTest > # fixtures :your, :models > > def test_successful_login > george = enter_site(:george) > > > end > > > > module BrowsingTestDSL > include ERB::Util > attr_writer :name > > def tries_to_go_to_admin > get "/admin/book/new" > assert_response :redirect > assert_redirected_to "/account/login" > end > > def enter_site(name) > open_session do |session| > session.extend(BrowsingTestDSL) > session.name = name > yield session if block_given? > end > > > > end > > > end > > end > > When I run this test, rails tell me test_site() is undefined, however, I''ve > declared it inside the private module (I''m using the module to implement > this test''s DSL, as seen in the book Beginning Ruby on Rails E-Commerce from > Apress). > > Here''s the output: > > "Loaded suite test/integration/authentication_test > Started > E > Finished in 0.312 seconds. > 1) Error: > test_successful_login(AuthenticationTest): > NoMethodError: undefined method `enter_site'' for > #<ActionController::Integration::Session:0x4751620> > c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/test_process.rb:452:in > `meod_missing'' > c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/integration.rb:547:in > `sen > c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/integration.rb:547:in > `metd_missing'' > test/integration/authentication_test.rb:7:in `test_successful_login'' > c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/integration.rb:453:in > `run > 1 tests, 0 assertions, 0 failures, 1 errors" > > What am I doing wrong ?Your module isn''t included (in the sense of "include ModuleName") in your class. So instances of your class do not have the module in their method lookup path. Here''s a very small version, with the include instruction added: class C def x y end module M def y puts "hi" end end include M # This is the key line end The fact that the module is nested in the class doesn''t matter; it''s still just a module (C::M in my case), and it has to be included in any class that wants its objects to have access to it. David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.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 -~----------~----~----~----~------~----~------~--~---