method_info 0.1.10 → 0.1.11

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.10
1
+ 0.1.11
@@ -22,9 +22,12 @@ module MethodInfo
22
22
  # :punctuation_color Set colour for punctuation (only used when :enable_colors is true)
23
23
  # :suppress_slowness_warning Does not print out the warning about slowness on older ruby versions (default: false)
24
24
  # :match Shows only those methods that match this option. It's value can be either a string or a regexp (default: nil)
25
+
26
+ @@ruby_version_supports_owner_method = nil
27
+
25
28
  def self.build(object, options)
26
29
  # print warning message if a Method does not support the :owner method
27
- if !options[:suppress_slowness_warning] && ! Method.instance_methods.include?("owner")
30
+ if !options[:suppress_slowness_warning] && !ruby_version_supports_owner_method
28
31
  STDERR.puts "You are using a Ruby version (#{RUBY_VERSION}) that does not support the owner method of a Method - this may take a while. It will be faster for >=1.8.7."
29
32
  end
30
33
 
@@ -125,6 +128,12 @@ module MethodInfo
125
128
 
126
129
  private
127
130
 
131
+ def self.ruby_version_supports_owner_method
132
+ return @@ruby_version_supports_owner_method unless @@ruby_version_supports_owner_method.nil?
133
+ @@ruby_version_supports_owner_method =
134
+ Method.instance_methods.any? { |m| m.to_sym == :owner }
135
+ end
136
+
128
137
  def select_methods
129
138
  @methods = []
130
139
  @methods += @object.methods if @options[:public_methods]
@@ -50,7 +50,7 @@ module MethodInfo
50
50
 
51
51
  describe "with class hierarchy" do
52
52
  it "excludes the modules of a class that is excluded" do
53
- AncestorFilter.new([Fixnum, Integer, Precision, Numeric, Comparable, Object, Kernel],
53
+ AncestorFilter.new([Fixnum, Integer, Numeric, Comparable, Object, Kernel],
54
54
  :exclude => [Integer, Object]).picked.should ==
55
55
  [Fixnum, Numeric, Comparable]
56
56
  end
@@ -26,13 +26,27 @@ module MethodInfo
26
26
 
27
27
  describe "if a Method supports the :owner method" do
28
28
  before do
29
- Method.stub!(:instance_methods).and_return ["foo", "owner"]
29
+ AncestorMethodStructure.send(:class_variable_set,
30
+ '@@ruby_version_supports_owner_method',
31
+ nil)
30
32
  end
31
33
 
32
- it "should not print a warning message" do
34
+ it "should not print a warning message when instance methods are returned as strings" do
35
+ Method.stub!(:instance_methods).and_return ["foo", "owner"]
36
+ STDERR.should_not_receive :puts
37
+ AncestorMethodStructure.build(:foo, {})
38
+ end
39
+ it "should not print a warning message when instance methods are returned as symbols" do
40
+ Method.stub!(:instance_methods).and_return [:foo, :owner]
33
41
  STDERR.should_not_receive :puts
34
42
  AncestorMethodStructure.build(:foo, {})
35
43
  end
44
+ it "should not check for version more than once" do
45
+ Method.stub!(:instance_methods).and_return [:foo, :owner]
46
+ AncestorMethodStructure.build(:foo, {})
47
+ Method.should_not_receive(:instance_methods)
48
+ AncestorMethodStructure.build(:foo, {})
49
+ end
36
50
  end
37
51
  end
38
52
 
@@ -96,7 +110,7 @@ module MethodInfo
96
110
  describe "poor_mans_method_owner" do
97
111
  it "finds the owner if it is the base clas" do
98
112
  ams = AncestorMethodStructure.new(37, {})
99
- ams.send(:poor_mans_method_owner, 37.method(:rdiv), "rdiv").should == Fixnum
113
+ ams.send(:poor_mans_method_owner, 37.method(:abs), "abs").should == Fixnum
100
114
  end
101
115
 
102
116
  it "finds the owner if it is a super clas" do
@@ -106,7 +120,7 @@ module MethodInfo
106
120
 
107
121
  it "finds the owner if it is a module" do
108
122
  ams = AncestorMethodStructure.new(37, {})
109
- ams.send(:poor_mans_method_owner, 37.method(:prec), "prec").should == Precision
123
+ ams.send(:poor_mans_method_owner, 37.method(:is_a?), "is_a?").should == Kernel
110
124
  end
111
125
 
112
126
  it "finds the owner if it is the eigenclass" do
@@ -119,6 +133,7 @@ module MethodInfo
119
133
  end
120
134
 
121
135
  it "finds the owner if it is nested" do
136
+ pending "Spec needs to be fixed to work with 1.9.1" if RUBY_VERSION >= "1.9.1"
122
137
  module TestNestOne
123
138
  module TestNestTwo
124
139
  def nest
@@ -6,12 +6,12 @@ module MethodInfo
6
6
  describe "method_info" do
7
7
  it "passes the object it was called on to the option handler" do
8
8
  @obj = Object.new
9
- OptionHandler.should_receive(:handle).with(@obj, anything)
9
+ MethodInfo::OptionHandler.should_receive(:handle).with(@obj, anything)
10
10
  @obj.method_info
11
11
  end
12
12
 
13
13
  it "passes its options to the option handler" do
14
- OptionHandler.should_receive(:handle).with(anything, { :a => :one, :b => :two })
14
+ MethodInfo::OptionHandler.should_receive(:handle).with(anything, { :a => :one, :b => :two })
15
15
  Object.method_info(:a => :one, :b => :two)
16
16
  end
17
17
  end
@@ -28,12 +28,12 @@ module MethodInfo
28
28
  end
29
29
 
30
30
  it "uses a value from the default profile if an option was not passed" do
31
- MethodInfo::OptionHandler.stub!(:default_profile).and_return({ :mock_option, :mock_value })
31
+ MethodInfo::OptionHandler.stub!(:default_profile).and_return({ :mock_option => :mock_value })
32
32
  AncestorMethodStructure.should_receive(:build).with(anything, hash_including(:mock_option => :mock_value))
33
33
  MethodInfo::OptionHandler.handle(:object)
34
34
  end
35
35
  it "uses a value for an option if it was passed in" do
36
- MethodInfo::OptionHandler.stub!(:default_profile).and_return({ :mock_option, :mock_value })
36
+ MethodInfo::OptionHandler.stub!(:default_profile).and_return({ :mock_option => :mock_value })
37
37
  AncestorMethodStructure.should_receive(:build).with(anything, hash_including(:mock_option => :passed_value))
38
38
  MethodInfo::OptionHandler.handle(:object, :mock_option => :passed_value)
39
39
  end
@@ -4,7 +4,7 @@ require 'method_info'
4
4
  require 'spec'
5
5
  require 'spec/autorun'
6
6
 
7
- require 'ruby-debug'
7
+ require 'ruby-debug' if Gem.available?('ruby-debug')
8
8
 
9
9
  Spec::Runner.configure do |config|
10
10
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: method_info
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 11
9
+ version: 0.1.11
5
10
  platform: ruby
6
11
  authors:
7
12
  - Tom ten Thij
@@ -14,24 +19,30 @@ default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: rspec
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
23
31
  version: 1.2.9
24
- version:
32
+ type: :development
33
+ version_requirements: *id001
25
34
  - !ruby/object:Gem::Dependency
26
35
  name: cucumber
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
30
38
  requirements:
31
39
  - - ">="
32
40
  - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
33
43
  version: "0"
34
- version:
44
+ type: :development
45
+ version_requirements: *id002
35
46
  description: Defines a method_info method on every Object instance which provides information about methods that are defined on the object and the location where they were defined
36
47
  email: method_info@tomtenthij.nl
37
48
  executables: []
@@ -76,18 +87,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
87
  requirements:
77
88
  - - ">="
78
89
  - !ruby/object:Gem::Version
90
+ segments:
91
+ - 0
79
92
  version: "0"
80
- version:
81
93
  required_rubygems_version: !ruby/object:Gem::Requirement
82
94
  requirements:
83
95
  - - ">="
84
96
  - !ruby/object:Gem::Version
97
+ segments:
98
+ - 0
85
99
  version: "0"
86
- version:
87
100
  requirements: []
88
101
 
89
102
  rubyforge_project:
90
- rubygems_version: 1.3.5
103
+ rubygems_version: 1.3.6
91
104
  signing_key:
92
105
  specification_version: 3
93
106
  summary: Get info about an object's methods