From 3d377454dbeb9ab9fc0a4d491498c237e33e8d4b Mon Sep 17 00:00:00 2001 From: eparreno Date: Mon, 15 Nov 2010 19:21:40 +0100 Subject: remove old school validations and replaced with new validates method. Pending: fix active_record guide --- railties/guides/source/testing.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source/testing.textile') diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile index 3d4f31cc5d..c292a5d83b 100644 --- a/railties/guides/source/testing.textile +++ b/railties/guides/source/testing.textile @@ -315,7 +315,7 @@ Now to get this test to pass we can add a model level validation for the _title_ class Post < ActiveRecord::Base - validates_presence_of :title + validates :title, :presence => true end -- cgit v1.2.3 From 638b409eb4c75b9187c6cedc9f71e2e38ec84731 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 5 Dec 2010 09:46:52 -0800 Subject: fixed typo in test method name --- railties/guides/source/testing.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides/source/testing.textile') diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile index c292a5d83b..c9109a0ddf 100644 --- a/railties/guides/source/testing.textile +++ b/railties/guides/source/testing.textile @@ -183,7 +183,7 @@ class PostTest < ActiveSupport::TestCase The +PostTest+ class defines a _test case_ because it inherits from +ActiveSupport::TestCase+. +PostTest+ thus has all the methods available from +ActiveSupport::TestCase+. You'll see those methods a little later in this guide. -def test_truth +def test_the_truth Any method defined within a +Test::Unit+ test case that begins with +test+ (case sensitive) is simply called a test. So, +test_password+, +test_valid_password+ and +testValidPassword+ all are legal test names and are run automatically when the test case is run. @@ -256,7 +256,7 @@ This will run all the test methods from the test case. Note that +test_helper.rb You can also run a particular test method from the test case by using the +-n+ switch with the +test method name+. -$ ruby -Itest test/unit/post_test.rb -n test_truth +$ ruby -Itest test/unit/post_test.rb -n test_the_truth Loaded suite unit/post_test Started -- cgit v1.2.3 From f0580bd84c33479edce9081dfc53d1fcf6d879a1 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 11 Dec 2010 00:19:14 +0100 Subject: testing guide: revises explanation of the test macro --- railties/guides/source/testing.textile | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'railties/guides/source/testing.textile') diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile index c9109a0ddf..d7088dc04c 100644 --- a/railties/guides/source/testing.textile +++ b/railties/guides/source/testing.textile @@ -182,21 +182,27 @@ class PostTest < ActiveSupport::TestCase The +PostTest+ class defines a _test case_ because it inherits from +ActiveSupport::TestCase+. +PostTest+ thus has all the methods available from +ActiveSupport::TestCase+. You'll see those methods a little later in this guide. - -def test_the_truth - - Any method defined within a +Test::Unit+ test case that begins with +test+ (case sensitive) is simply called a test. So, +test_password+, +test_valid_password+ and +testValidPassword+ all are legal test names and are run automatically when the test case is run. -Rails adds a +test+ method that takes a test name and a block. It generates a normal +Test::Unit+ test with method names prefixed with +test_+. +Rails adds a +test+ method that takes a test name and a block. It generates a normal +Test::Unit+ test with method names prefixed with +test_+. So, test "the truth" do - # ... + assert true end -This makes test names more readable by replacing underscores with regular language. +acts as if you had written + + +def test_the_truth + assert true +end + + +only the +test+ macro allows a more readable test name. You can still use regular method definitions though. + +NOTE: The method name is generated by replacing underscores with spaces. The result does not need to be a valid Ruby identifier though, the name may contain punctuation characters etc. That's because in Ruby technically any string may be a method name. Odd ones need +define_method+ and +send+ calls, but formally there's no restriction. assert true @@ -380,7 +386,7 @@ There are a bunch of different types of assertions you can use. Here's the compl |+assert( boolean, [msg] )+ |Ensures that the object/expression is true.| |+assert_equal( obj1, obj2, [msg] )+ |Ensures that +obj1 == obj2+ is true.| |+assert_not_equal( obj1, obj2, [msg] )+ |Ensures that +obj1 == obj2+ is false.| -|+assert_same( obj1, obj2, [msg] )+ |Ensures that +obj1.equal?(obj2)+ is true.| +|+assert_same( obj1, obj2, [msg] )+ |Ensures that +obj1.equal?(obj2)+ is true.| |+assert_not_same( obj1, obj2, [msg] )+ |Ensures that +obj1.equal?(obj2)+ is false.| |+assert_nil( obj, [msg] )+ |Ensures that +obj.nil?+ is true.| |+assert_not_nil( obj, [msg] )+ |Ensures that +obj.nil?+ is false.| @@ -388,7 +394,7 @@ There are a bunch of different types of assertions you can use. Here's the compl |+assert_no_match( regexp, string, [msg] )+ |Ensures that a string doesn't matches the regular expression.| |+assert_in_delta( expecting, actual, delta, [msg] )+ |Ensures that the numbers +expecting+ and +actual+ are within +delta+ of each other.| |+assert_throws( symbol, [msg] ) { block }+ |Ensures that the given block throws the symbol.| -|+assert_raise( exception1, exception2, ... ) { block }+ |Ensures that the given block raises one of the given exceptions.| +|+assert_raise( exception1, exception2, ... ) { block }+ |Ensures that the given block raises one of the given exceptions.| |+assert_nothing_raised( exception1, exception2, ... ) { block }+ |Ensures that the given block doesn't raise one of the given exceptions.| |+assert_instance_of( class, obj, [msg] )+ |Ensures that +obj+ is of the +class+ type.| |+assert_kind_of( class, obj, [msg] )+ |Ensures that +obj+ is or descends from +class+.| -- cgit v1.2.3 From c8baefbca369be2c7ed85264809b52f3b40a0770 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 11 Dec 2010 00:22:51 +0100 Subject: spaces with underscores, I mean --- railties/guides/source/testing.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source/testing.textile') diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile index d7088dc04c..733c8a755e 100644 --- a/railties/guides/source/testing.textile +++ b/railties/guides/source/testing.textile @@ -202,7 +202,7 @@ end only the +test+ macro allows a more readable test name. You can still use regular method definitions though. -NOTE: The method name is generated by replacing underscores with spaces. The result does not need to be a valid Ruby identifier though, the name may contain punctuation characters etc. That's because in Ruby technically any string may be a method name. Odd ones need +define_method+ and +send+ calls, but formally there's no restriction. +NOTE: The method name is generated by replacing spaces with underscores. The result does not need to be a valid Ruby identifier though, the name may contain punctuation characters etc. That's because in Ruby technically any string may be a method name. Odd ones need +define_method+ and +send+ calls, but formally there's no restriction. assert true -- cgit v1.2.3