W4D4 Flashcards
TDD
Test Driven Development
Why do we test
Check that everything is working. Increases flexibility by reducing fear that something might be broken in the future.
Naturally produces documentation for our code
TDD Pyramid
Unit - Foundation, for specific methods. Classes are tested in isolation (use doubles)
Integration - Test how parts are working together, you need fewer
End 2 End - Tests the flow of the application from start to finish.
Red > Green > Refactor
Write tests before the code, they should all fail.
Green Minimuum amount of code to pass the test
Refactor > clean up the code to make everything look better
Demo
setup, structure, syntax
describe,
RSPEC setup
mkdir project cd project bundle init gems** rspec -- init --format documentaion --color
create a lib folder
file.rb
in spec
file_spec.rb
DESCRIBE Class
require ‘rspec’
require ‘class’
describe Class do
end
DESCRIBE ‘readability string’
describe ‘#method_test’ do
end
IT ‘readably test string”
it ‘expected execution’ do
end
CONTEXT block
wrap a given it block when some context to help with readability
context ‘with valid arguments’ do
it ‘intantiates correctly’ do
end
end
ALLOW
allow(:board).to receive(:vaild_pos?).and_return(false)
allow
simulates behavior that you would have required for the test to be testable
let(:) vs subject(:)
let signifies it is not the primary focus, subject is the focus
you can have multiple lets, but not multiple subjects