Skip to content

Instantly share code, notes, and snippets.

@cantremember
Created March 23, 2012 05:24
Show Gist options
  • Save cantremember/2167214 to your computer and use it in GitHub Desktop.
Save cantremember/2167214 to your computer and use it in GitHub Desktop.
coming up to speed with RSpec
specify "knowledge of nil" do
''.should_not be_nil
end
specify "numeric calculations" do
(355.0 / 113).should be_close(Math::PI, 0.1)
end
specify "changes made by a closure" do
array = []
lambda {
array << :a
}.should change(array, :size)
end
specify "equality" do
5.should eql 5
5.should equal 5
[:a].should_not equal [:a]
end
specify "raising of errors" do
# always construct fresh!!!
# otherwise it won't be re-wrappable
def raiser(s=nil)
lambda { raise(RuntimeError, s) if s }
end
raiser('x').should raise_error
raiser('y').should raise_error(RuntimeError, 'y')
end
specify "closure satisfaction" do
5.should satisfy {|n| (4..6).include?(n) }
end
specify "what lists do" do
[].should respond_to(:each, :find, :size)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment