Spurious "protected method [...] called for [...]" error with rspec-mocks
-------------------------------------------------------------------------

                 Key: JRUBY-5944
                 URL: https://jira.codehaus.org/browse/JRUBY-5944
             Project: JRuby
          Issue Type: Bug
    Affects Versions: JRuby 1.6.3
         Environment: jruby 1.6.3 (ruby-1.8.7-p330) (2011-07-07 965162f) 
(OpenJDK 64-Bit Server VM 1.6.0_22) [linux-amd64-java]
            Reporter: Stephen Lewis
            Assignee: Thomas E Enebo
         Attachments: test_protected_behaviour.rb

$ rvm use system
Now using system ruby.

$ ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]

$ rspec test_protected_behaviour.rb 
.

Finished in 0.00055 seconds
1 example, 0 failures

$ rvm use jruby-1.6.3
Using /home/stephenl/.rvm/gems/jruby-1.6.3

$ ruby -v
jruby 1.6.3 (ruby-1.8.7-p330) (2011-07-07 965162f) (OpenJDK 64-Bit Server VM 
1.6.0_22) [linux-amd64-java]

$ rspec test_protected_behaviour.rb 
F

Failures:

  1) A should let me say hello
     Failure/Error: new_instance.say_hello_protected
     NoMethodError:
       protected method `say_hello_protected' called for #<A:0x15a4eb56>
     # ./test_protected_behaviour.rb:8:in `say_hello_public'
     # ./test_protected_behaviour.rb:28:in `(root)'
     # org/jruby/RubyKernel.java:2061:in `instance_eval'
     # org/jruby/RubyArray.java:2336:in `collect'
     # org/jruby/RubyArray.java:2336:in `collect'

Finished in 0.017 seconds
1 example, 1 failure

Failed examples:

rspec ./test_protected_behaviour.rb:24 # A should let me say hello

Removing the "require 'yaml'" line in the attached file causes the test to 
pass. This is because RSpec::Mocks::Serialization#fix_for(...) only extends its 
target with RSpec::Mocks::Serialization::YAML if ::YAML is visible to it.

It looks like this inclusion is confusing 
DynamicMethod.calculateProtectedClass(), I suspect because the mock (against 
which the call to say_hello_protected is made) is a singleton, and the call to 
cls.getSuperClass() is returning RSpec::Mocks::Serialization::YAML rather than 
'A'. My understanding of rspec-mocks doesn't extend far enough for me to 
understand exactly why, though.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to