Spec & Test Helper

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Spec & Test Helper - Presentation Transcript

    1. Spec & test helpers
    2. Hello my name is
      • Michael Grosser
      • TU-Dresden / TFH-Berlin
      • Rathershort.com
    3. Motivation
      • Write less, test more
      • Rememberable syntax
      • Easy setup
      • Helpful failure messages
      • (Fast test runs)
    4. Spec & test helpers
      • Model Validation, Valid, Stay valid
      • Controller Resource, Misc, it renders, Response enhancers
      • Views Simple tests, Mails
    5. Model – Validation
      • assert_invalid_attributes User, :login=>['',nil,'admin'], :email=>['',nil,'aa']
      • <User.login> expected to be invalid when set to <admin>
    6. Model – Valid
      • fixtures = slow
      • ad-hoc building = error_prone && not DRY
      • Store valid sets of attributes in valid.yml
    7. Model – Valid
      • address: name: Micha mueller street: meine strasse additional: zusatz city: stadt zip: 13088 country: DE addressable_id: 1 addressable_type: Organisation
    8. Model – Valid
      • post :create, :user=>valid_attributes(User)
      • user = valid User
      • user = valid User, :name=>'too short'
      • user = create_valid User, :status=>'offline'
    9. Model – Stay Valid
      • rake db:validate_fixtures
      • rake db:validate_models
      • -- records - model -- 4x Access 2x Address 2x Attachment ...
    10. Controller - Resource
      • make_resourceful OR resource_controller
      • Tests ?
      • ”just test what you have added yourself”
      • no-test-ache ?
      • worry about 'small' changes ?
    11. Controller - Resource
      • describe UsersController do before(:each) do login_as(:quentin) @item = stub_model(User,:to_param=>'1') end end
      • behave_like_resource
      • behave_like_resource_show
    12. Controller – Misc - it_...
      • response.should render_template('show')
      • response.should redirect_to(movie_path(@movie))
      • flash[:notice].should_not be_blank
    13. Controller – Misc - it_...
      • it_renders :show
      • it_redirects @user
      • it_flashes :notice
      • it_assigns :user, @user
    14. Controller – Response enhancers
      • response.should render_template('index')
      • Expected to render index, got nil
      • response.should be_success
      • Expected true, got false
    15. Controller – Response enhancers
      • Status should be redirect but was 200(success) - rendered addresses/new - Flash: :error = Address contains errors! - Errors:Errors on @address(Address): City can't be blank
    16. Views - Simple
      • before(:each) do assigns[:dvds] = dvds(:one) assigns[:current_user] = users :quentin @path = 'dvds/' end
      • it &quot;renders show&quot; do render @path+&quot;show.haml&quot; end
    17. Views - Mails
      • it &quot;contains link to movie&quot; do deliver(:release_notification,@user,@movie) @text.should=~%r[movies/#{@movie.id}] end
    18. Views - Mails
      • def deliver(action, *objs) raise &quot;no mailer&quot; unless @mailer @mailer.send(&quot;deliver_#{action.to_s}&quot;,*objs) @delivery = ActionMailer::Base.deliveries.last @text = @delivery.body_port.to_s end
      • def mails ActionMailer::Base.deliveries end
    19. Downloads / Details
      • pragmatig.wordpress.com
      • [email_address]
    20. Ende
      • Danke

    + grossergrosser, 2 years ago

    custom

    713 views, 0 favs, 0 embeds more stats

    A summary of test helpers and plugins for everyday more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 713
      • 713 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 25
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories