Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
测试ruby脚本_Ruby_Unit Testing_Cucumber - Fatal编程技术网

测试ruby脚本

测试ruby脚本,ruby,unit-testing,cucumber,Ruby,Unit Testing,Cucumber,我正在创建一个Ruby(不是Rails)脚本,我必须使用标准的Rails单元测试和Cucumber进行测试。我不能用RSpec 那么如何使用Cucumber和Rails test::Unit测试ruby脚本呢?有可能吗?为了方便起见,我在这里创建了一个完整的示例,包括一个耙子。文件结构如下所示: ./notepad.rb ./Rakefile ./test ./test/test_notepad.rb ./features ./features/add_note.feature ./featur

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


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

为了方便起见,我在这里创建了一个完整的示例,包括一个耙子。文件结构如下所示:

./notepad.rb
./Rakefile
./test
./test/test_notepad.rb
./features
./features/add_note.feature
./features/step_definitions
./features/step_definitions/add_note_step.rb
事实上,这个例子甚至不使用类,所以你可以用它来测试典型的“脚本”。文件内容如下:

所以最后你可以这样做:

$ 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

干杯,Philip

是的,这是可能的,对于cucumber来说,创建特征文件和步骤定义就足够了。确保步骤定义需要您想要测试的东西。您能告诉我如何做吗?很遗憾,我这里没有示例代码。最好的开始方式是使用页面上的六个步骤制作一个小型项目。feautere def必须具有文件结尾.feature,即步骤定义_step.rb IIRC。为什么不能使用RSpec?我有理由不在这种情况下使用它。