Rspec notes

Video from Efficient Rails Test-Driven Development by Walfram Amold

RSpec verifications

should respond_to
# works with any ? method so-called predicates
should be_nil
should be_valid
should_not be_nil; should_not be_valid
lambda{...}.should change(), {}, .from().to(), .by()
should eql, ==, equal

RSpec structure

before, before(:each), before(:all)
after, after(:each), after(:all)
describe do...end, nested
it do...end

Practical

$ rails address_book
$ cd address_book
$ script/generate rspec
$ script/generate rspec model Person first_name:string last_name:string

Specify/it and context/describe

"context" and "specify" are the aliases of "describe" and "it".

&:to_s

v.map(&:to_s)
# Is the same as:
v.map { |i| i.to_s }

Enumerable classes

This code will display all enumerable classes.

ObjectSpace.each_object(Class) {|cl| puts cl if cl < Enumerable}
Written on October 21, 2013