Escolar Documentos
Profissional Documentos
Cultura Documentos
Novembro 2008
Behavior Driven Development
Story
As a ... [role]
Scenarios
G W T – Given, When, Then
Scenario: título
• Given a user called Dave • When I click the ‘profile’ • Then I should see my
link profile page
• And Dave is logged in
• When I enter my new • And it should list how
password and confirmation many items I have bought
• Escrever os controllers
• Escrever os models
• Executar a “Story”
Instalando rSpec
Para testar apenas código Ruby sem aplicação Rails basta executar o comando:
• gem install rspec
rSpec on Rails :
Versão 1.1.4 o rSpec utiliza o Github, vamos apenas clonar seu repositório com os comandos:
cd vendor/plugins
git clone git://github.com/dchelimsky/rspec.git
cd rspec
git checkout 1.1.4
cd ..
git clone git://github.com/dchelimsky/rspec-rails.git
cd rspec-rails
git checkout 1.1.4
cd ../../../
rSpec on Rails
• script/generate rspec
Aplicação
Aplicando rSpec no projeto pilates
Requisitos básicos:
• Uma pessoa podetervários lancamentos
Temos então:
• Um “usuário” com um “name” relacionado avários “tasks”
Modelo Usuário
Para criar o modelo usuário temos generators do próprio rSpec.
script/generate rspec_model Usuario name:string login:string email:string crypted_password:string
rake db:migrate
Temos no banco:
Rodando os Testes
- rake spec
DEPRECATION WARNING
Proporção de Testes em relação ao código
- rake stats
• http://www.slideshare.net/rahoulb/telling-stories-with-rspec-presentation
• http://blog.davidchelimsky.net/2008/6/16/slides-
•
http://www.joesniff.co.uk/ruby/telling-a-good-story-rspec-stories-from-the-trenches.html
• http://kpumuk.info/category/ruby-on-rails/
•
http://simplesideias.com.br/usando-o-rspec-para-testar-sua-aplicacao-rails-modelos/#com
• http://rspec.info/documentation/test_unit.html
• http://www.nabble.com/alias-:calling-:lambda-td12789662.html