Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for whiny nil #1476 [court3nay/marcel]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1507 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
- Loading branch information
Showing
2 changed files
with
20 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,38 @@ | ||
require 'test/unit' | ||
|
||
|
||
## mock to enable testing without activerecord | ||
# mock to enable testing without activerecord | ||
module ActiveRecord | ||
class Base | ||
def save! | ||
end | ||
end | ||
end | ||
|
||
require 'active_support/whiny_nil' | ||
|
||
|
||
require File.dirname(__FILE__) + '/../lib/active_support/inflector' | ||
require File.dirname(__FILE__) + '/../lib/active_support/whiny_nil' | ||
|
||
class WhinyNilTest < Test::Unit::TestCase | ||
def test_unchanged | ||
begin | ||
nil.method_thats_not_in_whiners | ||
rescue NoMethodError => nme | ||
assert_match(/nil:NilClass/, nme.message) | ||
end | ||
nil.method_thats_not_in_whiners | ||
rescue NoMethodError => nme | ||
assert_match(/nil:NilClass/, nme.message) | ||
end | ||
|
||
def test_active_record | ||
begin | ||
nil.save! | ||
rescue NoMethodError => nme | ||
assert(!(nme.message =~ /nil:NilClass/)) | ||
end | ||
nil.save! | ||
rescue NoMethodError => nme | ||
assert(!(nme.message =~ /nil:NilClass/)) | ||
end | ||
|
||
def test_array | ||
begin | ||
nil.each | ||
rescue NoMethodError => nme | ||
assert(!(nme.message =~ /nil:NilClass/)) | ||
end | ||
nil.each | ||
rescue NoMethodError => nme | ||
assert(!(nme.message =~ /nil:NilClass/)) | ||
end | ||
|
||
def test_id | ||
nil.id | ||
rescue RuntimeError => nme | ||
assert(!(nme.message =~ /nil:NilClass/)) | ||
end | ||
end | ||
end |