Permalink
Browse files

Added test/do declaration style testing to ActiveSupport::TestCase [D…

…HH via Jay Fields]
  • Loading branch information...
dhh committed Jun 13, 2008
1 parent 048ac36 commit f74ba37f4e4175d5a1b31da59d161b0020b58e94
Showing with 11 additions and 1 deletion.
  1. +2 −0 activesupport/CHANGELOG
  2. +9 −1 activesupport/lib/active_support/test_case.rb
View
@@ -1,5 +1,7 @@
*Edge*
* Added test/do declaration style testing to ActiveSupport::TestCase [DHH via Jay Fields]
* Added Object#present? which is equivalent to !Object#blank? [DHH]
* Added Enumberable#several? to encapsulate collection.size > 1 [DHH]
@@ -9,5 +9,13 @@ class Test::Unit::TestCase #:nodoc:
module ActiveSupport
class TestCase < Test::Unit::TestCase
# test "verify something" do
# ...
# end
def self.test(name, &block)
test_name = "test_#{name.gsub(/[\s]/,'_')}".to_sym
raise "#{test_name} is already defined in #{self}" if self.instance_methods.include?(test_name.to_s)
define_method(test_name, &block)
end
end
end
end

4 comments on commit f74ba37

@seven1m

This comment has been minimized.

Show comment
Hide comment
@seven1m

seven1m Jun 13, 2008

Contributor

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)
Contributor

seven1m replied Jun 13, 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)
@tammersaleh

This comment has been minimized.

Show comment
Hide comment
@tammersaleh

tammersaleh Jun 13, 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,:b]on#tobook?”
@

instead of

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

tammersaleh replied Jun 13, 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,:b]on#tobook?”
@

instead of

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

@tammersaleh

This comment has been minimized.

Show comment
Hide comment
@tammersaleh

tammersaleh Jun 13, 2008

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

tammersaleh replied Jun 13, 2008

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

@ymendel

This comment has been minimized.

Show comment
Hide comment
@ymendel

ymendel Jun 16, 2008

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

ymendel replied Jun 16, 2008

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

Please sign in to comment.