[rspec-users] driving rspec from a Ruby script

David Chelimsky dchelimsky at gmail.com
Sat Jan 17 12:34:24 EST 2009

On Sat, Jan 17, 2009 at 8:48 AM, Ed Keith <lists at ruby-forum.com> wrote:
> Ashley Moran wrote:
>> On 16 Jan 2009, at 17:44, Ed Keith wrote:
>> You don't provide enough information for me to be sure, but what you
>> describe sounds sufficiently high-level enough to make Cucumber[1]
>> worth looking into.
>> If you search the archives of this list I posted a very bad example of
>> using Cucumber to spec binaries written in other languages (I used
>> sort, I think).
>> Ashley
>> [1] http://wiki.github.com/aslakhellesoy/cucumber
>> --
>> http://www.patchspace.co.uk/
>> http://aviewfromafar.net/
>> http://twitter.com/ashleymoran
> I looked at Cucumber, I'm not clear on what it does, but I do not think
> it is what I need.
> Going into the details: I am testing a C++ library. There are many test
> classes to test different aspects of the library. Some of the test cases
> as supposed to fail to compile when the library is misused. At first I
> used ruby to run the compilers and check the return value against 0 for
> success. For the tested that were supposed to fail to compile, that was
> all I needed. For the tests that were supposed to work I then ran the
> generated executable and tested the return value. So far everything is
> great.
> The library is supposed to be portable. So I am testing it with several
> different compilers on several different operating systems. I do not
> want to put platform specific information into the RSpec files, so I
> wrote shell scripts of Unix and batch files on windows to set up the
> environment for each compiler and then call RSpec with each
> configuration environment. Now I have two problems: 1) Batch language is
> real pain to do anything nontrivial in; 2) I have two sets of driver
> scripts to maintain.
> I should be able to solve both problems by using a portable scripting
> language for the driver scripts. My first thought was to use Python,
> since I know it. This will work, but there are two things that make me
> think it is suboptimal: 1) It will require that Python be installed on
> all test systems; 2) It will require that the python interpreter invoke
> the Ruby interpreter, this is very inefficient, not to mention ugly.
> I can easily solve the first problem by writing the driver scrips in
> Ruby since Ruby must be installed to run RSpec, and I intended to learn
> Ruby eventually anyway. My first, naive, attempt works, but I am running
> the ruby interpreter inside the ruby interpreter recursively when I call
> RSpec ("system spec spec1.rb"). There must be a better way to invoke
> RSpec without recursively invoking the Ruby interpreter.

You probably just need the spec command:

By default, it will load up any files in a directory (or its subs)
named xxx_spec.rb. So in this case, if you change spec1.rb to
xyz_spec.rb and stick it in an examples directory and type:

  spec examples

There are numerous command line options (described in the doc ref'd
above) to tweak the run and its output.

If those don't give you the flexibility you want, you can use the
SpecTask in a rake file:
http://rspec.info/documentation/tools/rake.html, which gives you a
place to write any arbitrary Ruby code you need to set up your
environment and then configure rspec to run in a variety of different


> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list