Hello guys!
I'm posting here since I've tried many solutions on internet, without success.
I've written a Sinatra app and everything seems to be working well on browser.
However, when I run my unit tests, they always return status 404
Here are some informations about my code:
[user_controller.rb]
require 'sinatra'
require 'sinatra/base'
# Matches: /users
class UserController < Sinatra::Base
get '/' do
"Hello User"
end
end
[service_controller.rb]
require 'sinatra'
require 'sinatra/base'
# Matches: /services
class ServiceController < Sinatra::Base
get '/' do
"Hello Service"
end
end
$:.unshift(File.dirname(__FILE__))
Dir.glob('./app/{controllers,helpers}/*.rb').each { |file| require file }
#
# Mapping routes
#
map('/users') { run UserController }
map('/services') { run ServiceController }
So, I run the whole environment like this:
/usr/local/bin/foreman start -d .
My test setup:
[test_helper.rb]
ENV['RACK_ENV'] = 'test'
require 'test/unit'
require 'rack/test'
[user_controller_test.rb]
require File.expand_path '../../test_helper.rb', __FILE__
require_relative "../../controllers/user_controller"
class UserControllerTest < Test::Unit::TestCase
include Rack::Test::Methods
def app
Sinatra::Application
end
def test_user
get '/'
assert_equal 200, last_response.status
end
When I run 'rake', the test above returns 404.
PS: I've simplified the code, since is a lot o things. So, this is in essence my problem.
Maybe there is some error running tests since I've a
config.ru file connectin the whole thing.
Hope you guys can help me.
Thanks in advance! :)