From 279b2dfd509747708fc5b87d9027e514a23e5da9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Thu, 27 Mar 2014 20:28:33 +0100 Subject: [PATCH] [vm] Sync and add NEWS+tests for warning when overriding attr methods. --- NEWS | 3 +++ test/helpers/bacon.rb | 9 +++++++++ test/test/spec/protocol_spec.rb | 29 +++++++++++++++++++++++++++++ vm | 2 +- 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 860bdf03..27617e0a 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,8 @@ = RubyMotion 2.25 = + * Improved user feedback by printing a warning when overriding a protocol + method that was previously defined with one of the `attr_*' methods. This + may print false positives. * Fixed a bug which `rake device debug=1' does not work with Xcode 5.1. * Fixed an error in `rake device debug=1' if it would use UTF-8 as app name. * Fixed a bug where an application could not be installed and launched on the diff --git a/test/helpers/bacon.rb b/test/helpers/bacon.rb index 54ec829d..51575453 100644 --- a/test/helpers/bacon.rb +++ b/test/helpers/bacon.rb @@ -35,6 +35,15 @@ module Bacon alias_method :on_64bit_it, RUBY_ARCH =~ /64/ ? :it : :xit alias_method :on_ios_it, defined?(UIView) ? :it : :xit + + def capture_warning + $last_rb_warn = nil + ENV['RM_CAPTURE_WARNINGS'] = '1' + yield + $last_rb_warn + ensure + ENV.delete('RM_CAPTURE_WARNINGS') + end end # Overrides the SpecDoxzRtput to provide colored output by default diff --git a/test/test/spec/protocol_spec.rb b/test/test/spec/protocol_spec.rb index 1733ebc8..3a84a2d5 100644 --- a/test/test/spec/protocol_spec.rb +++ b/test/test/spec/protocol_spec.rb @@ -28,3 +28,32 @@ describe "conformsToProtocol:" do TestObjCSubclassConformsToProtocolObject.new.conformsToProtocol(NSProtocolFromString('TestConformsToProtocol')).should == true end end + +describe "A protocol method" do + it "warns when overriding a method defined with the `attr_reader' macro" do + class TestConformsToProtocolObject4 + attr_reader :requiredMethod1 + end + + warning = capture_warning do + class TestConformsToProtocolObject4 + def requiredMethod1; 42; end + end + end + warning.should.match /protocol method `TestConformsToProtocolObject4#requiredMethod1'/ + end + + xit "warns when overriding a method defined with the `attr_writer' macro" do + class TestConformsToProtocolObject5 + attr_reader :requiredMethod1 + end + + warning = capture_warning do + class TestConformsToProtocolObject5 + #def requiredMethod1=(x); x; end + def setRequiredMethod1(x); x; end + end + end + warning.should.match /protocol method `TestConformsToProtocolObject5#requiredMethod1='/ + end +end diff --git a/vm b/vm index 995cead5..1e9b9c80 160000 --- a/vm +++ b/vm @@ -1 +1 @@ -Subproject commit 995cead5b3ecc83b1575bec12448de7fa6860508 +Subproject commit 1e9b9c80c2609d4ac6e3dd848642d21a2d931b89