Bret,

That link you provided was the way to go allright. Here is my two scripts for 
anyone trying to ruby scripts to work with Nunit

*google.rb*
require 'watir'
include Watir
require 'test/unit'

class TestExampleTemplate < Test::Unit::TestCase 
  def test_search
    ie = IE.new
    ie.goto("http://www.google.com";)
    ie.text_field(:name, "q").set("pickaxe")
    ie.button(:value, "Google Search").click
    assert(ie.contains_text("Programming Ruby, 2nd Ed."))
  end
end

--------

*google.cs*
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using NUnit.Framework;

namespace Rap.Web.Test //rename to your namespace
{
    [TestFixture]
    public class TestGoogle
    {
        
        /// <summary>
        /// Verifies a valid Watir test will execute and allow success.
        /// </summary>
        [Test]
        [Category("Google")]
        public void Google()
        {
            WatirAssert.TestPassed("google.rb");
        }
    }

    public class WatirAssert
    {
        public static void TestPassed(string rubyFileName)
        {
            string output = String.Empty;
            using (Process p = new Process())
            {
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.FileName = "ruby.exe";
                p.StartInfo.Arguments = rubyFileName;
                p.StartInfo.WorkingDirectory = 
AppDomain.CurrentDomain.BaseDirectory;
                p.Start();
                output = p.StandardOutput.ReadToEnd();
                p.WaitForExit();
            }
            Console.Write(output);
            Trace.Write(output);
            Regex reg = new Regex(@"(?<tests>\d+) tests, (?<assertions>\d+) 
assertions, (?<failures>\d+) failures, (?<errors>\d+) errors", 
RegexOptions.Compiled);
            Match m = reg.Match(output);
            try
            {
                int tests = int.Parse(m.Groups["tests"].Value);
                int assertions = int.Parse(m.Groups["assertions"].Value);
                int failures = int.Parse(m.Groups["failures"].Value);
                int errors = int.Parse(m.Groups["errors"].Value);

                if (tests > 0 && failures > 0)
                {
                    Assert.Fail(String.Format("WatirAssert: Failures {0}", 
failures));
                }
                else if (errors > 0)
                {
                    Assert.Fail(String.Format("WatirAssert: Errors {0}", 
errors));
                }
            }
            catch(Exception e)
            {
                Assert.Fail("WatirAssert EXCEPTION: " + e.ToString());
            }
        }

    }
}
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to