论坛首页 编程语言技术论坛

expectations——轻量级的单元测试框架

浏览 2048 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-02-16  

项目主页:http://expectations.rubyforge.org/

安装的话:gem install  expectations

它将测试分为state based和behavior based,语法很DSL,作者写了篇文章《implementing internal dsl in ruby

例子,

 

state base test:

        # State based expectation where a value equals another value
          expect 2 do
            1 + 1
          end 

          expect /a string/ do
            "a string"
          end

          # State based test checking if actual is in the expected Range
          expect 1..5 do
            3
          end

          # State based test to determine if the object is an instance of the module
          expect Enumerable do
            []
          end

          # State based test to determine if the object is an instance of the class
          expect String do
            "a string"
          end

          # State based test to determine if the modules are the same
          expect Enumerable do
            Enumerable
          end
  

 behavior based test:

         # Behavior based test using a traditional mock
          expect mock.to_receive(:dial).with("2125551212").times(2) do |phone|
            phone.dial("2125551212")
            phone.dial("2125551212")
          end

          # Behavior based test on a concrete mock
          expect Object.to_receive(:deal) do
            Object.deal
          end
 

 

   发表时间:2008-02-20  
That is really cool !
0 请登录后投票
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics