??????????YOW Melbourne?????????????μ????Щ???????Щ?????@coreyhaines?? @rains???????TDD(????????????)??????????????????????????????????????????????(?????????2010????????????)?????????????????????????linux????????????Rspec???????????????????????д????????????(??????????????:))????????????????????????????????????????????????????????????????????д???????????????????


???????С???????????

????????д??????????????????????????????????????????Щ????????????????????:) ?????????д?????????????????????????????????????

1   describe "some test" do
2   it "should be true" do
3   true.should == true
4   end
5
6   it "should show that an expression can be true" do
7   (5 == 5).should == true
8    end
9
10   it "should be failing deliberately" do
11   5.should == 6
12   end
13   end

??  ????????????????????????????Rspec???????????д?Щ?????????????

?????????RSpec ????????? Ruby ????????????????????й??????????淶???ù淶?????????????????????????

?????????????????

?????????????????á?describe????????????μ??????????????????describe?? block?????κε??(???磬???????)???????????Ruby????????????puts????????Kernel block?У??????????κε?????(???Object???????Kernel????Ruby?е?????????????Object??)?????????????describe???Kernel block????????????????)??

1   module Kernel
2   def describe(description?? &block)
3   tests = Dsl.new.parse(description?? block)
4   tests.execute
5   end
6   end
 
 ?????Ruby block??Ruby?????block????????????????   

?????????????????describe?????????????????????????????????????????block???????????????????????describe?????????(???磬??it?? block)??????????????Dsl????????parse??????????????block???????????????????????????в????????????????????硣Dsl??????????????

1   class Dsl
2   def initialize
3   @tests = {}
4   end
5   def parse(description?? block)
6   self.instance_eval(&block)
7   Executor.new(description?? @tests)
8   end
9   def it(description?? &block)
10  @tests[description] = block
11  end
12  end