title: Converting to modular sinatra app breaks tests
body: <p>I've modularised by classic sinatra app and moved my routes in my sinatra app into individual routes files as per <a href="https://stackoverflow.com/a/5030173/111884">https://stackoverflow.com/a/5030173/111884</a>, however, I can't seem to get my tests working.</p>
  
  <p>This is what my files look like:</p>
  
  <p>./web.rb</p>
  
  
  
  <pre class="lang-rb prettyprint-override"><code>require 'sinatra'
  require 'sinatra/flash'
  
  class MyApp &lt; Sinatra::Application
    # ...
  end
  
  require_relative 'models/init'
  require_relative 'helpers/init'
  require_relative 'routes/init'
  </code></pre>
  
  <p>./routes/init.rb</p>
  
  <pre class="lang-rb prettyprint-override"><code>require_relative 'main'
  </code></pre>
  
  <p>./routes/main.rb</p>
  
  <pre class="lang-rb prettyprint-override"><code># The main routes for the core of the app
  class MyApp &lt; Sinatra::Application
    get '/' do
      erb :main
    end
  end
  </code></pre>
  
  <p>./spec/spec_helper.rb</p>
  
  <pre class="lang-rb prettyprint-override"><code>ENV['RACK_ENV'] = 'test'
  require 'minitest/autorun'
  require 'rack/test'
  require 'factory_girl'
  
  # Include factories.rb file
  begin
    require_relative '../test/factories.rb'
  rescue NameError 
    require File.expand_path('../test/factories.rb', __FILE__)
  end
  
  # Include web.rb file
  begin
    require_relative '../web'
  rescue NameError 
    require File.expand_path('../web', __FILE__)
  end
  </code></pre>
  
  <p>./spec/web_spec.rb</p>
  
  <pre class="lang-rb prettyprint-override"><code>begin 
    require_relative 'spec_helper'
  rescue NameError
    require File.expand_path('spec_helper', __FILE__)
  end
  
  include Rack::Test::Methods
  
  def app() Sinatra::Base end
  
  describe "Some test" do
    # ...
  end
  </code></pre>
  
  <p>Rakefile</p>
  
  <pre class="lang-rb prettyprint-override"><code># Test rake tasks
  require 'rake/testtask'
  Rake::TestTask.new do |t|
    t.libs &lt;&lt; "test"
    t.libs &lt;&lt; "spec"
    t.test_files = FileList['test/factories.rb', 'test/test_*.rb', 'spec/spec_helper.rb', 'spec/**/*_spec.rb']
    t.verbose = true
  end
  </code></pre>
  
  <p>The output of the tests is:</p>
  
  <pre class="lang-rb prettyprint-override"><code>&lt;h1&gt;Not Found&lt;/h1&gt;
  </code></pre>
  
  <p>It doesn't seem to be loading the <code>./routes/*.rb</code> files.</p>
  
  <p>I'm using <code>Sinatra::Application</code>, instead of <code>Sinatra::Base</code>, but <a href="https://stackoverflow.com/a/5030173/111884">https://stackoverflow.com/a/5030173/111884</a> uses it. It also references it here <a href="http://www.sinatrarb.com/extensions.html" rel="nofollow noreferrer">http://www.sinatrarb.com/extensions.html</a>. I have tried changing it to use <code>Sinatra::Base</code>, but it didn't fix it.</p>
  
  <p>I've also tried <a href="https://stackoverflow.com/questions/7095217/sinatra-tests-always-404ing">Sinatra tests always 404&#39;ing</a> and <a href="https://stackoverflow.com/questions/2480607/using-cucumber-with-modular-sinatra-apps">Using Cucumber With Modular Sinatra Apps</a>, but they don't work.</p>