Viva la Cucaruba!

Matt Yoho
@mattyoho
CUCARUBA!   MATT YOHO




                    Integration testing
                       for Rails gem
                          plugins
CUCARUBA!   MATT YOHO




    Cucumber
CUCARUBA! MATT YOHO

                      Aruba
CUCARUBA!   MATT YOHO




                          cucumber features
                        for command line apps
CUCARUBA!   MATT YOHO
CUCARUBA! MATT YOHO




              YO DAWG! I heard you like features in
              your features so we put cukes in your
                              cukes!
CUCARUBA!   MATT YOHO




                        For example...
CUCARUBA!   MATT YOHO




class WidgetController < AppController

 before_filter :find_widget, :only =>
  [:show, :edit, :update]

 def find_widget
  @widget ||= Widget.find(params[:id])
 end
end
CUCARUBA!   MATT YOHO




class WidgetController < AppController

  assume :widget

end
CUCARUBA!   MATT YOHO




class WidgetController < AppController

 def user_accout
  current_user.account
 end
 hide_action :user_account
 helper_method :user_account
end
CUCARUBA!   MATT YOHO




class WidgetController < AppController

 assume(:account) do
  current_user.account
 end
end
CUCARUBA!   MATT YOHO




                   Specs go a long way, but...
CUCARUBA!   MATT YOHO




                   Specs go a long way, but...


                        Rails dependencies, etc.
CUCARUBA!   MATT YOHO




                        Yuck.
CUCARUBA! MATT YOHO




      ~/projects/app/tmp/aruba
CUCARUBA! MATT YOHO




      ~/projects/app/tmp/aruba


                             ./tmp/aruba
                      rake
                      task
CUCARUBA! MATT YOHO




      ~/projects/app/tmp/aruba


                  templates          ./tmp/aruba
                              rake
                              task
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
   """
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
    """
CUCARUBA!   MATT YOHO




            A little slow, but totally badass.
CUCARUBA! MATT YOHO
CUCARUBA!   MATT YOHO




                         RVM and Bundler
                        are complimentary
CUCARUBA!   MATT YOHO




                 Be kind to your contributors
CUCARUBA!   MATT YOHO




                         Get
                        Forked
CUCARUBA! MATT YOHO




  http://github.com/aslakhellesoy/aruba

           http://github.com/rspec/rspec-
                         rails

              http://github.com/mattyoho/
                    basic_assumption
Thank you
Matt Yoho
matt@edgecase.com
@mattyoho

Cucaruba!

  • 1.
    Viva la Cucaruba! MattYoho @mattyoho
  • 2.
    CUCARUBA! MATT YOHO Integration testing for Rails gem plugins
  • 3.
    CUCARUBA! MATT YOHO Cucumber
  • 4.
  • 5.
    CUCARUBA! MATT YOHO cucumber features for command line apps
  • 6.
    CUCARUBA! MATT YOHO
  • 7.
    CUCARUBA! MATT YOHO YO DAWG! I heard you like features in your features so we put cukes in your cukes!
  • 8.
    CUCARUBA! MATT YOHO For example...
  • 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.
    CUCARUBA! MATT YOHO class WidgetController < AppController assume :widget end
  • 11.
    CUCARUBA! MATT YOHO class WidgetController < AppController def user_accout current_user.account end hide_action :user_account helper_method :user_account end
  • 12.
    CUCARUBA! MATT YOHO class WidgetController < AppController assume(:account) do current_user.account end end
  • 13.
    CUCARUBA! MATT YOHO Specs go a long way, but...
  • 14.
    CUCARUBA! MATT YOHO Specs go a long way, but... Rails dependencies, etc.
  • 15.
    CUCARUBA! MATT YOHO Yuck.
  • 16.
    CUCARUBA! MATT YOHO ~/projects/app/tmp/aruba
  • 17.
    CUCARUBA! MATT YOHO ~/projects/app/tmp/aruba ./tmp/aruba rake task
  • 18.
    CUCARUBA! MATT YOHO ~/projects/app/tmp/aruba templates ./tmp/aruba rake task
  • 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.
    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.
    CUCARUBA! MATT YOHO A little slow, but totally badass.
  • 22.
  • 23.
    CUCARUBA! MATT YOHO RVM and Bundler are complimentary
  • 24.
    CUCARUBA! MATT YOHO Be kind to your contributors
  • 25.
    CUCARUBA! MATT YOHO Get Forked
  • 26.
    CUCARUBA! MATT YOHO http://github.com/aslakhellesoy/aruba http://github.com/rspec/rspec- rails http://github.com/mattyoho/ basic_assumption
  • 27.

Editor's Notes

  • #3 What the heck is Cucaruba?!
  • #4 BDD integration testing framework
  • #5 Extension to Cucumber for command line apps
  • #6 Command line apps, eh...?
  • #7 RSpec is a command line app! Cucumber is a command line app!
  • #8 I heard you like features in your features so we put cukes in your cukes!
  • #9 A Rails gem plugin is a great thing to integration test. Particularly in an automated way.
  • #10 Common controller idiom.
  • #11 Much cleaner.
  • #12 Another common idiom.
  • #13 Cleaner again.
  • #15 Getting Rails components into your specs can be painful, and mocking them out entirely is asking for unpleasant surprises.
  • #16 It gets painful.
  • #17 Aruba operates in tmp/aruba relative to your project root. This directory must exist for Aruba to run!
  • #18 Rake tasks to set up a Rails app in the working directory.
  • #19 Copy in your templates or do other setup work to put the app into a testable state.
  • #20 Example Cucumber feature using Aruba steps. Aruba is oriented around file reads and writes and command line input and output.
  • #21 &amp;#x201C;foo.feature&amp;#x201D; will be created by Aruba.
  • #22 Just like a two-headed turtle.
  • #23 It makes for, at the least, a great some testing option.
  • #24 RVM gemsets and Bundler dependency management assist in automating the process of setting up a development sandbox for developing your library.
  • #25 This makes for a happier contributor experience...
  • #26 ...which leads to more contributors.
  • #27 Aruba itself, and a great example of using it can be found in rspec/rspec-rails. It also is used in BasicAssumption.