A Short Introduction to Test-Driven-Development (TDD)

I’ve practiced TDD (Test-Driven-Development) for years and feel knowledgeable about when it’s useful and when it isn’t. In this post, I’d like to summarize what I’ve learned. My definition of TDD It’s worth mentioning first that there are different versions of TDD. There’s outside-in or black-box TDD, red-green-refactor, BDD, ATDD, and more. They’re all in the same family, but they are distinct. Getting to caught up on terminology can quickly distract from the core concepts they share. ...

September 11, 2019

Learn to Test

What is a skill one could learn to set themselves apart from other entry-level programmers? Testing. The web frameworks of today all have mature test libraries. Hashrocket’s default tool is Ruby on Rails, and testing is a fundamental part of that community. Everything we do is test-driven. New apprentices who come into any consultancy will have a lot to learn. At Hashrocket we use a pretty customized setup of Vim and Tmux, and have a ton of aliases and shorthands that can be hard to pick up. Our apprentices pair program with full-time developers, on real projects. It can be daunting at first. ...

July 15, 2016

Expect a Case-Insensitive Match

We had a testing issue this week when a button’s text save changes! was rendering as SAVE CHANGES!, due to the CSS property text-transform: uppercase. How do you test that? One technique is to use RSpec’s match method, and include case insensitivity with i (explored earlier here): > button_text = "foo" => "foo" > expect(button_text).to match("FOO") RSpec::Expectations::ExpectationNotMetError: expected "foo" to match "FOO" # stuff > expect(button_text).to match(/FOO/i) => true We ultimately hard coded the expectation to match("FOO"), because allowing fOo and FoO seemed too permissive. But it remains an option.

January 5, 2016

Testing Edit Forms

Today I found a way to assert that an edit form’s inputs include a record’s saved data. I think it strikes a good balance between broad and narrow scope. # spec/features/user_edits_kit_spec.rb within 'form' do expect(page).to have_selector("input[value='Default copy.']") end This asserts that some content is inside an input field in the form, rather than just anywhere on the page. You can narrow the scope as needed.

November 17, 2015