# Testing with before\_filter

**URL:** <https://www.ruby-forum.com/t/testing-with-before-filter/172555>\
**Category:** Rails\
**Created:** [July 23, 2009, 9:25am UTC](https://www.ruby-forum.com/t/testing-with-before-filter/172555 "2009-07-23T09:25:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![axyd80](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/82dd89/32.png) [@axyd80](https://www.ruby-forum.com/u/axyd80)\
**Post date:** [July 23, 2009, 9:25am UTC](https://www.ruby-forum.com/t/testing-with-before-filter/172555/1 "2009-07-23T09:25:36Z")

</div>

Hi all  
i’ve developed before\_filter - [locale filter · GitHub](http://gist.github.com/138659) and in  
tests like  
test “should get index” do  
get :index  
assert\_response :success  
assert\_not\_nil assigns(:articles)  
end

i see  
test\_should\_get\_index(ArticlesControllerTest):  
NoMethodError: You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.split  
app/controllers/application\_controller.rb:20:in `set_locale' /test/functional/articles_controller_test.rb:5:in `test\_should\_get\_index’

When i’ve added  
setup do  
@request.headers[‘HTTP\_ACCEPT\_LANGUAGE’] = “en”  
end

nothing changed ☹ Could you tell me plz - whats wrong?

Rails 2.3.2, Ruby 1.8

---

<div class="post-metadata">

**Author:** ![axyd80](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/82dd89/32.png) [@axyd80](https://www.ruby-forum.com/u/axyd80)\
**Post date:** [July 23, 2009, 3:05pm UTC](https://www.ruby-forum.com/t/testing-with-before-filter/172555/2 "2009-07-23T15:05:40Z")

</div>

I’ve solved this issue with  
@request.env[‘HOST’] = “[somesite.com](http://somesite.com)”  
@request.env[‘HTTP\_ACCEPT\_LANGUAGE’] = “en”

Alexey Poimtsev wrote:

> Hi all  
> i’ve developed before\_filter - [locale filter · GitHub](http://gist.github.com/138659) and in  
> tests like  
> test “should get index” do  
> get :index  
> assert\_response :success  
> assert\_not\_nil assigns(:articles)  
> end
> 
> i see  
> test\_should\_get\_index(ArticlesControllerTest):  
> NoMethodError: You have a nil object when you didn’t expect it!  
> You might have expected an instance of Array.  
> The error occurred while evaluating nil.split  
> app/controllers/application\_controller.rb:20:in `set_locale' /test/functional/articles_controller_test.rb:5:in `test\_should\_get\_index’
> 
> When i’ve added  
> setup do  
> @request.headers[‘HTTP\_ACCEPT\_LANGUAGE’] = “en”  
> end
> 
> nothing changed ☹ Could you tell me plz - whats wrong?
> 
> Rails 2.3.2, Ruby 1.8
