# Method undefined in integration test

**URL:** <https://www.ruby-forum.com/t/method-undefined-in-integration-test/112472>\
**Category:** Rails\
**Created:** [August 19, 2007, 11:09pm UTC](https://www.ruby-forum.com/t/method-undefined-in-integration-test/112472 "2007-08-19T23:09:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhfs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@mhfs](https://www.ruby-forum.com/u/mhfs)\
**Post date:** [August 19, 2007, 11:09pm UTC](https://www.ruby-forum.com/t/method-undefined-in-integration-test/112472/1 "2007-08-19T23:09:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mhfs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@mhfs](https://www.ruby-forum.com/u/mhfs)\
**Post date:** [September 25, 2007, 11:04pm UTC](https://www.ruby-forum.com/t/method-undefined-in-integration-test/112472/2 "2007-09-25T23:04:51Z")

</div>

Hi –

On Sun, 19 Aug 2007, Marcelo de Moraes S. wrote:

> def test\_successful\_login
> 
> ```
> yield session if block_given?
> 
> ```
> 
> Finished in 0.312 seconds.  
> 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](http://www.awprofessional.com/title/0321509242))  
RUBY FOR RAILS ([Ruby for Rails](http://www.manning.com/black))
- Ruby/Rails training  
& consulting: Ruby Power and Light, LLC ([http://www.rubypal.com](http://www.rubypal.com))
