2012-09-29 37 views
3

我创建了一个Ruby(不是Rails)脚本,我必须使用标准的Rails单元测试和Cucumber进行测试。我不能使用RSpec。测试ruby脚本

那么如何用Cucumber和Rails Test :: Unit测试ruby脚本呢?可能吗?

+0

是的,它是可能的,黄瓜应该足以创建特征文件和步骤定义。确保步骤定义需要你想测试的东西。 – Philip

+0

你能告诉我怎么做吗? –

+0

尤其是使用Cucumber –

回答

5

在这里,我创建了一个完整的示例,包括一个Rakefile以方便使用。文件结构是这样的:

./notepad.rb 
./Rakefile 
./test 
./test/test_notepad.rb 
./features 
./features/add_note.feature 
./features/step_definitions 
./features/step_definitions/add_note_step.rb 

其实这个例子中甚至不使用类,这样你就可以真正测试典型的“脚本”的程度。文件内容在这里:http://pastebin.com/sJUP7VSA

那么,到底你可以这样做:

$ rake test 
Finished tests in 0.001368s, 730.9942 tests/s, 1461.9883 assertions/s. 

1 tests, 2 assertions, 0 failures, 0 errors, 0 skips 

$ rake cucumber 
1 scenario (1 passed) 
2 steps (2 passed) 
0m0.002s 

干杯,菲利普