Changeset 188
- Timestamp:
- 02/16/08 07:18:55 (6 months ago)
- Files:
-
- incubator/reopen/lib/reopen.rb (modified) (2 diffs)
- incubator/reopen/test/test_reopen.rb (modified) (2 diffs)
- incubator/reopen/TODO.txt (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
incubator/reopen/lib/reopen.rb
r185 r188 23 23 24 24 class <<self 25 attr_accessor :log 26 25 27 def check_for_collisions(clazz, module_to_include) 26 28 new_methods = Set.new(module_to_include.instance_methods(false)) … … 32 34 end 33 35 34 def collision(clazz, module_to_include, method) 35 puts "Warning: #{module_to_include} is attempting to redefine #{method}" 36 puts " Originally defined in #{clazz}" 36 def warning(clazz, module_to_include, method) 37 "Warning: #{module_to_include} is attempting to redefine #{method} originally defined in #{clazz}" 38 end 39 40 def collision(*args) 41 log ? log.warn(warning(*args)) : puts(warning(*args)) 37 42 end 38 43 end incubator/reopen/test/test_reopen.rb
r185 r188 46 46 end 47 47 48 it "should report collisions to the console (by default)" do 49 Reopen.expects(:puts).times(2) 48 49 end 50 51 describe "reopen warnings" do 52 before do 53 @class = Class.new 54 end 55 56 after do 57 Reopen.log = nil 58 end 59 60 it "should format a warning message" do 61 Reopen.warning(:a, :b, :c).should == "Warning: b is attempting to redefine c originally defined in a" 62 end 63 64 it "should delegate to a log if specified" do 65 log = stub 66 log.expects(:warn).returns(:warning) 67 Reopen.log = log 68 Reopen.expects(:warning).returns(:warning) 69 Reopen.expects(:puts).never 70 @class.reopen do 71 def hello; "hello"; end 72 end 73 @class.reopen do 74 def hello; "hello again"; end 75 end 76 77 end 78 79 it "should report collision warnings to the console (by default)" do 80 Reopen.expects(:warning).returns(:stub_warning) 81 Reopen.expects(:puts).with(:stub_warning).times(1) 50 82 @class.reopen do 51 83 def hello; "hello"; end … … 57 89 58 90 end 91
