at the top of the Stack' do stack = Stack.new stack.push 1 stack.push 2 expect(stack.top).to eq 1 end end end describe Stack do describe '#push' do it 'puts an element at the top of the Stack' do stack = Stack.new stack.push 1 stack.push 2 expect(stack.top).to eq 2 end end end Teste errado Teste correto
todos as completed' do sign_in create_todo 'Buy me a beer' find('.todos li', text: 'Buy me a beer').click_on 'Mark complete' expect(page).to have_css('.todos li.completed', text: 'Buy me a beer') end end
todos as completed' do sign_in create_todo 'Buy me a beer' find('.todos li', text: 'Buy me a beer').click_on 'Mark complete' expect(page).to have_css('.todos li.completed', text: 'Buy me a beer') end end Domínio do problema Domínio de UI Domínio de UI
todos as completed' do sign_in create_todo 'Buy me a beer' mark_complete 'Buy me a beer' expect(page).to have_completed_todo 'Buy me a beer' end end Domínio do problema Domínio do problema
at the top of the Stack' do stack = Stack.new stack.push 1 stack.push 2 expect(stack.top).to eq 2 end end describe '#pop' do it 'remove an element at the final of the Stack' do stack = Stack.new stack.push 1 stack.push 2 stack.push 3 stack.pop expect(stack.last).to eq 2 end end end
hits the target' do it 'congratulates the player' do @game = Game.new @game.phase = :final @game.hit_the_target expect(@game.output).to eq 'Congratulations!' end it 'set the score to the player' do @game = Game.new @game.phase = :final @game.hit_the_target expect(@game.score).to eq 100 end end end
hits the target' do it 'congratulates the player' do @game = Game.new @game.phase = :final @game.hit_the_target expect(@game.output).to eq 'Congratulations!' end it 'set the score to the player' do @game = Game.new @game.phase = :final @game.hit_the_target expect(@game.score).to eq 100 end end end DRY
hits the target' do before do @game = Game.new @game.phase = :final @game.hit_the_target end it 'congratulates the player' do expect(@game.output).to eq 'Congratulations!' end it 'set the score to the player' do expect(@game.score).to eq 100 end end end DRY
hits the target' do before do @game = Game.new @game.phase = :final @game.hit_the_target end it 'congratulates the player' do expect(@game.output).to eq 'Congratulations!' end it 'set the score to the player' do expect(@game.score).to eq 100 end end end
do computer = SecretOfLife.new computer.print_the_answer expect(STDOUT.read).to eq 42 end end IOError: not opened for reading from (irb):1:in `read' from (irb):1
do printer = double('printer') computer = SecretOfLife.new(printer) expect(printer).to receive(:print).with('42') computer.print_the_answer end end Test double
do printer = double('printer') computer = SecretOfLife.new(printer) expect(printer).to receive(:print).with('42') computer.print_the_answer end end Test double Injeção de dependência
do printer = double('printer') computer = SecretOfLife.new(printer) expect(printer).to receive(:print).with('42') computer.print_the_answer end end Test double Injeção de dependência Mock do test double
do printer = double('printer') computer = SecretOfLife.new(printer) expect(printer).to receive(:print).with('42') computer.print_the_answer end end Setup Verify Exercise
do printer = double('printer')' computer = SecretOfLife.new(printer) expect(printer).to receive(:print).with('42') computer.print_the_answer end end describe Stack do describe '#push' do it 'puts an element at the top of the Stack' do stack = Stack.new stack.push 1 stack.push 2 expect(stack.top).to eq 1 end end end Verify Verify
do user = double('user')' allow(user).to receive(:log_in) .with(:name => 'rands0n', :password => '12345') .and_return true account = Account.new(user).log_in expect(account.is_logged?).to be_true end end Estubando o objeto user
do user = double('user')' allow(user).to receive(:log_in) .with(:name => 'rands0n', :password => '12345') .and_return true account = Account.new(user).log_in expect(account.is_logged?).to be_true end end Stub: fase de setup
do printer = double('printer')' computer = SecretOfLife.new(printer) expect(printer).to receive(:print).with('42') computer.print_the_answer end end Verify describe Account do it 'log the user on the system' do user = double('user')' allow(user).to receive(:log_in) .with(:name => 'rands0n', :password => '12345') .and_return true account = Account.new(user).log_in expect(account.is_logged?).to be_true end end Setup