Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- describe Array do
- it "maintains a list of values and its size" do
- a = []
- a.size.should == 0
- (1..10).each do |i|
- a << i
- a.size.should == i
- end
- end
- it "has a shorter syntax for specifying values" do
- a = %w{ four score and seven years ago }
- a[1].should == "score"
- a.size.should == 6
- end
- end
- describe String do
- it "has a convenient syntax for specifying without needing backslashes" do
- s = %Q{ No need to backslash ' or "! }
- s.index('\'').should be > 0
- s.index("\"").should be > 0
- s.should match /' or "/
- end
- it "can do replacement based on string or Regexp" do
- s = "John Blanco is one cool guy."
- s.gsub("cool", "geeky").should match /one geeky guy.\z/
- s.gsub(/o/, "0").should_not match /o/
- end
- it "can calculate successions" do
- "123".succ.should == "124"
- "ABC".next.should == "ABD"
- end
- end
- describe Regexp do
- it "matches the standard classes" do
- s = "I've got 99 problems and a b**** ain't one."
- s.index(/\d+/).should == 9
- s.index(/\*/).should == 28
- s.index(/z/).should == nil
- s.index(/'/).should == 1
- end
- it "can handle multi-line strings" do
- s = "everytime you drop the bomb\nyou kill the god your child has born"
- s.index(/bomb.you/m).should_not == nil
- (s =~ /bomb.you/m).should_not == nil
- (s =~ /bomb$/m).should_not == nil
- (s =~ /bomb\z/m).should == nil
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement