I'm trying to get some unit tests written for a small Sinatra app. When I run ruby test.rb
, the terminal reports that it is "running tests" but it is not actually picking up my unit tests.
The app itself runs fine whether by locally typing ruby app.js
or through phusion passenger, so hopefully that indicates that my config.ru and app.js file are set up properly.
Here is what I have so far.
test.rb
require_relative 'app'
require 'test/unit'
require 'rack/test'
ENV['RACK_ENV'] = 'test'
class AppTest < Test::Unit::TestCase
include Rack::Test::Methods
puts "Debug 1"
def app
puts "Debug 2"
Sinatra::Application
end
def root
get '/'
assert last_response.ok?
end
end
The terminal
$ ruby test.rb
Debug 1
Run options:
# Running tests:
Finished tests in 0.004781s, 0.0000 tests/s, 0.0000 assertions/s.
0 tests, 0 assertions, 0 failures, 0 errors, 0 skips
ruby -v: ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-darwin14.0]
It seems as though "app" and the first test "root" are never being run, since the debug line isn't printed. What have I missed in the test setup? It looks as though I'm mimicking tests from the sinatra recipe / existing apps so I'm not sure what I'm messing up. Thanks!
The test method has to be named test_root
for the test to be run. Otherwise it's just a private method and won't be called unless it's called by an test_
method.