Spec & Test Helper
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Spec & Test Helper

on

  • 2,256 views

A summary of test helpers and plugins for everyday rails work. Including models/controllers/views/mails.

A summary of test helpers and plugins for everyday rails work. Including models/controllers/views/mails.

Statistics

Views

Total Views
2,256
Views on SlideShare
2,253
Embed Views
3

Actions

Likes
0
Downloads
28
Comments
0

1 Embed 3

http://www.slideshare.net 3

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

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