Advertisement
ZaBlanc

Kata 8/29 Ruby Spec

Aug 29th, 2011
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.46 KB | None | 0 0
  1. describe Array do
  2.   it "maintains a list of values and its size" do
  3.     a = []
  4.     a.size.should == 0
  5.  
  6.     (1..10).each do |i|
  7.       a << i
  8.       a.size.should == i
  9.     end
  10.   end
  11.  
  12.   it "has a shorter syntax for specifying values" do
  13.     a = %w{ four score and seven years ago }
  14.    
  15.     a[1].should == "score"
  16.     a.size.should == 6
  17.   end
  18. end
  19.  
  20. describe String do
  21.   it "has a convenient syntax for specifying without needing backslashes" do
  22.     s = %Q{ No need to backslash ' or "! }
  23.  
  24.    s.index('\'').should be > 0
  25.     s.index("\"").should be > 0
  26.     s.should match /' or "/
  27.  end
  28.  
  29.  it "can do replacement based on string or Regexp" do
  30.    s = "John Blanco is one cool guy."
  31.  
  32.    s.gsub("cool", "geeky").should match /one geeky guy.\z/
  33.    s.gsub(/o/, "0").should_not match /o/
  34.  end
  35.  
  36.  it "can calculate successions" do
  37.    "123".succ.should == "124"
  38.    "ABC".next.should == "ABD"
  39.  end
  40. end
  41.  
  42. describe Regexp do
  43.  it "matches the standard classes" do
  44.    s = "I've got 99 problems and a b**** ain't one."
  45.    
  46.    s.index(/\d+/).should == 9
  47.    s.index(/\*/).should == 28
  48.    s.index(/z/).should == nil
  49.    s.index(/'/).should == 1
  50.   end
  51.  
  52.   it "can handle multi-line strings" do
  53.     s = "everytime you drop the bomb\nyou kill the god your child has born"
  54.    
  55.     s.index(/bomb.you/m).should_not == nil
  56.     (s =~ /bomb.you/m).should_not == nil
  57.     (s =~ /bomb$/m).should_not == nil
  58.     (s =~ /bomb\z/m).should == nil
  59.   end
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement