tdd no rails

Upload: valtermaia1087

Post on 05-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 Tdd No Rails

    1/74

  • 7/31/2019 Tdd No Rails

    2/74

  • 7/31/2019 Tdd No Rails

    3/74

  • 7/31/2019 Tdd No Rails

    4/74

  • 7/31/2019 Tdd No Rails

    5/74

  • 7/31/2019 Tdd No Rails

    6/74

  • 7/31/2019 Tdd No Rails

    7/74

  • 7/31/2019 Tdd No Rails

    8/74

  • 7/31/2019 Tdd No Rails

    9/74

  • 7/31/2019 Tdd No Rails

    10/74

  • 7/31/2019 Tdd No Rails

    11/74

  • 7/31/2019 Tdd No Rails

    12/74

  • 7/31/2019 Tdd No Rails

    13/74

  • 7/31/2019 Tdd No Rails

    14/74

  • 7/31/2019 Tdd No Rails

    15/74

  • 7/31/2019 Tdd No Rails

    16/74

  • 7/31/2019 Tdd No Rails

    17/74

  • 7/31/2019 Tdd No Rails

    18/74

  • 7/31/2019 Tdd No Rails

    19/74

  • 7/31/2019 Tdd No Rails

    20/74

  • 7/31/2019 Tdd No Rails

    21/74

  • 7/31/2019 Tdd No Rails

    22/74

  • 7/31/2019 Tdd No Rails

    23/74

  • 7/31/2019 Tdd No Rails

    24/74

  • 7/31/2019 Tdd No Rails

    25/74

  • 7/31/2019 Tdd No Rails

    26/74

  • 7/31/2019 Tdd No Rails

    27/74

  • 7/31/2019 Tdd No Rails

    28/74

  • 7/31/2019 Tdd No Rails

    29/74

  • 7/31/2019 Tdd No Rails

    30/74

  • 7/31/2019 Tdd No Rails

    31/74

  • 7/31/2019 Tdd No Rails

    32/74

  • 7/31/2019 Tdd No Rails

    33/74

  • 7/31/2019 Tdd No Rails

    34/74

  • 7/31/2019 Tdd No Rails

    35/74

  • 7/31/2019 Tdd No Rails

    36/74

  • 7/31/2019 Tdd No Rails

    37/74

  • 7/31/2019 Tdd No Rails

    38/74

  • 7/31/2019 Tdd No Rails

    39/74

  • 7/31/2019 Tdd No Rails

    40/74

  • 7/31/2019 Tdd No Rails

    41/74

  • 7/31/2019 Tdd No Rails

    42/74

  • 7/31/2019 Tdd No Rails

    43/74

  • 7/31/2019 Tdd No Rails

    44/74

  • 7/31/2019 Tdd No Rails

    45/74

  • 7/31/2019 Tdd No Rails

    46/74

  • 7/31/2019 Tdd No Rails

    47/74

  • 7/31/2019 Tdd No Rails

    48/74

  • 7/31/2019 Tdd No Rails

    49/74

  • 7/31/2019 Tdd No Rails

    50/74

  • 7/31/2019 Tdd No Rails

    51/74

  • 7/31/2019 Tdd No Rails

    52/74

  • 7/31/2019 Tdd No Rails

    53/74

  • 7/31/2019 Tdd No Rails

    54/74

  • 7/31/2019 Tdd No Rails

    55/74

  • 7/31/2019 Tdd No Rails

    56/74

  • 7/31/2019 Tdd No Rails

    57/74

  • 7/31/2019 Tdd No Rails

    58/74

  • 7/31/2019 Tdd No Rails

    59/74

  • 7/31/2019 Tdd No Rails

    60/74

  • 7/31/2019 Tdd No Rails

    61/74

  • 7/31/2019 Tdd No Rails

    62/74

  • 7/31/2019 Tdd No Rails

    63/74

  • 7/31/2019 Tdd No Rails

    64/74

  • 7/31/2019 Tdd No Rails

    65/74

    Testes de integrao

  • 7/31/2019 Tdd No Rails

    66/74

    g

    classArtistStoriesTest< ActionController::IntegrationTestfixtures :artists, :albums

    def test_artist_story artist = artists(:millencolin)

    user = new_sessionuser.search_artist artistuser.view_album artist.albums.first

    end

    privatedef new_session

    open_sessiondo |session| def session.search_artist(artist)

    get search_artist(artist.name)assert_response:redirectassert_redirected_to artist_path(artist.slug)

    end

    def session.view_album(album)get album_path(album.slug)assert_response:successassert_template'view'

    endend

    endend

    test/integration/artist_stories_test.rb

    Testes de integrao

  • 7/31/2019 Tdd No Rails

    67/74

    g

    classArtistStoriesTest< ActionController::IntegrationTestfixtures :artists, :albums

    def test_artist_story artist = artists(:millencolin)

    user = new_sessionuser.search_artist artistuser.view_album artist.albums.first

    end

    privatedef new_session

    open_sessiondo |session| def session.search_artist(artist)

    get search_artist(artist.name)assert_response:redirectassert_redirected_to artist_path(artist.slug)

    end

    def session.view_album(album)get album_path(album.slug)assert_response:successassert_template'view'

    endend

    endend

    test/integration/artist_stories_test.rb

    user = new_sessionuser.search_artist artistuser.view_album artist.albums.first

    Testes de integrao

  • 7/31/2019 Tdd No Rails

    68/74

    classArtistStoriesTest< ActionController::IntegrationTestfixtures :artists, :albums

    def test_artist_story artist = artists(:millencolin)

    user = new_sessionuser.search_artist artistuser.view_album artist.albums.first

    end

    privatedef new_session

    open_sessiondo |session| def session.search_artist(artist)

    get search_artist(artist.name)assert_response:redirectassert_redirected_to artist_path(artist.slug)

    end

    def session.view_album(album)get album_path(album.slug)assert_response:successassert_template'view'

    endend

    endend

    test/integration/artist_stories_test.rb

    user = new_sessionuser.search_artist artistuser.view_album artist.albums.first

    melhor, impossvel!

    Mocks & Stubs

  • 7/31/2019 Tdd No Rails

    69/74

    Cdigos que eliminam o acesso a um recurso

    Ficam sob o diretriotest/mocks/test Deve ter o mesmo nome do arquivo e estrutura daclasse/mdulo que voc quer substituir

    RAILS_ROOT/lib/launch_missile.rb

    test/mocks//launch_missile.rb

    Mocks & Stubs

  • 7/31/2019 Tdd No Rails

    70/74

    require open-uri

    classFeed def load(url)

    openURI.parse(url).readend

    end

    lib/feed.rb

    Mocks & Stubs

  • 7/31/2019 Tdd No Rails

    71/74

    require open-uri

    classFeed def load(url)

    openURI.parse(url).readend

    end

    lib/feed.rb

    no o ideal:a) pode ser lento;

    b) pode no estar disponvel;c) imagine se fosse transao de pagamento!

    Mocks & Stubs

  • 7/31/2019 Tdd No Rails

    72/74

    require open-uri

    classFeed def load(url)

    File.new(#{RAILS_ROOT}/test/fixtures/feed.xml).readend

    end

    test/mocks/test/feed.rb

    Mocks & Stubs

  • 7/31/2019 Tdd No Rails

    73/74

    require open-uri

    classFeed def load(url)

    File.new(#{RAILS_ROOT}/test/fixtures/feed.xml).readend

    end

    test/mocks/test/feed.rb

    muito mais fcil e rpido:faa quantos pagamentos quiser!

  • 7/31/2019 Tdd No Rails

    74/74

    Dvidas?