Refactor duplication in RSpec tests using the Parameterized Test Method
What do you do when you need to run the same test multiple times, but with different parameters? If you copy and paste the test, you end up with a hard-to-read test file. You can’t easily tell how the tests differ from one another. Worse, when you need to change one, you need to change them all. Take the following simple test file: def double_it(number) number * 2 end describe '#double_it' do it 'doubles 1 into 2' do expect(double_it(1)).to eq(2) end it 'doubles 2 into 4' do expect(double_it(2)