Skip to content

Commit 6486fa6

Browse files
committed
Add testing snippets
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.
1 parent 1af2287 commit 6486fa6

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

Rakefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,16 @@ end
224224

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

227-
task default: [:spec, :acceptance]
227+
desc "Run short, self-contained snippets"
228+
task :snippets do
229+
sh "echo Running snippets"
230+
Dir['snippets/*.rb'].each do |snippet|
231+
sh "echo Running #{snippet}"
232+
sh "ruby #{snippet}"
233+
end
234+
end
235+
236+
task default: [:spec, :acceptance, :snippets]
228237

229238
task :verify_private_key_present do
230239
private_key = File.expand_path('~/.gem/rspec-gem-private_key.pem')

script/custom_build_functions.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ function run_cukes {
1818
function run_all_spec_suites {
1919
fold "one-by-one specs" run_specs_one_by_one
2020
}
21+
22+
function run_snippets {
23+
bin/rake snippets
24+
}

script/run_build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ fi
2020

2121
fold "cukes" run_cukes
2222

23+
fold "snippets" run_snippets
24+
2325
if documentation_enforced; then
2426
fold "doc check" check_documentation_coverage
2527
fi

snippets/use_active_record_false.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require "bundler/inline"
2+
3+
gemfile(true) do
4+
source "https://rubygems.org"
5+
6+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
7+
8+
# Those Gemfiles carefully pick the right versions depending on
9+
# settings in the ENV, `.rails-version` and `maintenance-branch`.
10+
eval_gemfile 'Gemfile-rspec-dependencies'
11+
eval_gemfile 'Gemfile-rails-dependencies'
12+
13+
gem "rspec-rails", path: "./"
14+
gem "sqlite3"
15+
gem "ammeter"
16+
end
17+
18+
# Initialization
19+
require "active_record/railtie"
20+
require "rspec/rails"
21+
22+
# Run specs on exit
23+
require "rspec/autorun"
24+
25+
# RSpec configuration
26+
RSpec.configure do |config|
27+
config.use_active_record = false
28+
end
29+
30+
# Rails project code
31+
class Command
32+
end
33+
34+
# Rails project specs
35+
RSpec.describe Command do
36+
it 'does not not break' do
37+
Command.new
38+
end
39+
end

0 commit comments

Comments
 (0)