From 90c1d06b617fc4306628d8a5e8fffe74cba2d21d Mon Sep 17 00:00:00 2001 From: Jason Frey Date: Fri, 9 Dec 2016 23:00:26 -0500 Subject: [PATCH 1/4] Replace RubyParser with RipperRubyParser RubyParser lags Ruby and doesn't yet have Ruby 2.4 support. RipperRubyParser uses Ripper and so will always have the latest version. --- Gemfile | 2 +- lib/extensions/descendant_loader.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index cde677e91a7..457ef133656 100644 --- a/Gemfile +++ b/Gemfile @@ -76,9 +76,9 @@ gem "rails-controller-testing", :require => false gem "rails-i18n", "~>5.x" gem "recursive-open-struct", "~>1.0.0" gem "responders", "~>2.0" +gem "ripper_ruby_parser", :require => false gem "ruby-dbus" # For external auth gem "ruby-progressbar", "~>1.7.0", :require => false -gem "ruby_parser", "~>3.8", :require => false gem "rufus-scheduler", "~>3.1.3", :require => false gem "rugged", "=0.25.0b10", :require => false gem "secure_headers", "~>3.0.0" diff --git a/lib/extensions/descendant_loader.rb b/lib/extensions/descendant_loader.rb index 2d1f54216c6..9853fb0a4c3 100644 --- a/lib/extensions/descendant_loader.rb +++ b/lib/extensions/descendant_loader.rb @@ -68,10 +68,10 @@ def self.status(io = $stdout) # and the name of its superclass), given a path to a ruby script file. module Parser def classes_in(filename) - require 'ruby_parser' + require 'ripper_ruby_parser' content = File.read(filename) - parsed = RubyParser.for_current_ruby.parse(content) + parsed = RipperRubyParser::Parser.new.parse(content) classes = collect_classes(parsed) @@ -94,7 +94,7 @@ def classes_in(filename) [search_combos, define_combos, flatten_name(name), flatten_name(sklass)] end.compact - rescue Racc::ParseError + rescue RipperRubyParser::SyntaxError puts "\nSyntax error in #{filename}\n\n" raise end From ef992a1018525d7d52ea9e0c3bcb89bd553aa633 Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Thu, 2 Feb 2017 11:59:21 -0500 Subject: [PATCH 2/4] The method signature looks different since it now uses kwargs. https://github.com/ruby/ruby/commit/baa43cd0c2217548c9e19366056fdc5fbd50fa4a Fixes: expected: ("/etc/httpd/conf.d/manageiq-https-mirror.conf", {:force=>true}) got: ("/etc/httpd/conf.d/manageiq-https-mirror.conf", {:force=>true, :noop=>nil, :verbose=>nil}) --- spec/models/miq_server/rhn_mirror_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/miq_server/rhn_mirror_spec.rb b/spec/models/miq_server/rhn_mirror_spec.rb index db9812733d8..20f50ab09fe 100644 --- a/spec/models/miq_server/rhn_mirror_spec.rb +++ b/spec/models/miq_server/rhn_mirror_spec.rb @@ -34,7 +34,7 @@ expect(FileUtils).to receive(:mkdir_p).with("/repo/mirror") expect(MiqApache::Conf).to receive(:create_conf_file).once.and_return(true) - expect(FileUtils).to receive(:rm).with("/etc/httpd/conf.d/manageiq-https-mirror.conf", :force => true) + expect(FileUtils).to receive(:rm).with("/etc/httpd/conf.d/manageiq-https-mirror.conf", hash_including(:force => true)) expect(MiqApache::Control).to receive(:restart).once expect(LinuxAdmin::Yum).to receive(:download_packages).once.with("/repo/mirror", "cfme-appliance") expect(Dir).to receive(:glob).with("/repo/mirror/**/*.rpm").and_return(rpm_file_list) From ff9b4675f35303d00f93132bc081328fdcfd7da9 Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Thu, 2 Feb 2017 13:31:14 -0500 Subject: [PATCH 3/4] Monkeypatch webmock's StubSocket due to a ruby 2.4.0 change in net/http Ruby 2.4.0 removed the closed? check in the conditional in: s.close if !s.closed? Webmock was changed to add close to StubSocket along with another change.. https://github.com/ruby/ruby/commit/f845a9ef76c0195254ded79c85c24332534f4057 https://github.com/bblimke/webmock/commit/8f2176a1fa75374df55b87d782e08ded673a75b4 WebMock 2.3.1+ fixed the issue with ruby 2.4.0 by adding StubSocket#close. --- spec/support/webmock_ruby24_bridge.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 spec/support/webmock_ruby24_bridge.rb diff --git a/spec/support/webmock_ruby24_bridge.rb b/spec/support/webmock_ruby24_bridge.rb new file mode 100644 index 00000000000..7ea92383efb --- /dev/null +++ b/spec/support/webmock_ruby24_bridge.rb @@ -0,0 +1,15 @@ +# Ruby 2.4.0 removed the closed? check in the conditional in: s.close if !s.closed? +# Webmock was changed to add close to StubSocket along with another change. +# https://github.com/ruby/ruby/commit/f845a9ef76c0195254ded79c85c24332534f4057 +# https://github.com/bblimke/webmock/commit/8f2176a1fa75374df55b87d782e08ded673a75b4 +# WebMock 2.3.1+ fixed this. +# We should upgrade webmock but that requires some re-recording of cassettes (I think) +# and maybe other things. +if WebMock::VERSION < "2.3.1" + class StubSocket + def close + end + end +else + warn "Remove me: #{__FILE__}:#{__LINE__}. WebMock 2.3.1+ fixed the issue with ruby 2.4.0 by adding StubSocket#close." +end From 56f5fc9c0d3359b2e48793661dfb845e86468e51 Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Tue, 21 Mar 2017 14:40:51 -0400 Subject: [PATCH 4/4] Ruby 2.4 unifies Fixnum and Bignum into Integer For now, make the test expectations different for ruby 2.4.0+ vs. prior rubies. CustomAttribute#value_type returns a symbol for a ruby core class, a hardcoded value instead of the class's behavior. Do we use this? Why are we returning a value instead of caring about behavior of the old Fixnum and Integer? If we don't use this, we should remove the whole method and it's tests added in: https://github.com/ManageIQ/manageiq/commit/46873949ddbed0fab43671af6cef6d5b10e70e09 The PR that added this was: https://github.com/ManageIQ/manageiq/pull/11000 Adding CustomAttribute to provider UI/API was added in: https://github.com/ManageIQ/manageiq/pull/10897 --- spec/models/custom_attribute_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/models/custom_attribute_spec.rb b/spec/models/custom_attribute_spec.rb index 6ad97d3a680..719745b881c 100644 --- a/spec/models/custom_attribute_spec.rb +++ b/spec/models/custom_attribute_spec.rb @@ -12,6 +12,9 @@ end it "returns the value type of Fixnum custom attributes" do - expect(int_custom_attribute.value_type).to eq(:fixnum) + # TODO: Ruby 2.4 unifies fixnum and bignum into integer, we shouldn't be + # returnings ruby types like this. + expected = RUBY_VERSION >= "2.4.0" ? :integer : :fixnum + expect(int_custom_attribute.value_type).to eq(expected) end end