Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

respond_to_missing? does not convert method to symbol #2946

Closed
splattael opened this issue May 15, 2015 · 1 comment
Closed

respond_to_missing? does not convert method to symbol #2946

splattael opened this issue May 15, 2015 · 1 comment
Assignees
Milestone

Comments

@splattael
Copy link
Contributor

Hi,

there is a difference between MRI and JRuby when handling respond_to? via respond_to_missing?.

MRI calls respond_to_missing? with already symbolized version of the method name provided to respond_to?.

Here is the test case:

gem 'minitest', '~> 5.0'
require 'minitest/autorun'

class RespondToMissingTest < Minitest::Test
  class Foo
    def respond_to_missing?(method, *args)
      method == :bar
    end
  end

  def test_does_respond_to_method_symbol
    foo = Foo.new
    assert foo.respond_to?(:bar)
  end

  def test_does_respond_to_method_string
    foo = Foo.new
    assert foo.respond_to?("bar")
  end
end

Running with MRI 2.2.2 passes

$ ruby -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
$ ruby respond_to_missing.rb 
Run options: --seed 13929

# Running:

..

Finished in 0.001279s, 1563.8977 runs/s, 1563.8977 assertions/s.

2 runs, 2 assertions, 0 failures, 0 errors, 0 skips

Running with JRuby 1.7.20 fails

$ ruby -v
jruby 1.7.20 (1.9.3p551) 2015-05-04 3086e6a on Java HotSpot(TM) Server VM 1.7.0_76-b13 +jit [linux-i386]
$ ruby respond_to_missing.rb 
Run options: --seed 40736

# Running:

F.

Finished in 0.019000s, 105.2632 runs/s, 105.2632 assertions/s.

  1) Failure:
RespondToMissingTest#test_does_respond_to_method_string [/tmp/respond_to_missing.rb:18]:
Failed assertion, no message given.

2 runs, 2 assertions, 1 failures, 0 errors, 0 skips

Note, it also fails with JRUBY_OPTS="--2.0".

Is this a JRuby bug or just a MRI anomaly?

Kind regards,
Peter

@kares kares added this to the JRuby 1.7.21 milestone May 24, 2015
@kares kares self-assigned this May 24, 2015
@kares kares closed this as completed in 4ed3010 May 25, 2015
kares added a commit that referenced this issue May 25, 2015
* jruby-1_7: (54 commits)
  [travis-ci] re-try sudo: false
  dry out the two (Java helper) respond_to_p19 methods
  respondsTo JRuby API under 1.9.3 does not do respond_to_missing? like MRI does
  sleep should convert it's "time interval" argument the same way as MRI
  respond_to_missing? should always get a symbol name passed (fixes #2946)
  add a respond_to_missing unit test (on 1.9)
  introduce and use conversion( just like MRI does) on #timeout's sec argument
  add missing ' ' (space) in exception message ... TypeError from `sleep('invalid')`
  DateTime.iso8601 fails with an error if a second fraction is present
  [build] switch to 1.7.21-SNAPSHOT for test-jruby-jars
  refactor Timeout's scheduled tasks to an inner class (for easier identification)
  further hand drying of the Timeout module impl
  less (int) casting noiz
  add some (internal) generics for an improved readability xp
  inner class' Finalizer fields id and finalized can be final
  generix-ize the environment field (at least internally) + use a StringBuilder
  unnecessary (int) cast
  missing throw statement in RubyString's concat
  tune timeout to work when scheduling or argument convenrsion throws (see #2940)
  return empty Ruby array for empty dir list
  ...

Conflicts:
	.gitignore
	.travis.yml
	VERSION
	core/pom.xml
	core/src/main/java/org/jruby/RubyArray.java
	core/src/main/java/org/jruby/RubyBasicObject.java
	core/src/main/java/org/jruby/RubyDir.java
	core/src/main/java/org/jruby/RubyEnumerable.java
	core/src/main/java/org/jruby/RubyFile.java
	core/src/main/java/org/jruby/RubyGlobal.java
	core/src/main/java/org/jruby/RubyIO.java
	core/src/main/java/org/jruby/RubyKernel.java
	core/src/main/java/org/jruby/RubyModule.java
	core/src/main/java/org/jruby/RubyString.java
	core/src/main/java/org/jruby/RubyTime.java
	core/src/main/java/org/jruby/ext/timeout/Timeout.java
	core/src/main/java/org/jruby/java/proxies/JavaProxy.java
	core/src/main/java/org/jruby/util/Dir.java
	core/src/main/java/org/jruby/util/encoding/CharsetTranscoder.java
	docs/man/pom.xml
	docs/pom.xml
	ext/pom.xml
	ext/readline/pom.xml
	ext/ripper/pom.xml
	lib/pom.xml
	lib/ruby/1.9/date/format.rb
	lib/ruby/1.9/io/linux_console.rb
	lib/ruby/shared/gauntlet_rubygems.rb
	lib/ruby/shared/rubygems.rb
	lib/ruby/shared/rubygems/available_set.rb
	lib/ruby/shared/rubygems/basic_specification.rb
	lib/ruby/shared/rubygems/command.rb
	lib/ruby/shared/rubygems/command_manager.rb
	lib/ruby/shared/rubygems/commands/cert_command.rb
	lib/ruby/shared/rubygems/commands/cleanup_command.rb
	lib/ruby/shared/rubygems/commands/contents_command.rb
	lib/ruby/shared/rubygems/commands/dependency_command.rb
	lib/ruby/shared/rubygems/commands/environment_command.rb
	lib/ruby/shared/rubygems/commands/generate_index_command.rb
	lib/ruby/shared/rubygems/commands/help_command.rb
	lib/ruby/shared/rubygems/commands/install_command.rb
	lib/ruby/shared/rubygems/commands/list_command.rb
	lib/ruby/shared/rubygems/commands/mirror_command.rb
	lib/ruby/shared/rubygems/commands/outdated_command.rb
	lib/ruby/shared/rubygems/commands/owner_command.rb
	lib/ruby/shared/rubygems/commands/pristine_command.rb
	lib/ruby/shared/rubygems/commands/push_command.rb
	lib/ruby/shared/rubygems/commands/query_command.rb
	lib/ruby/shared/rubygems/commands/search_command.rb
	lib/ruby/shared/rubygems/commands/setup_command.rb
	lib/ruby/shared/rubygems/commands/specification_command.rb
	lib/ruby/shared/rubygems/commands/uninstall_command.rb
	lib/ruby/shared/rubygems/commands/unpack_command.rb
	lib/ruby/shared/rubygems/commands/update_command.rb
	lib/ruby/shared/rubygems/commands/which_command.rb
	lib/ruby/shared/rubygems/commands/yank_command.rb
	lib/ruby/shared/rubygems/compatibility.rb
	lib/ruby/shared/rubygems/config_file.rb
	lib/ruby/shared/rubygems/core_ext/kernel_gem.rb
	lib/ruby/shared/rubygems/core_ext/kernel_require.rb
	lib/ruby/shared/rubygems/defaults.rb
	lib/ruby/shared/rubygems/dependency.rb
	lib/ruby/shared/rubygems/dependency_installer.rb
	lib/ruby/shared/rubygems/dependency_list.rb
	lib/ruby/shared/rubygems/deprecate.rb
	lib/ruby/shared/rubygems/doctor.rb
	lib/ruby/shared/rubygems/errors.rb
	lib/ruby/shared/rubygems/exceptions.rb
	lib/ruby/shared/rubygems/ext.rb
	lib/ruby/shared/rubygems/ext/builder.rb
	lib/ruby/shared/rubygems/ext/cmake_builder.rb
	lib/ruby/shared/rubygems/ext/configure_builder.rb
	lib/ruby/shared/rubygems/ext/ext_conf_builder.rb
	lib/ruby/shared/rubygems/ext/rake_builder.rb
	lib/ruby/shared/rubygems/gemcutter_utilities.rb
	lib/ruby/shared/rubygems/indexer.rb
	lib/ruby/shared/rubygems/install_update_options.rb
	lib/ruby/shared/rubygems/installer.rb
	lib/ruby/shared/rubygems/installer_test_case.rb
	lib/ruby/shared/rubygems/local_remote_options.rb
	lib/ruby/shared/rubygems/name_tuple.rb
	lib/ruby/shared/rubygems/package.rb
	lib/ruby/shared/rubygems/package/old.rb
	lib/ruby/shared/rubygems/package/tar_header.rb
	lib/ruby/shared/rubygems/package/tar_reader/entry.rb
	lib/ruby/shared/rubygems/package/tar_writer.rb
	lib/ruby/shared/rubygems/path_support.rb
	lib/ruby/shared/rubygems/platform.rb
	lib/ruby/shared/rubygems/psych_additions.rb
	lib/ruby/shared/rubygems/rdoc.rb
	lib/ruby/shared/rubygems/remote_fetcher.rb
	lib/ruby/shared/rubygems/request.rb
	lib/ruby/shared/rubygems/request_set.rb
	lib/ruby/shared/rubygems/request_set/gem_dependency_api.rb
	lib/ruby/shared/rubygems/requirement.rb
	lib/ruby/shared/rubygems/resolver/current_set.rb
	lib/ruby/shared/rubygems/security.rb
	lib/ruby/shared/rubygems/security/policy.rb
	lib/ruby/shared/rubygems/security/signer.rb
	lib/ruby/shared/rubygems/security/trust_dir.rb
	lib/ruby/shared/rubygems/server.rb
	lib/ruby/shared/rubygems/source.rb
	lib/ruby/shared/rubygems/source/installed.rb
	lib/ruby/shared/rubygems/source/local.rb
	lib/ruby/shared/rubygems/source/specific_file.rb
	lib/ruby/shared/rubygems/source_list.rb
	lib/ruby/shared/rubygems/spec_fetcher.rb
	lib/ruby/shared/rubygems/specification.rb
	lib/ruby/shared/rubygems/ssl_certs/AddTrustExternalCARoot.pem
	lib/ruby/shared/rubygems/stub_specification.rb
	lib/ruby/shared/rubygems/syck_hack.rb
	lib/ruby/shared/rubygems/test_case.rb
	lib/ruby/shared/rubygems/test_utilities.rb
	lib/ruby/shared/rubygems/text.rb
	lib/ruby/shared/rubygems/uninstaller.rb
	lib/ruby/shared/rubygems/uri_formatter.rb
	lib/ruby/shared/rubygems/user_interaction.rb
	lib/ruby/shared/rubygems/util/list.rb
	lib/ruby/shared/rubygems/validator.rb
	lib/ruby/shared/rubygems/version.rb
	maven/jruby-complete/pom.xml
	maven/jruby-dist/pom.xml
	maven/jruby-jars/pom.xml
	maven/jruby-noasm/pom.xml
	maven/jruby-rake-plugin/pom.xml
	maven/jruby-stdlib/pom.xml
	maven/jruby/pom.xml
	maven/pom.xml
	pom.xml
	test/pom.xml
	test/test_dir.rb
	test/test_kernel.rb
	test/test_respond_to.rb
	test/test_timeout.rb
@splattael
Copy link
Contributor Author

Please excuse my late response.

@kares Thank you for fixing :)

I can confirm it works for 1.7.21-SNAPSHOT and 9.0.0.0-SNAPSHOT!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants