DEV Community

Cover image for Building Tests in Ruby: The Basics

Building Tests in Ruby: The Basics

Tori Crawford on July 29, 2019

Throughout my time in bootcamp, the learning environment was built off of tests, meaning that I learned by running tests, seeing my errors, and goi...
Collapse
 
ark profile image
Ark Shraier • Edited

Thank you, Victoria, for the post. Here's my humble addition to your thoughts.

One small (read important) thing that may become an obstacle in TDD is the fact, that first step -- writing test, implies that you should completely understand the task and have already decomposed it in your mind into small pieces.

And following the point, this is the core of software development, -- to understand and decompose the task, that can take 40-70% of the time for the task.

And writing tests in RSpec or something else is not difficult after that.

(I'm not talking here about simple scaffolded model and controller tests, but TDD for the business logic)

Collapse
 
torianne02 profile image
Tori Crawford

You are absolutely correct. Thank you so much for adding this to the discussion.

Collapse
 
oinak profile image
Oinak

Thank you Victoria, very good introduction to testing and RSpec.

I would like to leave here a couple of links to resources on testing with the ruby included test library Minitest that supports both assertions

  def test_foo_bar
    assert_equal(foo, bar)
  end

and expectations

describe 'Foo' do
  it '#bar' do
    expect(foo).must_equal(bar)
  end
end

Which might be useful for those leaning on having less dependencies or lighter tests:

Thank you very much for your work and time!

Collapse
 
mahendrachoudhary profile image
Mahendra Choudhary

thanks for introducing us to importance of TDD and rspec .