|
| 1 | +if __FILE__ =~ /^snippets/ |
| 2 | + fail "Snippets are supposed to be run from their own directory to avoid side " \ |
| 3 | + "effects as e.g. the root `Gemfile`, or `spec/spec_helpers.rb` to be " \ |
| 4 | + "loaded by the root `.rspec`." |
| 5 | +end |
| 6 | + |
| 7 | +# We opt-out from using RubyGems, but `bundler/inline` requires it |
| 8 | +require 'rubygems' |
| 9 | + |
| 10 | +require "bundler/inline" |
| 11 | + |
| 12 | +# We pass `false` to `gemfile` to skip the installation of gems, |
| 13 | +# because it may install versions that would conflict with versions |
| 14 | +# from the main `Gemfile.lock`. |
| 15 | +gemfile(false) do |
| 16 | + source "https://rubygems.org" |
| 17 | + |
| 18 | + git_source(:github) { |repo| "https://github.com/#{repo}.git" } |
| 19 | + |
| 20 | + # Those Gemfiles carefully pick the right versions depending on |
| 21 | + # settings in the ENV, `.rails-version` and `maintenance-branch`. |
| 22 | + Dir.chdir('..') do |
| 23 | + eval_gemfile 'Gemfile-sqlite-dependencies' |
| 24 | + # This Gemfile expects `maintenance-branch` file to be present |
| 25 | + # in the current directory. |
| 26 | + eval_gemfile 'Gemfile-rspec-dependencies' |
| 27 | + # This Gemfile expects `.rails-version` file |
| 28 | + eval_gemfile 'Gemfile-rails-dependencies' |
| 29 | + end |
| 30 | + |
| 31 | + gem "rspec-rails", path: "../" |
| 32 | +end |
| 33 | + |
| 34 | +# Run specs at exit |
| 35 | +require "rspec/autorun" |
| 36 | + |
| 37 | +require "rails" |
| 38 | +require "active_record/railtie" |
| 39 | +require "rspec/rails" |
| 40 | + |
| 41 | +# This connection will do for database-independent bug reports |
| 42 | +ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") |
| 43 | + |
| 44 | +RSpec.configure do |config| |
| 45 | + config.use_transactional_fixtures = true |
| 46 | +end |
| 47 | + |
| 48 | +RSpec.describe 'Foo' do |
| 49 | + subject { true } |
| 50 | + |
| 51 | + # Rails 6.1 and after |
| 52 | + let(:name) { raise "Should never raise" } |
| 53 | + # Before Rails 6.1 |
| 54 | + let(:method_name) { raise "Should never raise" } |
| 55 | + |
| 56 | + it { is_expected.to be_truthy } |
| 57 | +end |
0 commit comments