Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion interesting test tool... looking for opinions.
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ryan Leavengood  
View profile  
 More options Aug 4 2005, 10:56 am
Newsgroups: comp.lang.ruby
From: "Ryan Leavengood" <mrc...@netrox.net>
Date: Thu, 4 Aug 2005 23:56:14 +0900
Local: Thurs, Aug 4 2005 10:56 am
Subject: Re: interesting test tool... looking for opinions.
Ryan Leavengood said:

> Another possible issue is the fact that there is no equivalent to Java
> annotations, though I've done some prototyping and figured out a way to
> fairly easily have the equivalent in Ruby, at least for methods.

I see there has been quite a few additional discussions of this. I decided
to code up a more thorough prototype of how Java method annotations could
be simulated in Ruby:

class Class
  attr_reader :configs, :groups, :test_methods
  def config(hash)
    @config_method = true
    @temp_configs = []
    hash.each do |key, value|
      if value
        @temp_configs << key
      end
    end
  end

  def test(hash)
    @test_method = true
    @current_groups = hash[:groups]
  end

  def method_added(method)
    if @config_method or @test_method
      if @current_groups
        @groups||={}
        @current_groups.each do |group|
          (@groups[group]||=[]) << method
        end
      end
      if @config_method
        @configs||={}
        @temp_configs.each do |config|
          (@configs[config]||=[]) << method
        end
      end
      if @test_method
        (@test_methods||=[]) << method
      end
    end
    @config_method = false
    @current_groups = nil
    @temp_configs=nil
    @test_method = false
  end
end

class Test
  config :before_test => true
  def setup
    puts "Test#setup called"
  end

  config :after_test => true
  def teardown
    puts "Test#teardown called"
  end

  test :groups => ['one']
  def test_method1
    puts "Test#test_method1 called"
  end

  test :groups => ['two']
  def test_method2
    puts "Test#test_method2 called"
  end
end

class Test2
  config :before_test => true
  def setup
    puts "Test2#setup called"
  end

  config :after_test => true
  def teardown
    puts "Test2#teardown called"
  end

  test :groups => ['one']
  def test_method1
    puts "Test2#test_method1 called"
  end

  test :groups => ['two']
  def test_method2
    puts "Test2#test_method2 called"
  end
end

def run_tests(tests, test_instance, test_class)
  tests.each do |method|
    if test_class.configs[:before_test]
      test_class.configs[:before_test].each do |config_method|
        test_instance.__send__(config_method)
      end
    end
    test_instance.__send__(method)
    if test_class.configs[:after_test]
      test_class.configs[:after_test].each do |config_method|
        test_instance.__send__(config_method)
      end
    end
  end
end

if $0 == __FILE__
  %w{Test Test2}.each do |klass|
    klass = Module.const_get(klass)
    test = klass.new
    run_tests(klass.test_methods, test, klass)
    klass.groups.each do |group, list|
      puts "\nTesting group #{group}:"
      run_tests(list, test, klass)
    end
    puts
  end
end
__END__

Ryan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.