Share
Embed
Testes no Rails: Além do Ruby
Um ponto de vista sobre como cuidar e evoluir de forma sustentável a camada de JavaScripts de uma aplicação Rails. Utilizando como base uma abordagem TDD, indo além dos simples testes de aceitação: escrevendo testes de unidade e desenvolvendo código fácil de ser testado.
Halan Pinheiro
September 03, 2013
Transcript
62 slides
-
Testes no Rails: Além do Ruby Por Halan Pinheiro terça-feira,
3 de setembro de 13 -
‣Como vamos poder comer? ‣ Por que comemos? terça-feira, 3
de setembro de 13 -
‣Como vamos poder comer? ‣ Por que comemos? ‣ Onde
vamos almoçar? terça-feira, 3 de setembro de 13 -
‣Como vamos poder comer? ‣ Por que comemos? ‣ Onde
vamos almoçar? Sobrevivência Interrogação Sofisticação terça-feira, 3 de setembro de 13 -
‣Como? ‣Por quê? ‣Onde? ... Embora uma grande civilização leve
milênios para passar pelas fases do Como, do Porquê e do Onde, pequenos agrupamentos sociais podem passar por elas com extrema rapidez. terça-feira, 3 de setembro de 13 -
Mocha <html> <head> <title>Mocha Tests</title> <script type="text/javascript" src="mocha.js"></script> <script> mocha.setup('bdd');
var assert = function(expression){ if(!expression) throw; }; describe('Winston Smith sum', function(){ it('2 + 2 always be equal 4', function(){ assert(2 + 2 == 4); }); }); mocha.run(); </script> </head> <body></body> </html> terça-feira, 3 de setembro de 13 -
Mocha <html> <head> <title>Mocha Tests</title> <script type="text/javascript" src="mocha.js"></script> <script> mocha.setup('bdd');
var assert = function(expression){ if(!expression) throw; }; describe('Winston Smith sum', function(){ it('2 + 2 always be equal 4', function(){ assert(2 + 2 == 4); }); }); mocha.run(); </script> </head> <body></body> </html> terça-feira, 3 de setembro de 13 -
Mocha <html> <head> <title>Mocha Tests</title> <script type="text/javascript" src="mocha.js"></script> <script> mocha.setup('bdd');
var assert = function(expression){ if(!expression) throw; }; describe('Winston Smith sum', function(){ it('2 + 2 always be equal 4', function(){ assert(2 + 2 == 4); }); }); mocha.run(); </script> </head> <body></body> </html> terça-feira, 3 de setembro de 13 -
Mocha <html> <head> <title>Mocha Tests</title> <script type="text/javascript" src="mocha.js"></script> <script> mocha.setup('bdd');
var assert = function(expression){ if(!expression) throw; }; describe('Winston Smith sum', function(){ it('2 + 2 always be equal 4', function(){ assert(2 + 2 == 4); }); }); mocha.run(); </script> </head> <body></body> </html> terça-feira, 3 de setembro de 13 -
Mocha <html> <head> <title>Mocha Tests</title> <script type="text/javascript" src="mocha.js"></script> <script> mocha.setup('bdd');
var assert = function(expression){ if(!expression) throw; }; describe('Winston Smith sum', function(){ it('2 + 2 always be equal 4', function(){ assert(2 + 2 == 4); }); }); mocha.run(); </script> </head> <body></body> </html> terça-feira, 3 de setembro de 13 -
Mocha + Chai.js window.expect = chai.expect; describe('Winston Smith sum', function(){
it('2+2 always be equal 4', function(){ expect( 2 + 2 ).to.be.equal(4); }); }); describe( 'we love the expressiveness of chai: write.with.dots.is.cool', function(){ it('2+2 always be equal 4 and 4 is a number', function(){ expect(2 + 2).to.be.equal(4).and.is.a('number'); }); }); terça-feira, 3 de setembro de 13 -
Mocha + Chai.js window.expect = chai.expect; describe('Winston Smith sum', function(){
it('2+2 always be equal 4', function(){ expect( 2 + 2 ).to.be.equal(4); }); }); describe( 'we love the expressiveness of chai: write.with.dots.is.cool', function(){ it('2+2 always be equal 4 and 4 is a number', function(){ expect(2 + 2).to.be.equal(4).and.is.a('number'); }); }); terça-feira, 3 de setembro de 13 -
Mocha + Chai.js window.expect = chai.expect; describe('Winston Smith sum', function(){
it('2+2 always be equal 4', function(){ expect( 2 + 2 ).to.be.equal(4); }); }); describe( 'we love the expressiveness of chai: write.with.dots.is.cool', function(){ it('2+2 always be equal 4 and 4 is a number', function(){ expect(2 + 2).to.be.equal(4).and.is.a('number'); }); }); terça-feira, 3 de setembro de 13 -
Mocha + Chai.js window.expect = chai.expect; describe('Winston Smith sum', function(){
it('2+2 always be equal 4', function(){ expect( 2 + 2 ).to.be.equal(4); }); }); describe( 'we love the expressiveness of chai: write.with.dots.is.cool', function(){ it('2+2 always be equal 4 and 4 is a number', function(){ expect(2 + 2).to.be.equal(4).and.is.a('number'); }); }); terça-feira, 3 de setembro de 13 -
Sinon.js //= require products describe('Products', function(){ beforeEach(function(){ this.server = sinon.fakeServer.create();
this.server.requests[0].respond( 200, { "Content-Type": "application/json" }, JSON.stringify([{id: 2}, {id: 7}, {id: 8}]); ); }); afterEach(function(){ this.restore(); }); it('fetch loads some products', function(){ var new products = new Products() products.fetch(); expect(products).to.be.length(6); }); }); terça-feira, 3 de setembro de 13 -
Sinon.js //= require products describe('Products', function(){ beforeEach(function(){ this.server = sinon.fakeServer.create();
this.server.requests[0].respond( 200, { "Content-Type": "application/json" }, JSON.stringify([{id: 2}, {id: 7}, {id: 8}]); ); }); afterEach(function(){ this.restore(); }); it('fetch loads some products', function(){ var new products = new Products() products.fetch(); expect(products).to.be.length(6); }); }); terça-feira, 3 de setembro de 13 -
Sinon.js //= require products describe('Products', function(){ beforeEach(function(){ this.server = sinon.fakeServer.create();
this.server.requests[0].respond( 200, { "Content-Type": "application/json" }, JSON.stringify([{id: 2}, {id: 7}, {id: 8}]); ); }); afterEach(function(){ this.restore(); }); it('fetch loads some products', function(){ var new products = new Products() products.fetch(); expect(products).to.be.length(6); }); }); terça-feira, 3 de setembro de 13 -
Sinon.js //= require products describe('Products', function(){ beforeEach(function(){ this.server = sinon.fakeServer.create();
this.server.requests[0].respond( 200, { "Content-Type": "application/json" }, JSON.stringify([{id: 2}, {id: 7}, {id: 8}]); ); }); afterEach(function(){ this.restore(); }); it('fetch loads some products', function(){ var new products = new Products() products.fetch(); expect(products).to.be.length(3); }); }); terça-feira, 3 de setembro de 13 -
Sinon.js //= require products describe('Products', function(){ beforeEach(function(){ this.server = sinon.fakeServer.create();
this.server.requests[0].respond( 200, { "Content-Type": "application/json" }, JSON.stringify([{id: 2}, {id: 7}, {id: 8}]); ); }); afterEach(function(){ this.restore(); }); it('fetch loads some products', function(){ var new products = new Products() products.fetch(); expect(products).to.be.length(3); }); }); terça-feira, 3 de setembro de 13 -
Sinon.js //= require products describe('Products', function(){ beforeEach(function(){ this.server = sinon.fakeServer.create();
this.server.requests[0].respond( 200, { "Content-Type": "application/json" }, JSON.stringify([{id: 2}, {id: 7}, {id: 8}]); ); }); afterEach(function(){ this.restore(); }); it('fetch loads some products', function(){ var new products = new Products() products.fetch(); expect(products).to.be.length(3); }); }); terça-feira, 3 de setembro de 13 -
Não vou testar isso! É só um JavaScript... terça-feira, 3
de setembro de 13 -
Konacha group :development, :test do gem "konacha" end terça-feira, 3
de setembro de 13 -
Konacha group :development, :test do gem "konacha" end terça-feira, 3
de setembro de 13 -
Konacha group :development, :test do gem "konacha" gem "poltergeist" end
terça-feira, 3 de setembro de 13 -
config/initializers/konacha.rb Konacha.configure do |config| require 'capybara/poltergeist' config.driver = :poltergeist end
if defined?(Konacha) terça-feira, 3 de setembro de 13 -
config/initializers/konacha.rb Konacha.configure do |config| require 'capybara/poltergeist' config.driver = :poltergeist end
if defined?(Konacha) terça-feira, 3 de setembro de 13 -
$ bundle exec rake konacha:run ................... Finished in 0.503 seconds
19 examples, 0 failed, 0 pending terça-feira, 3 de setembro de 13 -
$ bundle exec rake konacha:run ................... Finished in 0.503 seconds
19 examples, 0 failed, 0 pending terça-feira, 3 de setembro de 13