Skip to content

Drop rspec in favor of minitest #22

@zhisme

Description

@zhisme

Migrate from RSpec to Minitest

Why

Basically the gem is simple and all we need here is few asserts, verifying correct state and output.

Current State

  • ~60 RSpec tests across 3 spec files
  • Dependencies: rspec, rubocop-rspec
  • RSpec features used: stub_const, allow/receive mocking, let, context blocks, around hooks

Pros for Migration

1. Only asserts
RSpec's DSL is expressive but actually is not needed for the gem. Tests should be simple and fast. RSpec DSL is not needed for that case. Lets use following example for simplicity illustration:

# RSpec
expect(result.valid?).to be true
expect(result.short_name).to eq 'TC'

# Minitest
assert result.valid?
assert_equal 'TC', result.short_name

2. Faster boot time
For a small gem you run tests constantly. RSpec's boot overhead (loading DSL, matchers, etc.) adds up. Minitest loads in milliseconds.

3. Fewer dependencies
Remove from Gemfile:

  • rspec (~3 gems)
  • rubocop-rspec

Add:

  • minitest (usually bundled with Ruby)
  • mocha or minitest-mock (for stubbing, if needed)

4. Rails-native patterns
If anyone uses this gem with Rails, they're already familiar with Minitest assertions. One less context switch.

5. No magic
RSpec's described_class, implicit subjects, shared contexts, and matcher DSL are powerful but obscure what's actually happening. Minitest forces explicit, readable tests.

Migration Considerations

RSpec features that need replacement:

RSpec Minitest Equivalent
describe/context class FooTest < Minitest::Test
it "does thing" def test_does_thing
expect(x).to eq(y) assert_equal y, x
expect(x).to be true assert x
expect(x).to be_nil assert_nil x
let(:foo) { ... } `def foo; @foo
before def setup
after def teardown
stub_const Define test modules inline or use Object.const_set
allow(x).to receive(:y) mocha gem or Minitest::Mock
around setup/teardown with manual cleanup

Files to migrate:

  • spec/spec_helper.rbtest/test_helper.rb
  • spec/lazy_names/line_validator_spec.rbtest/lazy_names/line_validator_test.rb
  • spec/lazy_names/ruby_loader_spec.rbtest/lazy_names/ruby_loader_test.rb
  • spec/integration/ruby_config_spec.rbtest/integration/ruby_config_test.rb

Config files to update/remove:

  • Remove .rspec
  • Remove .rspec_status
  • Update Gemfile
  • Update Rakefile (task definition)
  • Update .rubocop.yml (remove rspec rules)

References

Metadata

Metadata

Assignees

Labels

dependenciesPull requests that update a dependency fileenhancementNew feature or requestrubyPull requests that update ruby code

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions