# How do I test this?

**URL:** <https://www.ruby-forum.com/t/how-do-i-test-this/116605>\
**Category:** Rails\
**Created:** [October 7, 2007, 10:42pm UTC](https://www.ruby-forum.com/t/how-do-i-test-this/116605 "2007-10-07T22:42:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [October 7, 2007, 10:42pm UTC](https://www.ruby-forum.com/t/how-do-i-test-this/116605/1 "2007-10-07T22:42:39Z")

</div>

I have this code in my controller which streams a file to the client.  
How on earth do I test this?

#Stream the file to the client over HTTP  
def preview  
device\_id=params[:device\_id]

```
  path = @campaign.get_preview_url(device_id)

  #THE CONTENT TYPE IS REQUIRED!
  ext=File.extname(file_name)

  if ext == ".3gp"
      m_type="video/3gpp"
  elsif ext == ".3g2"
      m_type="video/3gpp2"
  elsif ext ==".mp4"
      m_type="video/mp4"
  end

  send_file path, :disposition => 'inline', :type => m_type

```

end

---

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [October 8, 2007, 7:06am UTC](https://www.ruby-forum.com/t/how-do-i-test-this/116605/2 "2007-10-08T07:06:50Z")

</div>

Hye Eggie,  
what’s that @campaign object contain?, if it’s your server, then you  
have to just write one mock server,

and i am assuming this code is in some controller.,

def test\_preview\_for\_3gp  
get :preview, :device\_id =\> test\_device # send what ever you  
want.  
assert\_response :success  
assert\_not\_nil @response.headers[“Content-Type”].index(‘video/  
3gpp’) # write different set of Functional TestCases for your if/else  
ladder.

```
  expected_file_name = "/tmp/test.3gpp"
  assert_equal expected_file_name, assigns(:path) # i just

```

assumed the path variable can be made instance variable.

```
  assert_not_nil @response
  assert_kind_of String, @response.body # i don't know what put

```

in place of String here, if you do some google you may get some idea.  
Sorry, here  
end

and one more thing is you can add some more assertions provided if you  
know what’s the 3gp format, so if you want your FT’s(Functional-Test-  
Cases) to  
cover even the content delivered, then you have to parse the 3gp  
file(or find any equivalent Ruby class, [i don’t know any such class])  
and write assertions  
for response.body to contain like header, tags etc. of 3gp format.

I guess it helps you, sorry if not.

Good Luck,
