Skip to content

Instantly share code, notes, and snippets.

@krisleech
Last active February 14, 2020 15:05
Show Gist options
  • Select an option

  • Save krisleech/9e5c47dfc7fd7ac8db3e366788a91ca2 to your computer and use it in GitHub Desktop.

Select an option

Save krisleech/9e5c47dfc7fd7ac8db3e366788a91ca2 to your computer and use it in GitHub Desktop.
Inline Gemfile for learning and reporting bugs
require 'bundler/inline'

gemfile(true) do
  source 'https://rubygems.org'
  gem 'activerecord'
  gem 'sqlite3'
  gem 'rspec'
  gem 'pry'
end

require 'rspec/autorun'
require 'active_record'

ActiveRecord::Base.establish_connection(adapter: "sqlite3",
                                        database: ":memory:")

ActiveRecord::Schema.define do
  create_table :planets, force: true do |t|
    t.string  :name
  end
end

class Planet < ActiveRecord::Base
  validates :name, presence: true
end

# planet = Planet.create!(name: 'Earth')
#
# puts planet.inspect

RSpec.describe Planet do
  it 'can be created' do
    expect { Planet.create!(name: 'Earth') }.not_to raise_error
  end
end

You can run the file with ruby -W0 test.rb or run on file change with ls *.rb | entr ruby -W0 test.rb.

Example usages:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment