Pat Maddox wrote: > On Sat, Jan 17, 2009 at 6:48 AM, Ed Keith <li...@ruby-forum.com> wrote:
> What about...Ruby? > > I think it would make a lot of sense to define a couple hashes/objects > that represent each compiler. If you're just using different strings, > you can use a hash. > > gcc = {:name => 'gcc', :command => 'gcc', :flags => '...'} > pcc = {:name => 'pcc', :command => 'pcc', :flags => '...'} > watcom = {:name => 'watcom', :command => 'wcm', :flags => '...'} > > [gcc, pcc, watcom].each do |compiler| > describe "#{compiler[:name] compiler" do > it "should build the binary" do > Dir.chdir(project_dir) { exec "make > COMPILER=#{compiler[:command]} FLAGS='#{compiler[:flags]}" } > build_binary.exit_code.should == 0 > end > end > > You probably wouldn't put the compiler definitions right in there, but > you could if you wanted to. But putting them in another file is easy > and good. > > If you need more complex setup, create helper classes. > > class GccCompiler > def setup > # create some files... > end > > def name; "gcc" end > def command; "gcc" end > end > > Same thing then, you create a new instance of each of these classes, > iterate through, call their setup method, etc. > > Pat This is close to what I was thinking of, but I am doing the compilation inside RSpec. My specifications look like this: it 'fail to compile if foo is assigned to int' do x = system ENV[COMPILER] test_int_assign_fail.cpp x.should_not == 0 end it 'allow use of foo as bool' do x = system ENV[COMPILER] test_use_as_bool.cpp x.should == 0 x = system test_use_as_bool x.should == 0 end My shell script or batch file sets the environment variables needed to compile. My problem is that I do not like the following line in Ruby : system spec spec1.rb it looks very inefficient, so I am looking for a better solution. -EdK -- Posted via http://www.ruby-forum.com/. _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users