Part 5 · 1 chapters · ~8 min

Tooling and Testing

Bundler and gems, Minitest and RSpec, fixtures and FactoryBot, model, request and system tests, Capybara, parallel testing, RuboCop and Standard, Brakeman and bundler-audit, and continuous integration for Rails apps.

6

Tests and quality tools

code
# test/integration/transfers_test.rb (Minitest)
class TransfersTest < ActionDispatch::IntegrationTest
  test "retrying with the same key creates one transfer" do
    2.times do
      post transfers_path, params: { transfer: { amount_kobo: 50_000, to: accounts(:bayo).id } },
           headers: { "Idempotency-Key" => "k1", "Authorization" => bearer(users(:ada)) }, as: :json
    end
    assert_equal 1, Transfer.where(idempotency_key: "k1").count
  end
end

bin/rails test               bin/rails test:system       bundle exec rubocop      bundle exec brakeman
RUBY AND RAILS TOOLING
the test and quality toolchain
BundlerGemfile and Gemfile.lock:dependencies pinned and installed.MinitestRails' default test framework:fast, plain Ruby, fixtures.RSpecThe popular alternative:describe/it, rich matchers, let.FactoryBotTest data builders instead offixtures.RuboCop + StandardLinting and formatting;rubocop-rails adds Rails rules.Brakeman + bundler-auditStatic security analysis forRails; vulnerable gems.
swipe the figure sideways, or tap expand for full screen
1/6
dependencies
Bundler resolves and locks gems; bundle exec runs commands with exactly those versions.
Gemfile + lockfilebundle exec