Fitnesse & Fit 和 Ruby。
Fitnesse, Fit and Ruby
昨天花了一些时间在这方面上。 Austin问能不能使用Fitnesse,所以试用了一下。
Fitnesse 是一个很优秀的测试工具。acceptance testing。
Fit 同上。
由于官方站点没有给出Ruby 相关的文档,只有Java 和 C#的(貌似),所以我就把安装和运行例子的过程记录了下来,供大家参考:
Due to no documents available for Ruby on "fitnesse" official website, I recorded my steps of installation and running its examples:
(references:
NOTE: guides on these 2 sites don't work and are out-of-date!
http://xprogramming.com/articles/rubyfitnesse/
http://blog.coryfoy.com/2005/12/fitnesse-and-ruby-a-basic-tutorial/
)
1. $sudo gem install fit
2. download the fitnesse.jar file (下载这个文件)
3. java -jar fitnesse.jar -p 8080
现在fitnesse 已经跑起来了。打开 localhost:8080, 发现它就是个wiki.
4. 随便编辑一个页面,末尾加上这句话: (edit anyone page, add this line to the end)
^ArithmeticFixture
5. 保存。刷新。打开这个新页面。 (save & fresh & open this new page)
6. 加入这个内容: (add these line of codes)
!define COMMAND_PATTERN {/usr/bin/ruby -I %p -I /usr/lib/ruby/gems/1.8/gems/fit-1.2/lib /usr/lib/ruby/gems/1.8/gems/fit-1.2/bin/FitServer.rb}!path "/usr/lib/ruby/gems/1.8/gems/fit-1.2/lib/eg"!|eg.ArithmeticFixture||x|y|+|-|*|/||1|1|2|0|1|1|
class ArithmeticFixture < Fit::PrimitiveFixture def initialize super @x = @y = 0 end def do_rows rows super(rows.more) # skip column heads end def do_cell cell, column_index case column_index when 0 then @x = parse_integer(cell); when 1 then @y = parse_integer(cell); when 2 then check(cell, parse_integer(cell), @x + @y) when 3 then check(cell, parse_integer(cell), @x - @y) when 4 then check(cell, parse_integer(cell), @x * @y) when 5 then check(cell, parse_integer(cell), @x / @y) else ignore(cell) end end