Skip to content

Commit

Permalink
Add testing snippets
Browse files Browse the repository at this point in the history
Snippet is a self-contained example that defines the configuration,
Rails project code and specs to run.

It:
 - allows for clean separation between different snippets
 - works quite fast
 - reuses the already installed gems

In theory snippets retain the ability to use generators and arbitrary
commands, but it makes the case under test less evident.
  • Loading branch information
pirj committed Jan 14, 2021
1 parent 4e88eb3 commit 5b0bdd0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,16 @@ end

task acceptance: ['smoke:app', 'no_active_record:smoke:app', :cucumber]

task default: [:spec, :acceptance]
desc "Run short, self-contained snippets"
task :snippets do
sh "echo Running snippets"
Dir['snippets/*.rb'].each do |snippet|
sh "echo Running #{snippet}"
sh "ruby #{snippet}"
end
end

task default: [:spec, :acceptance, :snippets]

task :verify_private_key_present do
private_key = File.expand_path('~/.gem/rspec-gem-private_key.pem')
Expand Down
4 changes: 4 additions & 0 deletions script/custom_build_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ function run_cukes {
function run_all_spec_suites {
fold "one-by-one specs" run_specs_one_by_one
}

function run_snippets {
bin/rake snippets
}
2 changes: 2 additions & 0 deletions script/run_build
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ fi

fold "cukes" run_cukes

fold "snippets" run_snippets

if documentation_enforced; then
fold "doc check" check_documentation_coverage
fi
Expand Down
39 changes: 39 additions & 0 deletions snippets/use_active_record_false.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require "bundler/inline"

gemfile(true) do
source "https://rubygems.org"

git_source(:github) { |repo| "https://github.com/#{repo}.git" }

# Those Gemfiles carefully pick the right versions depending on
# settings in the ENV, `.rails-version` and `maintenance-branch`.
eval_gemfile 'Gemfile-rspec-dependencies'
eval_gemfile 'Gemfile-rails-dependencies'

gem "rspec-rails", path: "./"
gem "sqlite3"
gem "ammeter"
end

# Initialization
require "active_record/railtie"
require "rspec/rails"

# Run specs on exit
require "rspec/autorun"

# RSpec configuration
RSpec.configure do |config|
config.use_active_record = false
end

# Rails project code
class Command
end

# Rails project specs
RSpec.describe Command do
it 'does not not break' do
Command.new
end
end

0 comments on commit 5b0bdd0

Please sign in to comment.