forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Object#peek as helper method to inspect object
So, instead of you having to do this: @user.tap{ |u| puts u.inspect }.activate! Now you can do: @user.peek.activate!
- Loading branch information
Showing
5 changed files
with
57 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Object | ||
# Call +#tap+ on the object, then print out the inspect version of the object to your standard | ||
# output. This is the shortcut for: +object.tap { |o| puts o.inspect }+ | ||
def peek | ||
tap { |object| puts object.inspect } | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'abstract_unit' | ||
require 'active_support/core_ext/object' | ||
|
||
class PeekTest < ActiveSupport::TestCase | ||
class Sister | ||
class << self | ||
def inspect | ||
"My Sister" | ||
end | ||
|
||
def cute? | ||
false | ||
end | ||
|
||
def name | ||
"Kirino" | ||
end | ||
end | ||
end | ||
|
||
def test_peek_on_nil | ||
assert_equal "nil\n", capture(:stdout) { nil.peek } | ||
end | ||
|
||
def test_peek_on_class | ||
assert_equal "My Sister\n", capture(:stdout) { Sister.peek } | ||
end | ||
|
||
def test_peek_on_string | ||
assert_equal "\"Kirino\"\n", capture(:stdout) { Sister.name.peek } | ||
end | ||
|
||
def test_peek_chain | ||
assert_equal "false\n", capture(:stdout) { | ||
assert_equal "FALSE", Sister.cute?.peek.to_s.upcase | ||
} | ||
end | ||
end |
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