# Expanding tests with own methods

**URL:** <https://www.ruby-forum.com/t/expanding-tests-with-own-methods/193009>\
**Category:** Rails\
**Created:** [August 9, 2010, 11:41pm UTC](https://www.ruby-forum.com/t/expanding-tests-with-own-methods/193009 "2010-08-09T23:41:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f4b2a3/32.png) [@jimb](https://www.ruby-forum.com/u/jimb)\
**Post date:** [August 9, 2010, 11:41pm UTC](https://www.ruby-forum.com/t/expanding-tests-with-own-methods/193009/1 "2010-08-09T23:41:38Z")

</div>

I want to call the method ‘url\_for’ in my functional test.  
e.g. assert\_select “a[href=?]”, url\_for(:action =\> :new), :text =\> ‘Neue  
Seite’

The book I am reading suggests doing this:

class PagesControllerTest \< ActionController::TestCase  
def setup  
def self.url\_for(options, \*parameters\_for\_method\_reference)  
options.merge! :only\_path =\> true  
@controller.url\_for(options, \*parameters\_for\_method\_reference)  
end  
end  
…  
end

Why is it necessary to define ‘url\_for’ within the definition of the  
‘setup’ method?

Why is it necessary to define ‘url\_for’ using self?

All of my tests run just fine if I define url\_for as a normal instance  
method:

class PagesControllerTest \< ActionController::TestCase  
def url\_for(options, \*parameters\_for\_method\_reference)  
options.merge! :only\_path =\> true  
@controller.url\_for(options, \*parameters\_for\_method\_reference)  
end  
def test\_create\_link\_in\_index  
get :index  
assert\_select “a[href=?]”, url\_for(:action =\> :new), :text =\> ‘Neue  
Seite’  
end  
…  
end

Thanks in advance.
