whats_up 1.1.4 → 1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +4 -0
- data/.gitignore +1 -0
- data/{README.md → README.rdoc} +14 -15
- data/Rakefile +19 -0
- data/lib/whats_up.rb +6 -51
- data/lib/whats_up/classic.rb +20 -10
- data/lib/whats_up/dummy_out.rb +5 -2
- data/lib/whats_up/frozen_section.rb +14 -2
- data/lib/whats_up/method_finder.rb +41 -31
- data/lib/whats_up/methods.rb +67 -0
- data/lib/whats_up/version.rb +1 -1
- data/spec/classic_spec.rb +12 -0
- data/spec/frozen_section_spec.rb +0 -1
- data/spec/methods_spec.rb +62 -0
- data/whats_up.gemspec +8 -1
- metadata +56 -3
data/.autotest
CHANGED
data/{README.md → README.rdoc}
RENAMED
@@ -1,12 +1,11 @@
|
|
1
|
-
whats\_up
|
2
|
-
=========
|
1
|
+
= whats\_up
|
3
2
|
|
4
|
-
This is a fork of Dr. Nic's excellent little
|
3
|
+
This is a fork of Dr. Nic's excellent little what_methods utility, updated a bit to expand
|
5
4
|
functionality and bring syntax a bit more in line with the Ruby status quo. It's actually been
|
6
5
|
batted around the internet for a while, with rough etchings dating to 2002. So this is my shot at
|
7
6
|
it.
|
8
7
|
|
9
|
-
|
8
|
+
<b>Dr. Nic says</b> (or is heard from echoes traversing the sands of time)<b>:</b>
|
10
9
|
|
11
10
|
This is from Dr. Nic. See http://drnicwilliams.com/2006/10/12/my-irbrc-for-consoleirb/
|
12
11
|
|
@@ -49,20 +48,20 @@ Just what you need in the console.
|
|
49
48
|
Notice the last example: you can pass parameters after the desired result. whats_up will tell you
|
50
49
|
what method will return the desired result if you pass those parameters to it.
|
51
50
|
|
52
|
-
|
51
|
+
<b>Bryan says:</b>
|
53
52
|
|
54
|
-
This modest little update retains the original
|
55
|
-
2006, before the Ruby community had a rough consensus that
|
56
|
-
false value (or at least something useable as such). I've aliased that method as
|
53
|
+
This modest little update retains the original +what?+ method, but that was from the halcyon days of
|
54
|
+
2006, before the Ruby community had a rough consensus that +?+ methods should be returning a true or
|
55
|
+
false value (or at least something useable as such). I've aliased that method as +what_equals+.
|
57
56
|
|
58
57
|
You can add arguments by either supplying additional arguments after the expected result or by using
|
59
|
-
the
|
58
|
+
the +given+ method. So the following two queries are equivalent:
|
60
59
|
|
61
60
|
5.given(1).what_equals 6
|
62
61
|
5.what_equals 6, 1
|
63
62
|
|
64
|
-
Note also the addition of helpers like
|
65
|
-
|
63
|
+
Note also the addition of helpers like +whats_exactly+, which will only find exact matches, and
|
64
|
+
+what_matches+, which will match a regular expression:
|
66
65
|
|
67
66
|
> 5.whats_exactly 5.0
|
68
67
|
5.to_f == 5.0
|
@@ -77,8 +76,8 @@ Note also the addition of helpers like `whats_exactly`, which will only find exa
|
|
77
76
|
"hello".oct == 0
|
78
77
|
=> {:length=>5, :size=>5, :bytesize=>5, :to_i=>0, :hex=>0, :oct=>0}
|
79
78
|
|
80
|
-
And if you just want to know everything, I've added
|
81
|
-
current methods and
|
79
|
+
And if you just want to know everything, I've added +what_works_with+ that lists the results of all
|
80
|
+
current methods and +whats_not_blank_with+ that ignores any false, falsy or empty values:
|
82
81
|
|
83
82
|
> "hello".what_works_with 2
|
84
83
|
"hello" <=> 2 == nil
|
@@ -99,5 +98,5 @@ current methods and `whats_not_blank_with` that ignores any false, falsy or empt
|
|
99
98
|
"hello".upto(2) == #<Enumerator: "hello":upto(2)>
|
100
99
|
# ...
|
101
100
|
|
102
|
-
In line with the original
|
103
|
-
like
|
101
|
+
In line with the original +what_methods+ gem, you can <tt>require "whats_up/classic"</tt> to enable
|
102
|
+
aliases like +what?+, +matches?+, +exactly?+, +works?+ and +not_blank?+.
|
data/Rakefile
CHANGED
@@ -1 +1,20 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
+
require "sdoc"
|
3
|
+
|
4
|
+
# Quick hack until SDoc gets fixed
|
5
|
+
class RDoc::Generator::SDoc; alias :basedir :base_dir; end
|
6
|
+
|
7
|
+
RDoc::Task.new do |rdoc|
|
8
|
+
rdoc.rdoc_dir = "doc/rdoc"
|
9
|
+
rdoc.title = "whats_up Documentation"
|
10
|
+
|
11
|
+
rdoc.options << "-f" << "sdoc" # format with SDoc
|
12
|
+
rdoc.options << "-T" << "rails" # use the Rails template
|
13
|
+
rdoc.options << "-c" << "utf-8"
|
14
|
+
rdoc.options << "-g" # link to GitHub
|
15
|
+
rdoc.options << "-m" << "README.rdoc" # use README.rdoc as main file
|
16
|
+
rdoc.options << "-v" # verbose
|
17
|
+
|
18
|
+
rdoc.rdoc_files.include "README.rdoc"
|
19
|
+
rdoc.rdoc_files.include "lib/**/*.rb"
|
20
|
+
end
|
data/lib/whats_up.rb
CHANGED
@@ -20,59 +20,14 @@
|
|
20
20
|
# http://www.doublegifts.com/pub/ruby/methodfinder.rb.html
|
21
21
|
# * Checks permutations of arguments
|
22
22
|
# http://www.doublegifts.com/pub/ruby/methodfinder2.rb.html
|
23
|
-
#
|
24
|
-
# Last updated: 2006/05/20
|
25
|
-
|
26
|
-
class Object
|
27
|
-
def given(*args)
|
28
|
-
if frozen?
|
29
|
-
WhatsUp::FrozenSection.new self, args: args
|
30
|
-
else
|
31
|
-
@args = args
|
32
|
-
self
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def what_equals(expected_result, *args, &block)
|
37
|
-
show_methods expected_result, {}, *args, &block
|
38
|
-
end
|
39
|
-
|
40
|
-
def whats_exactly(expected_result, *args, &block)
|
41
|
-
show_methods expected_result, { force_exact: true }, *args, &block
|
42
|
-
end
|
43
|
-
|
44
|
-
def what_matches(expected_result, *args, &block)
|
45
|
-
show_methods expected_result, { force_regex: true }, *args, &block
|
46
|
-
end
|
47
|
-
|
48
|
-
def what_works_with(*args, &block)
|
49
|
-
show_methods nil, { show_all: true }, *args, &block
|
50
|
-
end
|
51
|
-
alias :what_works :what_works_with
|
52
|
-
|
53
|
-
def whats_not_blank_with(*args, &block)
|
54
|
-
show_methods nil, { show_all: true, exclude_blank: true }, *args, &block
|
55
|
-
end
|
56
|
-
alias :whats_not_blank :whats_not_blank_with
|
57
|
-
|
58
|
-
# Make sure cloning doesn't cause anything to fail via type errors
|
59
|
-
alias_method :__clone__, :clone
|
60
|
-
def clone
|
61
|
-
__clone__
|
62
|
-
rescue TypeError
|
63
|
-
self
|
64
|
-
end
|
65
|
-
|
66
|
-
private
|
67
|
-
|
68
|
-
def show_methods(expected_result, opts = {}, *args, &block)
|
69
|
-
@args = args unless args.empty?
|
70
|
-
WhatsUp::MethodFinder.show(self, expected_result, opts, *@args, &block)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
23
|
module WhatsUp
|
24
|
+
autoload :Classic, "whats_up/classic"
|
75
25
|
autoload :DummyOut, "whats_up/dummy_out"
|
76
26
|
autoload :FrozenSection, "whats_up/frozen_section"
|
77
27
|
autoload :MethodFinder, "whats_up/method_finder"
|
28
|
+
autoload :Methods, "whats_up/methods"
|
29
|
+
end
|
30
|
+
|
31
|
+
class Object # :nodoc:
|
32
|
+
include WhatsUp::Methods
|
78
33
|
end
|
data/lib/whats_up/classic.rb
CHANGED
@@ -1,15 +1,25 @@
|
|
1
1
|
require "whats_up"
|
2
2
|
|
3
|
-
class Object
|
4
|
-
alias :what? :what_equals
|
5
|
-
alias :exactly? :whats_exactly
|
6
|
-
alias :matches? :what_matches
|
7
|
-
alias :works? :what_works_with
|
8
|
-
alias :not_blank? :whats_not_blank_with
|
9
|
-
end
|
10
|
-
|
11
3
|
module WhatsUp
|
12
|
-
|
13
|
-
|
4
|
+
# This module contains the original +what?+ method, as well as some aliases for newer methods. In
|
5
|
+
# line with the current expectation that a Ruby method ending in +?+ returns a true or false value
|
6
|
+
# (or at least something truthy or falsy), I've decided not to make +what?+ and it's brethren the
|
7
|
+
# default. You can include them by:
|
8
|
+
#
|
9
|
+
# require "whats_up/classic"
|
10
|
+
#
|
11
|
+
# or, if whats_up is already loaded:
|
12
|
+
#
|
13
|
+
# WhatsUp::Classic # which triggers whats_up/classic to autoload
|
14
|
+
module Classic
|
15
|
+
alias :what? :what_equals
|
16
|
+
alias :exactly? :whats_exactly
|
17
|
+
alias :matches? :what_matches
|
18
|
+
alias :works? :what_works_with
|
19
|
+
alias :not_blank? :whats_not_blank_with
|
14
20
|
end
|
15
21
|
end
|
22
|
+
|
23
|
+
class Object # :nodoc:
|
24
|
+
include WhatsUp::Classic
|
25
|
+
end
|
data/lib/whats_up/dummy_out.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
module WhatsUp
|
2
2
|
# A class to suppress anything that would normally output to $stdout
|
3
3
|
class DummyOut
|
4
|
-
# Does nothing (instead of writing to
|
5
|
-
def write(*args)
|
4
|
+
# Does nothing (instead of writing to an IO stream)
|
5
|
+
def write(*args)
|
6
|
+
end
|
7
|
+
alias :print :write
|
8
|
+
alias :puts :write
|
6
9
|
end
|
7
10
|
end
|
@@ -1,5 +1,15 @@
|
|
1
1
|
module WhatsUp
|
2
|
+
# A classic designed to allow variables to be stored along with a frozen object.
|
3
|
+
#
|
4
|
+
# Frozen objects can't have new instance variables added directly, so this prevents whats_up
|
5
|
+
# methods from being locked out of inspecting anything frozen. This proxy class should be
|
6
|
+
# initialized automatically if whats_up detects that the object it's to inspect is frozen.
|
2
7
|
class FrozenSection
|
8
|
+
# The frozen object
|
9
|
+
attr_reader :object
|
10
|
+
|
11
|
+
# Creates a new FrozenSection object from the provided +object+ and a list of instance variables
|
12
|
+
# to store
|
3
13
|
def initialize(object, vars = {})
|
4
14
|
@object = object
|
5
15
|
vars.each do |key, value|
|
@@ -9,9 +19,11 @@ module WhatsUp
|
|
9
19
|
|
10
20
|
private
|
11
21
|
|
12
|
-
|
22
|
+
# An override of Methods#show_methods that passes the object stored in <tt>@object</tt> instead of
|
23
|
+
# +self+
|
24
|
+
def show_methods(expected_result, opts = {}, *args, &block) # :doc:
|
13
25
|
@args = args unless args.empty?
|
14
|
-
|
26
|
+
MethodFinder.show(@object, expected_result, opts, *@args)
|
15
27
|
end
|
16
28
|
end
|
17
29
|
end
|
@@ -1,46 +1,60 @@
|
|
1
1
|
module WhatsUp
|
2
|
+
# A singleton class used to iterate over the methods of an object trying to match any returned
|
3
|
+
# values with an expected result. ny matches will then be pretty printed to the console.
|
2
4
|
class MethodFinder
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
# A list of symbols indicated which methods to always ignore
|
6
|
+
@@blacklist = %w(daemonize debug debugger display ed emacs exactly? exec exit! fork given
|
7
|
+
matches? mate nano not_blank? sleep stub stub! stub_chain syscall system unstub
|
8
|
+
unstub! vi vim what? what_equals what_matches what_works what_works_with
|
9
|
+
whats_exactly whats_not_blank whats_not_blank_with works?).map(&:to_sym)
|
10
|
+
|
11
|
+
# A list of symbols for infix operators for which Ruby has special syntax
|
6
12
|
@@infixes = %w(+ - * / % ** == != =~ !~ !=~ > < >= <= <=> === & | ^ << >>).map(&:to_sym)
|
7
|
-
@@prefixes = %w(+@ -@ ~ !).map(&:to_sym)
|
8
13
|
|
9
|
-
|
10
|
-
|
11
|
-
@args = args
|
12
|
-
end
|
13
|
-
def ==(val)
|
14
|
-
MethodFinder.show(@obj, val, *@args)
|
15
|
-
end
|
14
|
+
# A list of symbols for prefix operators for which Ruby has special syntax
|
15
|
+
@@prefixes = %w(+@ -@ ~ !).map(&:to_sym)
|
16
16
|
|
17
17
|
class << self
|
18
|
+
# Builds a lambda for checking against the provided +expected_result+ given a hash of options.
|
19
|
+
# Given the value of a method, the result of this lambda will determine whether that method
|
20
|
+
# and value are included in the output of a whats_up method.
|
21
|
+
#
|
22
|
+
# ==== Options
|
23
|
+
#
|
24
|
+
# * <tt>:exclude_blank</tt> - Exclude blank values
|
25
|
+
# * <tt>:force_exact</tt> - Force values to be exactly equal
|
26
|
+
# * <tt>:force_regex</tt> - Coerce the +expected_result+ into a regular expression for pattern
|
27
|
+
# matching
|
28
|
+
# * <tt>:show_all</tt> - Show the results of all methods
|
18
29
|
def build_check_lambda(expected_result, opts = {})
|
19
30
|
if opts[:force_regex]
|
20
31
|
expected_result = Regexp.new(expected_result.to_s) unless expected_result.is_a?(Regexp)
|
21
|
-
->
|
32
|
+
->(value) { expected_result === value.to_s }
|
22
33
|
elsif expected_result.is_a?(Regexp) && !opts[:force_exact]
|
23
|
-
->
|
34
|
+
->(value) { expected_result === value.to_s }
|
24
35
|
elsif opts[:force_exact]
|
25
|
-
->
|
36
|
+
->(value) { expected_result.eql?(value) }
|
26
37
|
elsif opts[:show_all]
|
27
38
|
if opts[:exclude_blank]
|
28
|
-
->
|
39
|
+
->(value) { !value.nil? && !(value.respond_to?(:empty?) && value.empty?) }
|
29
40
|
else
|
30
|
-
->
|
41
|
+
->(value) { true }
|
31
42
|
end
|
32
43
|
else
|
33
|
-
->
|
44
|
+
->(value) { expected_result == value }
|
34
45
|
end
|
35
46
|
end
|
36
47
|
|
37
|
-
# Find all methods on
|
48
|
+
# Find all methods on +an_object+ which, when called with +args+ return +expected_result+
|
38
49
|
def find(an_object, expected_result, opts = {}, *args, &block)
|
39
50
|
check_result = build_check_lambda(expected_result, opts)
|
40
51
|
|
41
52
|
# Prevent any writing to the terminal
|
42
53
|
stdout, stderr = $stdout, $stderr
|
43
|
-
$stdout
|
54
|
+
unless $stdout.is_a?(DummyOut)
|
55
|
+
$stdout = $stderr = DummyOut.new
|
56
|
+
restore_std = true
|
57
|
+
end
|
44
58
|
|
45
59
|
# Use only methods with valid arity that aren't blacklisted
|
46
60
|
methods = an_object.methods
|
@@ -48,8 +62,8 @@ module WhatsUp
|
|
48
62
|
|
49
63
|
# Collect all methods equaling the expected result
|
50
64
|
results = methods.inject({}) do |res, name|
|
65
|
+
stdout.print ""
|
51
66
|
begin
|
52
|
-
stdout.print ""
|
53
67
|
value = an_object.clone.method(name).call(*args, &block)
|
54
68
|
res[name] = value if check_result.call(value)
|
55
69
|
rescue
|
@@ -58,11 +72,11 @@ module WhatsUp
|
|
58
72
|
end
|
59
73
|
|
60
74
|
# Restore printing to the terminal
|
61
|
-
$stdout, $stderr = stdout, stderr
|
75
|
+
$stdout, $stderr = stdout, stderr if restore_std
|
62
76
|
results
|
63
77
|
end
|
64
78
|
|
65
|
-
# Pretty
|
79
|
+
# Pretty prints the results of #find
|
66
80
|
def show(an_object, expected_result, opts = {}, *args, &block)
|
67
81
|
opts = {
|
68
82
|
exclude_blank: false,
|
@@ -71,13 +85,11 @@ module WhatsUp
|
|
71
85
|
show_all: false
|
72
86
|
}.merge(opts)
|
73
87
|
|
74
|
-
found
|
88
|
+
found = find(an_object, expected_result, opts, *args, &block)
|
75
89
|
prettified = prettify_found(an_object, found, *args)
|
76
90
|
max_length = prettified.map { |k, v| k.length }.max
|
77
91
|
|
78
|
-
prettified.each
|
79
|
-
puts "#{key.ljust max_length} == #{value}"
|
80
|
-
end
|
92
|
+
prettified.each { |k, v| puts "#{k.ljust max_length} == #{v}" }
|
81
93
|
|
82
94
|
found
|
83
95
|
end
|
@@ -85,11 +97,9 @@ module WhatsUp
|
|
85
97
|
private
|
86
98
|
|
87
99
|
# Pretty prints a method depending on whether it's an operator, has arguments, is array/hash
|
88
|
-
# syntax, etc.
|
89
|
-
#
|
90
|
-
#
|
100
|
+
# syntax, etc.
|
91
101
|
def prettify_found(an_object, found, *args)
|
92
|
-
args = args.map { |
|
102
|
+
args = args.map { |a| a.inspect }.join(", ")
|
93
103
|
pretty_object = truncate_inspect(an_object, to: 40)
|
94
104
|
|
95
105
|
found.map do |key, value|
|
@@ -119,7 +129,7 @@ module WhatsUp
|
|
119
129
|
|
120
130
|
if full.length > max_length
|
121
131
|
available_length = max_length - 5 # to account for the " ... "
|
122
|
-
left_cutoff = available_length * 2 / 3
|
132
|
+
left_cutoff = available_length * 2 / 3
|
123
133
|
right_cutoff = available_length - left_cutoff - 1
|
124
134
|
|
125
135
|
"#{full[0..left_cutoff]} ... #{full[-right_cutoff..-1]}"
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module WhatsUp
|
2
|
+
# The methods added to all objects by whats_up
|
3
|
+
module Methods
|
4
|
+
# Provides a list of arguments that will be used when trying to find matching methods.
|
5
|
+
#
|
6
|
+
# 5.given(1).what_equals 6
|
7
|
+
# # => 5 + 1 == 6
|
8
|
+
def given(*args)
|
9
|
+
if frozen?
|
10
|
+
FrozenSection.new self, args: args
|
11
|
+
else
|
12
|
+
@args = args
|
13
|
+
self
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Outputs a list of methods and their values that equal an +expected_result+, allowing for some
|
18
|
+
# coercion (e.g. <tt>5 == 5.0</tt>)
|
19
|
+
def what_equals(expected_result, *args, &block)
|
20
|
+
show_methods expected_result, {}, *args, &block
|
21
|
+
end
|
22
|
+
|
23
|
+
# Outputs a list of methods and their values that exactly equal an +expected_result+
|
24
|
+
def whats_exactly(expected_result, *args, &block)
|
25
|
+
show_methods expected_result, { force_exact: true }, *args, &block
|
26
|
+
end
|
27
|
+
|
28
|
+
# Outputs a list of methods and their values that match an +expected_result+, which is coerced
|
29
|
+
# into a regular expression if it's not already one
|
30
|
+
def what_matches(expected_result, *args, &block)
|
31
|
+
show_methods expected_result, { force_regex: true }, *args, &block
|
32
|
+
end
|
33
|
+
|
34
|
+
# Outputs a list of all methods and their values
|
35
|
+
def what_works_with(*args, &block)
|
36
|
+
show_methods nil, { show_all: true }, *args, &block
|
37
|
+
end
|
38
|
+
alias :what_works :what_works_with
|
39
|
+
|
40
|
+
# Outputs a list of all methods and their values, provided they are not blank (nil, false,
|
41
|
+
# undefined, empty)
|
42
|
+
def whats_not_blank_with(*args, &block)
|
43
|
+
show_methods nil, { show_all: true, exclude_blank: true }, *args, &block
|
44
|
+
end
|
45
|
+
alias :whats_not_blank :whats_not_blank_with
|
46
|
+
|
47
|
+
# Make sure cloning doesn't cause anything to fail via type errors
|
48
|
+
alias_method :__clone__, :clone
|
49
|
+
|
50
|
+
# Adds in a type error check to the default Object#clone method to prevent any interruptions while
|
51
|
+
# checking methods. If a TypeError is encountered, +self+ is returned
|
52
|
+
def clone
|
53
|
+
__clone__
|
54
|
+
rescue TypeError
|
55
|
+
self
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
# Called by all of the +what_+ methods, this tells MethodFinder to output the result for any methods
|
61
|
+
# matching an +expected_result+ for the #given arguments
|
62
|
+
def show_methods(expected_result, opts = {}, *args, &block) # :doc:
|
63
|
+
@args = args unless args.empty?
|
64
|
+
MethodFinder.show(self, expected_result, opts, *@args, &block)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/whats_up/version.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
+
|
3
|
+
describe "WhatsUp::Classic" do
|
4
|
+
it "should not have any classic methods without Classic loaded" do
|
5
|
+
"hello".should_not respond_to(:what?)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should have classic methods with Classic loaded" do
|
9
|
+
require "whats_up/classic"
|
10
|
+
"hello".should respond_to(:what?)
|
11
|
+
end
|
12
|
+
end
|
data/spec/frozen_section_spec.rb
CHANGED
@@ -0,0 +1,62 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
+
|
3
|
+
describe Methods do
|
4
|
+
before :all do
|
5
|
+
@stderr, @stdout = $stderr, $stdout
|
6
|
+
$stderr = $stdout = DummyOut.new
|
7
|
+
end
|
8
|
+
|
9
|
+
after :all do
|
10
|
+
$stderr, $stdout = @stderr, @stdout
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "what_equals" do
|
14
|
+
it "should find the correct method without arguments" do
|
15
|
+
"hello ".what_equals("hello").should have_key(:rstrip)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should find the correct method with arguments" do
|
19
|
+
"hello".what_equals("e", 1).should have_key(:[])
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should find the correct method with arguments using given" do
|
23
|
+
"hello".given(1).what_equals("e").should have_key(:[])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "what_matches" do
|
28
|
+
it "should find the correct method given a regular expression" do
|
29
|
+
5.what_matches(/5/).should have_key(:to_s)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should find the correct method by converting an arbitrary object to a regular expression" do
|
33
|
+
5.what_matches(5).should have_key(:to_s)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "whats_exactly" do
|
38
|
+
it "should fail to match inexact matches that would succeed with == type coercion" do
|
39
|
+
5.whats_exactly(5.0).should_not have_key(:to_i)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should succeed for exact matches" do
|
43
|
+
5.whats_exactly(5.0).should have_key(:to_f)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "whats_not_blank" do
|
48
|
+
it "should include only non-blank values" do
|
49
|
+
5.whats_not_blank.select { |n| !n || n.empty? }.should be_empty
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "what_works" do
|
54
|
+
it "should produce all results found with whats_not_blank" do
|
55
|
+
works = 5.what_works
|
56
|
+
|
57
|
+
5.whats_not_blank.keys.each do |key|
|
58
|
+
works.should have_key(key)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/whats_up.gemspec
CHANGED
@@ -13,10 +13,17 @@ Gem::Specification.new do |s|
|
|
13
13
|
|
14
14
|
s.files = `git ls-files`.split("\n")
|
15
15
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
|
19
|
+
s.add_runtime_dependency "sdoc"
|
20
|
+
|
19
21
|
s.add_development_dependency "autotest"
|
20
22
|
s.add_development_dependency "bundler"
|
21
23
|
s.add_development_dependency "rspec"
|
24
|
+
|
25
|
+
if RUBY_PLATFORM =~ /darwin/
|
26
|
+
s.add_development_dependency "autotest-fsevent"
|
27
|
+
s.add_development_dependency "autotest-growl"
|
28
|
+
end
|
22
29
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whats_up
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: '1.2'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,8 +10,24 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-03-
|
13
|
+
date: 2012-03-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: sdoc
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
15
31
|
- !ruby/object:Gem::Dependency
|
16
32
|
name: autotest
|
17
33
|
requirement: !ruby/object:Gem::Requirement
|
@@ -60,6 +76,38 @@ dependencies:
|
|
60
76
|
- - ! '>='
|
61
77
|
- !ruby/object:Gem::Version
|
62
78
|
version: '0'
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: autotest-fsevent
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
type: :development
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: autotest-growl
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
63
111
|
description: Determine what methods can be called on an object that return a given
|
64
112
|
value
|
65
113
|
email:
|
@@ -73,15 +121,18 @@ files:
|
|
73
121
|
- .gitignore
|
74
122
|
- .rspec
|
75
123
|
- Gemfile
|
76
|
-
- README.
|
124
|
+
- README.rdoc
|
77
125
|
- Rakefile
|
78
126
|
- lib/whats_up.rb
|
79
127
|
- lib/whats_up/classic.rb
|
80
128
|
- lib/whats_up/dummy_out.rb
|
81
129
|
- lib/whats_up/frozen_section.rb
|
82
130
|
- lib/whats_up/method_finder.rb
|
131
|
+
- lib/whats_up/methods.rb
|
83
132
|
- lib/whats_up/version.rb
|
133
|
+
- spec/classic_spec.rb
|
84
134
|
- spec/frozen_section_spec.rb
|
135
|
+
- spec/methods_spec.rb
|
85
136
|
- spec/spec_helper.rb
|
86
137
|
- whats_up.gemspec
|
87
138
|
homepage: http://brymck.herokuapp.com/
|
@@ -109,5 +160,7 @@ signing_key:
|
|
109
160
|
specification_version: 3
|
110
161
|
summary: Determine what methods can be called on an object that return a given value
|
111
162
|
test_files:
|
163
|
+
- spec/classic_spec.rb
|
112
164
|
- spec/frozen_section_spec.rb
|
165
|
+
- spec/methods_spec.rb
|
113
166
|
- spec/spec_helper.rb
|