Skip to content

Instantly share code, notes, and snippets.

@rodrigomanhaes
Created October 27, 2011 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodrigomanhaes/1320521 to your computer and use it in GitHub Desktop.
Save rodrigomanhaes/1320521 to your computer and use it in GitHub Desktop.
Exemplo de teste "procedural" escrito em Ruby
# Arquivo fatorial_spec.rb
require './fatorial'
describe 'fatorial' do
it 'calcula fatorial' do
fatorial(0).should == 1
fatorial(1).should == 1
fatorial(2).should == 2
fatorial(3).should == 6
fatorial(4).should == 24
fatorial(5).should == 120
end
end
# Arquivo fatorial.rb
def fatorial(n)
return 1 if n == 0
n * fatorial(n)
end
# Para rodar: rspec fatorial_spec.rb
# Necessário ter instalados o Ruby e a gem rspec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment