2012-09-29 159 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 

乾杯,菲利普