Repository navigation
Project setup
Cyril Kato edited this page Nov 1, 2026
·
1 revision
A spec file is a Ruby file: ruby spec/duck_spec.rb runs it, and its status is 0 when every expectation was met, 1 otherwise. A project shares what every file needs in a spec helper, and runs its files with a Rake task.
# spec/spec_helper.rb
require "r_spec"
require_relative "../lib/duck"# spec/duck_spec.rb
require_relative "spec_helper"
RSpec.describe Duck do
subject { described_class.new }
its(:walk) { is_expected.to eq "Klop klop!" }
end# Rakefile
require "rake/testtask"
Rake::TestTask.new do |t|
t.pattern = File.join("spec", "**", "*_spec.rb")
end
task spec: :test
task default: :test$ bundle exec rake
spec/duck_spec.rb:6: Success: expected "Klop klop!" to eq "Klop klop!"The task loads the files one after the other in one process, in the order of their names, and stops at the first expectation that is not met. One file runs alone with ruby spec/duck_spec.rb; there is no rspec command, no filter and no random order.
RSpec clone requires Ruby 3.3 or later on a system with fork, which each context uses.