Cucaruba!

1,825 views

Published on

RubyMidwest 2010 lightning talk presentation on using Aruba with Cucumber to integration test Ruby gem plugins for Rails.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,825
On SlideShare
0
From Embeds
0
Number of Embeds
79
Actions
Shares
0
Downloads
6
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

  • What the heck is Cucaruba?!
  • BDD integration testing framework
  • Extension to Cucumber for command line apps
  • Command line apps, eh...?
  • RSpec is a command line app! Cucumber is a command line app!
  • I heard you like features in your features so we put cukes in your cukes!
  • A Rails gem plugin is a great thing to integration test. Particularly in an automated way.
  • Common controller idiom.
  • Much cleaner.
  • Another common idiom.
  • Cleaner again.

  • Getting Rails components into your specs can be painful, and mocking them out entirely is asking for unpleasant surprises.
  • It gets painful.
  • Aruba operates in tmp/aruba relative to your project root. This directory must exist for Aruba to run!
  • Rake tasks to set up a Rails app in the working directory.
  • Copy in your templates or do other setup work to put the app into a testable state.
  • Example Cucumber feature using Aruba steps. Aruba is oriented around file reads and writes and command line input and output.
  • “foo.feature” will be created by Aruba.
  • Just like a two-headed turtle.
  • It makes for, at the least, a great some testing option.
  • RVM gemsets and Bundler dependency management assist in automating the process of setting up a development sandbox for developing your library.
  • This makes for a happier contributor experience...
  • ...which leads to more contributors.
  • Aruba itself, and a great example of using it can be found in rspec/rspec-rails. It also is used in BasicAssumption.

  • Cucaruba!

    1. 1. Viva la Cucaruba! Matt Yoho @mattyoho
    2. 2. CUCARUBA! MATT YOHO Integration testing for Rails gem plugins
    3. 3. CUCARUBA! MATT YOHO Cucumber
    4. 4. CUCARUBA! MATT YOHO Aruba
    5. 5. CUCARUBA! MATT YOHO cucumber features for command line apps
    6. 6. CUCARUBA! MATT YOHO
    7. 7. CUCARUBA! MATT YOHO YO DAWG! I heard you like features in your features so we put cukes in your cukes!
    8. 8. CUCARUBA! MATT YOHO For example...
    9. 9. CUCARUBA! MATT YOHO class WidgetController < AppController before_filter :find_widget, :only => [:show, :edit, :update] def find_widget @widget ||= Widget.find(params[:id]) end end
    10. 10. CUCARUBA! MATT YOHO class WidgetController < AppController assume :widget end
    11. 11. CUCARUBA! MATT YOHO class WidgetController < AppController def user_accout current_user.account end hide_action :user_account helper_method :user_account end
    12. 12. CUCARUBA! MATT YOHO class WidgetController < AppController assume(:account) do current_user.account end end
    13. 13. CUCARUBA! MATT YOHO Specs go a long way, but...
    14. 14. CUCARUBA! MATT YOHO Specs go a long way, but... Rails dependencies, etc.
    15. 15. CUCARUBA! MATT YOHO Yuck.
    16. 16. CUCARUBA! MATT YOHO ~/projects/app/tmp/aruba
    17. 17. CUCARUBA! MATT YOHO ~/projects/app/tmp/aruba ./tmp/aruba rake task
    18. 18. CUCARUBA! MATT YOHO ~/projects/app/tmp/aruba templates ./tmp/aruba rake task
    19. 19. CUCARUBA! MATT YOHO Feature: Rails Controllers Can Make Assumptions Scenario: controller invokes assume Given a file named "app/controllers/widgets_controller.rb" with: """ class WidgetsController < ApplicationController assume(:widget) { Widget.find(params[:id]) } end """ And a file named "app/views/widgets/show.html.erb" with: """ <blink><%= widget.name %></blink> """ And a file named "features/widget_is_viewed_by_visitor.feature" with: """ Feature: Widget is viewed by visitor Scenario: success Given a widget named "foobar" When I view the widget Then I should see "foobar" """ When I run "cucumber features/widget_is_viewed_by_visitor.feature" Then I should see: """ 1 scenario (1 passed) 3 steps """
    20. 20. CUCARUBA! MATT YOHO Feature: Foo Does Something Scenario: foo works Given a file named "foo.feature" with: """ Feature: Widget is viewed by visitor Scenario: success Given a foo named "bar" When I view the foo Then I should see "bar" """ When I run "cucumber foo.feature" Then I should see: """ 1 scenario (1 passed) 1 step """
    21. 21. CUCARUBA! MATT YOHO A little slow, but totally badass.
    22. 22. CUCARUBA! MATT YOHO
    23. 23. CUCARUBA! MATT YOHO RVM and Bundler are complimentary
    24. 24. CUCARUBA! MATT YOHO Be kind to your contributors
    25. 25. CUCARUBA! MATT YOHO Get Forked
    26. 26. CUCARUBA! MATT YOHO http://github.com/aslakhellesoy/aruba http://github.com/rspec/rspec- rails http://github.com/mattyoho/ basic_assumption
    27. 27. Thank you Matt Yoho matt@edgecase.com @mattyoho

    ×