Technology

RSpec Presentation

This is a zip of my RSpec presentation from Desert Code Camp this past weekend.

It includes all of my slides in the PDF, plus all of the supporting code.

Enjoy!

RSpec
Ruby on Rails
Technology
coding
desertcodecamp

Comments (0)

Permalink

RSpec cheatsheet

I couldn’t remember where I got this from, so I am posting it here. If anyone can help me figure out where this comes from I would love to give proper credit.

RSpec Cheat Sheet

RSpec
Ruby on Rails
Technology
coding

Comments (0)

Permalink

Growl, Autotest and RSpec 1.0.8

So I’ve finally gotten myself a mac. Well, actually my boss got one for me, but you get the point. Anyways, my coworkers and I were having problems with Autotest, RSpec, and Growl before the recent release. However, since 1.0.8 is a new version, we decided to try again. So far it’s worked. So with a big thanks to Daniel Fischer, I’d like to write up how.

How-to

Here’s how. First, get your essentials:

  • Growl
  • growlnotify
  • Zentest
  • Rspec

Second, download the following pictures:
rspec-okay
rspec-fail
rspec-pending

Third, copy the following into your .autotest file:

module Autotest::Growl
  def self.growl title, msg, img, pri=0, stick=""
    system "growlnotify -n autotest --image #{img} -p #{pri} -m #{ msg.inspect} #{title} #{stick}"
  end

  Autotest.add_hook :ran_command do |autotest|
    output = autotest.results.grep(/\d+\s.*examples?/).last.slice(/(\d+)\s.*examples?,\s(\d+)\s.*failures?(?:,\s(\d+)\s.*pending)?/)
    if output =~ /[1-9]\sfailures?/
      growl "Test Results", "#{output}", "~/Library/autotest/rails_fail.png", 2, "-s"
    elsif output =~ /pending/
      growl "Test Results", "#{output}", "~/Library/autotest/rails_pending.png"
    else
      growl "Test Results", "#{output}", "~/Library/autotest/rails_ok.png"
    end
  end
end

If you don’t already have one. Just save it to ~/.autotest. Replace the three image locations with your downloaded ones, and you should be good to go!

RSpec
Ruby on Rails
Technology
coding
productivity

Comments (9)

Permalink

Comment Driven Development

So on a reading trip about testing, I read about how certain parts of the aerospace industry practice TDD on the order of 4-to-1. Meaning 4 tests for every part of the system.

This got me thinking. We should start using Comment Driven Development*. How many lines of comment could we get in for each line of code. Just imagine how clear our code would be.

Example

Take this example:

jonny.go_to_store

Now, sure that is clear, but it could be better. Here it is with 100% CDD Coverage:

#Send jonny to the store
jonny.go_to_store

Even better is 200% CDD Coverage:

#Send jonny to the store, three blocks north and one block tothe left.
#he should get eggs, bacon and milk while he is there.
jonny.go_to_store.

Continue Reading »

Technology
coding
humor

Comments (0)

Permalink

RadRails Template Documentation

Ruby

  • alias – alias
  • atr – attribute reader
  • begin – begin rescue block
  • begin – begin rescue ensure block
  • block – do…end single variable block
  • block – do…end two variable block
  • block – single variable block
  • block – two variable block
  • case – case statement
  • class – Class Definition
  • class – class with initialize
  • class – Singleton Class Definition
  • def – def with params
  • def – method definition
  • defs – class method definition
  • each – each block
  • else – else block
  • elsif – elsif block
  • for – for – iterate over Collection
  • for – for – iterate over Range
  • if – if block
  • ifeif – ifelseif block
  • ifelse – if-else block
  • inject – inject block
  • lambda – lambda block
  • loop – loop block
  • module – Module definition
  • pp – plus plus
  • r – require
  • rescue – rescue block
  • rescue – rescue block with error variable
  • until – until loop
  • while – while loop
  • while – while statement

Get the ruby pack Here

Controller

  • rcea – render component action
  • rcec – render component controller
  • rceca – render component controller action
  • rea – redirect_to(action)
  • reai – redirect_to(action,id)
  • rec – redirect_to(controller,action)
  • reca – redirect_to(controller,action)
  • recai – redirect_to(controller,action,id)
  • reu – redirect_to(url)
  • verify – verify
  • verifyr – verify redirect

Get the controller pack here

Models

  • aal – acts_as_list
  • aat – acts_as_tree
  • bt – belongs to
  • bt – belongs to basic
  • find – find
  • find – find conditions order
  • find – find conditions order group
  • finda – find all
  • findf – find first
  • habtm – has and belongs to many
  • hm – has many complex
  • hm – has_many
  • ho – has one
  • ho – has one complex

Get the models pack here

Validation

  • va – validates_associated(attributes)
  • vaco – validates_acceptance_of(attribute,message)
  • vaif – validates associated if
  • vaon – validates_associated(attributes) on
  • vc – validates_confirmation_of(attributes,message)
  • vcif – validates confirmation of attribute on message if
  • vcon – validates_confirmation_of(attributes,message) on
  • ve – validates_exclusion_of(attribute,in,message)
  • veach – validates_each
  • veif – validates exclusion if
  • vf – validates_format_of(attribute,with,message)
  • vi – validates_inclusion_of(attribute,in,message)
  • vl – validates_length_of(attribute,maximum,message)
  • vl – validates_length_of(attribute,minimum,message)
  • vl – validates_length_of(attribute,range,message)
  • vn – validates numericality of
  • vp – validates_presence_of(attribute,message)
  • vpif – validates_presence_of(attribute,message)
  • vs – validates_size_of(attribute,maximum,message)
  • vs – validates_size_of(attribute,minimum,message)
  • vs – validates_size_of(attribute,range,message)
  • vu – validates_uniqueness_of(attribute,message)
  • vuif – validates_uniqueness_of(attribute,message)
  • vus – validates_uniqueness_of(attribute,message,scope)
  • vusif – validates_uniqueness_of(attribute,message,scope)

Get the validation pack here

Render

  • ra – render action
  • ral – render action,layout
  • rf – render(file)
  • rfu – render(file,use_full_path)
  • ri – render(inline)
  • ril – render(inline,locals)
  • rit – render(inline,type)
  • rl – render(layout)
  • rn – render(nothing)
  • rns – render(nothing,status)
  • rp – render(partial)
  • rpc – render(partial,collection)
  • rpl – render(partial,locals)
  • rpo – render(partial,object)
  • rps – render(partial,status)
  • rt – render text
  • rtl – render text layout
  • rtlt – render text layout true
  • rts – render text status

Get the render pack here

Environment

  • flash – flash[]
  • logi – logger info
  • logn – logger notice
  • logw – logger warning
  • p – params
  • s – session
  • sset – session setter

Get the environment pack here

Migration

  • mac – add column
  • mai – add index
  • mcc – change column
  • mct – create table
  • mdt – drop table
  • mex – execute
  • mnc – rename column
  • mrc – remove column
  • mri – remove index
  • mtc – t.column create

Get the migration pack here

Testing

  • ae – assert_equal
  • aio – assert instance of
  • ako – assert_kind_of
  • am – assert match
  • an – assert nil
  • ane – assert not equal
  • anm – assert not match
  • ann – assert_not_nil
  • ar – assert_raise
  • are – assert_response
  • aret – assert respond to
  • art – assert_redirected_to

Get the testing pack here

Rspec

  • cn – controller name
  • cshra – controller should have rendered action
  • cshrt – controller should have rendered text
  • cshrte – controller should have rendered template
  • csra – controller should render action
  • csrdt – controller should redirect to
  • csrr – controller should render rjs
  • csrrp – controller should render rjs page
  • csrt – controller should render text
  • csrte – controller should render template
  • rsbr – response should be redirect
  • rsbs – response should be success
  • sbe – should be empty
  • sbio – should be instance of
  • sbn – should be nil
  • sbs – should be something
  • se – should equal
  • sh – should have
  • shr – should have rjs
  • shrp – should have rjs page
  • sht – should have tag
  • shtc – should have tag content
  • sm – should match
  • snbe – should not be empty
  • sne – should not equal
  • snm – should not match
  • srt – should respond to
  • ss – should something

Get the rspec pack here

Rhtml

  • a – html link
  • at – attributes
  • cb – check box
  • cbt – check box tag
  • cfl – content for layout
  • comment – comment
  • div – div
  • ds – date select
  • dth1 – doctype xhtml 1.1
  • dthf – doctype 4 frameset
  • dths – doctype html strict
  • dtht – doctype html transitional
  • dtxf – doctype xhtml frameset
  • dtxs – doctype xhtml strict
  • dtxt – doctype xhtml transitional
  • emf – error message for
  • ff – file field
  • forin – for…in..end
  • frt – form_remote_tag(html)
  • ft – form_tag
  • hf – hidden field
  • hft – hidden field tag
  • htdoc – document outline
  • htt – http://
  • if – if block
  • ifei – if else if
  • ifeie – if else if else block
  • ifelse – if else block
  • img – image
  • ist – image submit tag
  • it – image tag
  • li – li
  • lia – link_to(action)
  • liai – link_to(action,id)
  • lic – link_to(controller)
  • lica – link_to(controller,action)
  • licai – link_to(controller,action,id)
  • link – link
  • ltr – link_to_remote(name,update,url)
  • meta – meta tag
  • metah – meta http equiv
  • ol – ol
  • pe – pe
  • pf – password field
  • pft – password field tag
  • pm – percent minus
  • pr – asp style script tags
  • pta – p text area
  • ptf – p text field
  • rb – radio button
  • rbt – radio button tag
  • rp – render partial
  • rpc – render partial collection
  • s – select
  • span – span
  • st – submit tag
  • style – style
  • ta – text area
  • table – table
  • tat – text area tag
  • td – td tag
  • tf – text field
  • tft – text field tag
  • trtd – tr and td
  • tt – closed tag
  • ul – ul

Get the rhtml pack here

Finally, documentation as promised. You can get the entire set of packs here as one zip file with all of the individual xml files inside. Or you can just download this zip and get it as two files. One for RHTML, and one for Ruby.

I’d also like to share my script for making this documentation. It should work for any Eclipse template file. Change the extension to .rb, and drop it in the directory with the xml files. Run it and it should create a txt file for each xml file in the directory. The text file is in textile and it is simply a h2 followed by a list of the templates. Enjoy

Ruby on Rails
Technology
coding
radrails

Comments (0)

Permalink