title: Rspec not recognizing tables in Sinatra app
body: <p>I am creating a lightweight app that requires custom routes so I'm using Sinatra over Rails. However, I am using a skeleton that closely mimics Rails functionality, just without having to fight convention at every turn. </p>
  
  <p>The problem is that when I try and run Rspec, it tells me that there is no relation. I keep thinking there must be a pluralization issue, but for the light of me, I can't find it. I'm not trying to do anything fancy (yet), but just be able to make something so I can start putting in validations and such after.</p>
  
  <p>Code Examples:</p>
  
  <p>THE PROBLEM</p>
  
  <p>When I run bundle exec rspec: </p>
  
  <pre><code>  1) Admin successfully creates Admin
   Failure/Error: admin = Admin.new
   ActiveRecord::StatementInvalid:
     PG::UndefinedTable: ERROR:  relation "admins" does not exist
     LINE 5:                WHERE a.attrelid = '"admins"'::regclass
                                               ^
     :               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                          pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
                     FROM pg_attribute a LEFT JOIN pg_attrdef d
                       ON a.attrelid = d.adrelid AND a.attnum = d.adnum
                    WHERE a.attrelid = '"admins"'::regclass
                      AND a.attnum &gt; 0 AND NOT a.attisdropped
                    ORDER BY a.attnum
   # ./spec/admin_spec.rb:6:in `block (2 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>But run manually in the console:</p>
  
  <pre><code>irb(main):007:0&gt; Admin.all.length
  D, [2016-05-04T18:42:02.818958 #30608] DEBUG -- :   Admin Load (1.3ms)  SELECT "admins".* FROM "admins"
  =&gt; 0
  irb(main):008:0&gt; admin = Admin.new
  =&gt; #&lt;Admin id: nil, name: nil, password: nil, created_at: nil, updated_at: nil&gt;
  irb(main):009:0&gt; admin.save
  D, [2016-05-04T18:42:15.127732 #30608] DEBUG -- :    (0.6ms)  BEGIN
  D, [2016-05-04T18:42:15.140416 #30608] DEBUG -- :   SQL (1.1ms)  INSERT INTO "admins" ("created_at", "updated_at") VALUES ($1, $2) RETURNING "id"  [["created_at", "2016-05-05 01:42:15.130599"], ["updated_at", "2016-05-05 01:42:15.130599"]]
  D, [2016-05-04T18:42:15.146401 #30608] DEBUG -- :    (2.3ms)  COMMIT
  =&gt; true
  irb(main):010:0&gt; Admin.all.length
  D, [2016-05-04T18:42:28.236480 #30608] DEBUG -- :   Admin Load (2.1ms)  SELECT "admins".* FROM "admins"
  =&gt; 1
  </code></pre>
  
  <p>THE CODE</p>
  
  <p>The Model: </p>
  
  <pre><code>class Admin &lt; ActiveRecord::Base
    # Remember to create a migration!
  end
  </code></pre>
  
  <p>The Migration:</p>
  
  <pre><code>class CreateAdmins &lt; ActiveRecord::Migration
    def change
      create_table :admins do |t|
        t.string :name
        t.string :password
  
        t.timestamps
      end
    end
  end
  </code></pre>
  
  <p>The Spec:</p>
  
  <pre><code>require 'spec_helper'
  
  describe Admin do
  
    it "successfully creates Admin" do
      admin = Admin.new
      expect(admin.save).to change{Admin.all.length}.by(1)
    end
  
  end
  </code></pre>
  
  <p>spec helper:</p>
  
  <pre><code>require 'rubygems'
  
  ENV['RACK_ENV'] ||= 'test'
  
  require File.expand_path("../../config/environment", __FILE__)
  require 'shoulda-matchers'
  require 'rack/test'
  require 'capybara'
  require 'capybara/rspec'
  
  RSpec.configure do |config|
    config.include Rack::Test::Methods
  end
  
  def app
    Sinatra::Application
  end
  
  Capybara.app = app.new
  </code></pre>
  
  <p>I hope this is enough information, This is my first question, tell me if you need more, or if less would have been better. Thank you!</p>
  
  <p>Also I've seen solutions to this involving rake tasks specific to Rails. Most of these don't exist in Sinatra and I'm having trouble finding the source code to get it into my Sinatra app.</p>