looksee 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d5b5cb3860af73f5d3800d9f580eecafa4c4f6f
4
- data.tar.gz: eafb21b450e03a9a1620937aa646013aa3684516
3
+ metadata.gz: b329abd3db89e86131b91f3d9fb3f7c6dfa84f6e
4
+ data.tar.gz: 07f340c3a34e5ca7a769c99cd0355030b70c2939
5
5
  SHA512:
6
- metadata.gz: 9be481e1b3359c05ec6be675284bf370dc9fecab2c9f42a6c6b81ecf454ed238b243111f48d5d17c1549afaf05cc06c44be4745bb0f64be31bd2de13526762c5
7
- data.tar.gz: c146b1c1b04970ae648d561eea58ef80e9cc9b309c8740a2696592284d360ac6ec60a45f7aa342c92dd14a057b0365ba79488b65d3e0c810a6c2d96e9a7a1cb7
6
+ metadata.gz: 369e6f4f8f4128b969b9e446190438d6eaa83a9815a42cf77fa3c86a7fa027c221b98ff439d4d6a9ade2ae17651712ade1fbb955260120e82e5465fc4a4f1000
7
+ data.tar.gz: 595ecc16a319e375a34159656c5c7ccb99fb4230641d97e7fdaab8bcfde66aa01ea724a72de583b8a8c35db9571b1c1b939e545b7693683e31d7b0e67e7928b1
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ == 2.1.1 2014-07-13
2
+
3
+ * Fix error for objects with an unnamed module in the lookup path.
4
+ * Fix editing for included methods.
5
+
1
6
  == 2.1.0 2014-03-05
2
7
 
3
8
  * Add alternative syntax: Looksee[object, *args]. Useful for BasicObject
data/ext/mri/mri.c CHANGED
@@ -213,6 +213,13 @@ VALUE Looksee_singleton_instance(VALUE self, VALUE singleton_class) {
213
213
  }
214
214
  }
215
215
 
216
+ VALUE Looksee_real_module(VALUE self, VALUE module_or_included_class) {
217
+ if (BUILTIN_TYPE(module_or_included_class) == T_ICLASS)
218
+ return RBASIC(module_or_included_class)->klass;
219
+ else
220
+ return module_or_included_class;
221
+ }
222
+
216
223
  VALUE Looksee_module_name(VALUE self, VALUE module) {
217
224
  if (BUILTIN_TYPE(module) == T_CLASS || BUILTIN_TYPE(module) == T_MODULE) {
218
225
  VALUE name = rb_mod_name(module);
@@ -294,6 +301,7 @@ void Init_mri(void) {
294
301
  rb_define_method(mMRI, "included_class?", Looksee_included_class_p, 1);
295
302
  rb_define_method(mMRI, "singleton_class?", Looksee_singleton_class_p, 1);
296
303
  rb_define_method(mMRI, "singleton_instance", Looksee_singleton_instance, 1);
304
+ rb_define_method(mMRI, "real_module", Looksee_real_module, 1);
297
305
  rb_define_method(mMRI, "module_name", Looksee_module_name, 1);
298
306
  #if RUBY_VERSION < 190
299
307
  rb_define_method(mMRI, "source_location", Looksee_source_location, 1);
Binary file
@@ -31,7 +31,8 @@ module Looksee
31
31
  if included_class?(mod) || object.is_a?(Module)
32
32
  description = module_name(object)
33
33
  if description.empty?
34
- description = "unnamed #{object.is_a?(Class) ? 'Class' : 'Module'}"
34
+ is_class = real_module(object).is_a?(Class)
35
+ description = "unnamed #{is_class ? 'Class' : 'Module'}"
35
36
  end
36
37
  else
37
38
  description = "#{module_name(object.class)} instance"
@@ -44,6 +45,10 @@ module Looksee
44
45
  end
45
46
  end
46
47
 
48
+ def real_module(module_or_included_class)
49
+ module_or_included_class
50
+ end
51
+
47
52
  def internal_superclass(klass)
48
53
  raise NotImplementedError, "abstract"
49
54
  end
@@ -28,7 +28,7 @@ module Looksee
28
28
  if visibility == :undefined
29
29
  return nil
30
30
  else
31
- return entry.module.instance_method(name)
31
+ return Looksee.adapter.real_module(entry.module).instance_method(name)
32
32
  end
33
33
  end
34
34
  nil
@@ -1,5 +1,5 @@
1
1
  module Looksee
2
- VERSION = [2, 1, 0]
2
+ VERSION = [2, 1, 1]
3
3
 
4
4
  class << VERSION
5
5
  include Comparable
@@ -227,44 +227,44 @@ describe "Looksee.adapter" do
227
227
  describe "#singleton_class?" do
228
228
  it "should return true if the object is a singleton class of an object" do
229
229
  object = (class << Object.new; self; end)
230
- @adapter.singleton_class?(object).should be_true
230
+ @adapter.singleton_class?(object).should == true
231
231
  end
232
232
 
233
233
  it "should return true if the object is a singleton class of a class" do
234
234
  object = (class << Class.new; self; end)
235
- @adapter.singleton_class?(object).should be_true
235
+ @adapter.singleton_class?(object).should == true
236
236
  end
237
237
 
238
238
  it "should return true if the object is a singleton class of a singleton class" do
239
239
  object = (class << (class << Class.new; self; end); self; end)
240
- @adapter.singleton_class?(object).should be_true
240
+ @adapter.singleton_class?(object).should == true
241
241
  end
242
242
 
243
243
  it "should return false if the object is just a class" do
244
244
  object = Class.new
245
- @adapter.singleton_class?(object).should be_false
245
+ @adapter.singleton_class?(object).should == false
246
246
  end
247
247
 
248
248
  it "should return false if the object is just a module" do
249
249
  object = Module.new
250
- @adapter.singleton_class?(object).should be_false
250
+ @adapter.singleton_class?(object).should == false
251
251
  end
252
252
 
253
253
  it "should return false if the object is just an object" do
254
254
  object = Object.new
255
- @adapter.singleton_class?(object).should be_false
255
+ @adapter.singleton_class?(object).should == false
256
256
  end
257
257
 
258
258
  it "should return false if the object is TrueClass" do
259
- @adapter.singleton_class?(TrueClass).should be_false
259
+ @adapter.singleton_class?(TrueClass).should == false
260
260
  end
261
261
 
262
262
  it "should return false if the object is FalseClass" do
263
- @adapter.singleton_class?(FalseClass).should be_false
263
+ @adapter.singleton_class?(FalseClass).should == false
264
264
  end
265
265
 
266
266
  it "should return false if the object is NilClass" do
267
- @adapter.singleton_class?(NilClass).should be_false
267
+ @adapter.singleton_class?(NilClass).should == false
268
268
  end
269
269
  end
270
270
 
@@ -401,6 +401,16 @@ describe "Looksee.adapter" do
401
401
  end
402
402
  end
403
403
 
404
+ describe "for an included class of an unnamed module" do
405
+ it "should describe the object as 'unnamed Module'" do
406
+ klass = Class.new do
407
+ include Module.new
408
+ end
409
+ mod = @adapter.lookup_modules(klass.new)[1]
410
+ @adapter.describe_module(mod).should == 'unnamed Module'
411
+ end
412
+ end
413
+
404
414
  describe "for a singleton class of an object" do
405
415
  it "should describe the object in brackets" do
406
416
  begin
@@ -4,7 +4,7 @@ describe Looksee do
4
4
  describe ".[]" do
5
5
  before do
6
6
  @object = Object.new
7
- Looksee.stub(:default_specifiers).and_return([:public, :overridden])
7
+ Looksee.stub(default_specifiers: [:public, :overridden])
8
8
  end
9
9
 
10
10
  it "should return an Inspector for the object's lookup path" do
@@ -65,11 +65,8 @@ describe Looksee::Editor do
65
65
  set_up_editor
66
66
 
67
67
  file, line = *source_location
68
- FileUtils.touch file
69
- Object.const_set(:C, Class.new { def f; end })
70
- Looksee.adapter.set_methods(C, [:f], [], [], [])
71
- Looksee.adapter.set_source_location(C, :f, source_location)
72
- Looksee.adapter.ancestors[object] = [C, Object]
68
+ open(file, 'w') { |f| f.puts "class C\n def f\n end\nend" }
69
+ load file
73
70
  end
74
71
 
75
72
  after do
@@ -102,7 +99,7 @@ describe Looksee::Editor do
102
99
  end
103
100
 
104
101
  it "should raise NoSourceLocationError and not run the editor if no source location is available" do
105
- Looksee.adapter.set_source_location(C, :f, nil)
102
+ Looksee.adapter.stub(source_location: nil)
106
103
  expect { editor.edit(object, :f) }.to raise_error(Looksee::NoSourceLocationError)
107
104
  editor_invocation.should be_nil
108
105
  end
@@ -2,6 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Looksee::Inspector do
4
4
  include TemporaryClasses
5
+ use_test_adapter
5
6
 
6
7
  describe "#inspect" do
7
8
  before do
@@ -4,6 +4,8 @@ describe Looksee::LookupPath do
4
4
  include TemporaryClasses
5
5
 
6
6
  describe "#entries" do
7
+ use_test_adapter
8
+
7
9
  before do
8
10
  temporary_module :M
9
11
  temporary_class(:C) { include M }
@@ -34,8 +36,8 @@ describe Looksee::LookupPath do
34
36
  end
35
37
 
36
38
  it "should know which methods have been overridden" do
37
- @lookup_path.entries[0].overridden?('public1').should be_false
38
- @lookup_path.entries[1].overridden?('public1').should be_true
39
+ @lookup_path.entries[0].overridden?('public1').should == false
40
+ @lookup_path.entries[1].overridden?('public1').should == true
39
41
  end
40
42
  end
41
43
 
@@ -43,10 +45,7 @@ describe Looksee::LookupPath do
43
45
  before do
44
46
  temporary_module(:M) { def f; end }
45
47
  temporary_class(:C) { include M; def f; end }
46
- @object = Object.new
47
- Looksee.adapter.ancestors[@object] = [C, M]
48
- Looksee.adapter.set_methods(M, [:f], [], [], [])
49
- Looksee.adapter.set_methods(C, [:f], [], [], [])
48
+ @object = C.new
50
49
  end
51
50
 
52
51
  it "should return the unoverridden UnboundMethod for the given method name" do
@@ -56,6 +55,14 @@ describe Looksee::LookupPath do
56
55
  method.name.should == (RUBY_VERSION < "1.9.0" ? 'f' : :f)
57
56
  end
58
57
 
58
+ it "should find methods in included modules" do
59
+ M.class_eval { def g; end }
60
+ lookup_path = Looksee::LookupPath.new(@object)
61
+ method = lookup_path.find('g')
62
+ method.owner.should == M
63
+ method.name.should == (RUBY_VERSION < "1.9.0" ? 'g' : :g)
64
+ end
65
+
59
66
  it "should return nil if the method does not exist" do
60
67
  lookup_path = Looksee::LookupPath.new(@object)
61
68
  lookup_path.find('g').should be_nil
@@ -63,8 +70,6 @@ describe Looksee::LookupPath do
63
70
 
64
71
  it "should return nil if the method has been undefined" do
65
72
  C.send(:undef_method, :f)
66
- Looksee.adapter.public_methods[C].delete(:f)
67
- Looksee.adapter.undefined_methods[C] << :f
68
73
  lookup_path = Looksee::LookupPath.new(@object)
69
74
  lookup_path.find('f').should be_nil
70
75
  end
@@ -73,11 +78,9 @@ describe Looksee::LookupPath do
73
78
  describe Looksee::LookupPath::Entry do
74
79
  it "should iterate over methods in alphabetical order" do
75
80
  temporary_class(:C)
76
- @object = Object.new
77
- Looksee.adapter.public_methods[C] = [:a, :c, :b]
78
- Looksee.adapter.ancestors[@object] = [C]
81
+ @object = C.new
82
+ Looksee.adapter.stub(internal_public_instance_methods: [:a, :c, :b])
79
83
  @lookup_path = Looksee::LookupPath.new(@object)
80
- @lookup_path.entries.size.should == 1
81
84
  @lookup_path.entries.first.map{|name, visibility| name}.should == ['a', 'b', 'c']
82
85
  end
83
86
  end
data/spec/spec_helper.rb CHANGED
@@ -17,5 +17,13 @@ end
17
17
  NATIVE_ADAPTER = Looksee.adapter
18
18
 
19
19
  RSpec.configure do |config|
20
- config.before { Looksee.adapter = TestAdapter.new }
20
+ config.extend TestAdapter::Mixin
21
+
22
+ config.expect_with :rspec do |c|
23
+ c.syntax = [:should, :expect]
24
+ end
25
+
26
+ config.mock_with :rspec do |c|
27
+ c.syntax = [:should, :expect]
28
+ end
21
29
  end
@@ -1,4 +1,11 @@
1
1
  class TestAdapter < Looksee::Adapter::Base
2
+ module Mixin
3
+ def use_test_adapter
4
+ before { Looksee.adapter = TestAdapter.new }
5
+ after { Looksee.adapter = NATIVE_ADAPTER }
6
+ end
7
+ end
8
+
2
9
  def lookup_modules(object)
3
10
  ancestors[object]
4
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: looksee
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - George Ogata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-05 00:00:00.000000000 Z
11
+ date: 2014-07-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: