Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing ruby script

I'm creating a Ruby (not Rails) script and I have to test using standard Rails unit tests and Cucumber. I can't use RSpec.

So how do I test a ruby script with Cucumber and Rails Test::Unit? Is it possible?

like image 423
Alan Coromano Avatar asked Oct 25 '25 02:10

Alan Coromano


1 Answers

Here, I created a complete example including a Rakefile for convenience. The file structure is this:

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

In fact this example doesn't even use classes, so you can really test typical "Scripts" with it. File contents are here: http://pastebin.com/sJUP7VSA

So in the end you can do this:

$ 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

Cheers, Philip

like image 54
Philip Avatar answered Oct 26 '25 19:10

Philip



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!