814 days ago · Tech · 0 comments

There’s a lot of testing tools for Ruby on Rails. Ruby started life with a strong testing culture. The ecosystem is brimming with tools. But not all of those tools spark joy. I love a lot of them. I’ve written about my nostalgia for Cucumber. But one tool that always makes me feel weird is Shoulda matchers. Shoulda matchers are a tool written by thoughtbot that gives you one line tests for various Rails features: RSpec.describe MenuItem, type: :model do describe 'associations' do it { should belong_to(:category).class_name('MenuCategory') } end describe 'validations' do it { should validate_presence_of(:name) } it { should validate_uniqueness_of(:name).scoped_to(:category_id) } end end This can seem like a great idea, but I can’t help feel that this style of testing breaks the boundary for Rails. The example above tests that the MenuItem model has particular associations and validations. I firmly believe that tests should act as a collaborator with the code under test. None of the…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.