avdi / naught

A toolkit for building Null Object classes in Ruby
MIT License
1.05k stars 53 forks source link

Fix JRuby compatibility #36

Closed c-lliope closed 10 years ago

c-lliope commented 11 years ago

See the comments on https://github.com/avdi/naught/pull/27

coveralls commented 11 years ago

Coverage Status

Coverage increased (+0.0%) when pulling c2da4d4c95a5d98b6f59c993b275bf4ffd39e989 on graysonwright:jruby into 5641a7c71d57361443cdaae0b0ee6ccdaf9b6c25 on avdi:master.

coveralls commented 11 years ago

Coverage Status

Coverage remained the same when pulling 9a86eae48dfd44e424f5bea50d6e47ca4aabf822 on graysonwright:jruby into 5641a7c71d57361443cdaae0b0ee6ccdaf9b6c25 on avdi:master.

c-lliope commented 11 years ago

I had to delete two specs that just weren't compatible with JRuby:

  context "when is called from a block" do
    it "prints the indication of a block" do
      expect(test_output).to receive(:puts).twice.
        with(/from block/)
      Caller.new.call_method_inside_block(null)
    end
  end

  context "when is called from many levels blocks" do
    it "prints the indication of blocks and its levels" do
      expect(test_output).to receive(:puts).exactly(4).times.
        with(/from block \(2 levels\)/)
      Caller.new.call_method_inside_nested_block(null)
    end
  end

They were failing because JRuby (and RBX) don't give a clear indication of blocks in their stacktrace.

As an example, the following code:

def foo
  2.times { raise 'ohno' }
end

foo

when run in the three different environments, give these stack traces:

MRI:

RuntimeError: ohno
    from (irb):2:in `block in foo'
    from (irb):2:in `times'
    from (irb):2:in `foo'
    from (irb):4

JRuby:

RuntimeError: ohno
    from (irb):2:in `foo'
    from org/jruby/RubyFixnum.java:280:in `times'
    from (irb):2:in `foo'
    from (irb):4:in `evaluate'
    ...

RBX:

RuntimeError: ohno
    from (irb):2:in `foo'
    from kernel/common/integer.rb:83:in `times'
    from (irb):2:in `foo'
    from (irb):4
    ...

They all give similar information, but the specs are looking for a specific indication that the call is coming from inside a block.

I don't think it's really necessary for Pebble to collect detailed information on the blocks, so I decided to scrap those specs. Pebbles will collect slightly less information on JRuby/RBX, but still capture the method name that the pebble was called from, etc.

Let me know if you think those specs were necessary.

avdi commented 10 years ago

Looks like @sferik has included JRuby support in his 1.8 compatibility PR. Thanks for getting the ball rolling!