public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Added test/do declaration style testing to ActiveSupport::TestCase [DHH 
via Jay Fields]
dhh (author)
Thu Jun 12 18:10:38 -0700 2008
commit  f74ba37f4e4175d5a1b31da59d161b0020b58e94
tree    fee4f0c757d26e5c0355f7ed5c086b1f81c9617a
parent  048ac3604cd46479002eaf7b1bb32770289580fc
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *Edge*
0
 
0
+* Added test/do declaration style testing to ActiveSupport::TestCase [DHH via Jay Fields]
0
+
0
 * Added Object#present? which is equivalent to !Object#blank? [DHH]
0
 
0
 * Added Enumberable#several? to encapsulate collection.size > 1 [DHH]
...
9
10
11
 
 
 
 
 
 
 
 
12
13
 
14
...
9
10
11
12
13
14
15
16
17
18
19
20
 
21
22
0
@@ -9,5 +9,13 @@ end
0
 
0
 module ActiveSupport
0
   class TestCase < Test::Unit::TestCase
0
+ # test "verify something" do
0
+ # ...
0
+ # end
0
+ def self.test(name, &block)
0
+ test_name = "test_#{name.gsub(/[\s]/,'_')}".to_sym
0
+ raise "#{test_name} is already defined in #{self}" if self.instance_methods.include?(test_name.to_s)
0
+ define_method(test_name, &block)
0
+ end
0
   end
0
-end
0
+end
0
\ No newline at end of file

Comments

  • seven1m Fri Jun 13 06:28:49 -0700 2008

    Interesting. This is something I had done in my tests that looks somewhat similar. Only that mine can have “unimplemented” tests.

    
    
    module TestExtensions
    def should(name, &block)
    if block_given?
    define_method 'test ' + name, &block
    else
    puts "Unimplemented: " + name
    end
    end
    end

    ActionController::TestCase.extend(TestExtensions)
    Test::Unit::TestCase.extend(TestExtensions)

  • tsaleh Fri Jun 13 06:54:51 -0700 2008

    Is there a reason for underscorizing the test names? doing the following is legal and more readable:

    @
    test_name = “test #{name}”.to_sym
    @

    With the current implementation, a test like:

    @
    test “User’s should return [:a, :b] on #to_book?”
    @

    (totally contrived) would produce a method like:

    @
    “test_User’s_should_return_[:a,]_on#to_book?”
    @

    instead of

    @
    test User’s should return [:a, :b] on #to_book?”
    @

  • tsaleh Fri Jun 13 06:55:36 -0700 2008

    ok, no idea how to format code blocks in github comments :-/

  • ymendel Sun Jun 15 17:07:45 -0700 2008

    Tammer: I learned that trick from you in shoulda, you nut.