-
-
Notifications
You must be signed in to change notification settings - Fork 942
Description
JRuby throws a NullPointerException in Rspec tests when creating tempfiles. The issue occurs when uploading fixture files using the same file across multiple describe blocks.
Here is the test code that exhibits the issue:
require 'spec_helper'
describe 'Tempfile' do
let(:file) { fixture_file_upload(Rails.root.join('spec/fixtures/file_1.txt').to_s) }
describe 'test' do
describe '1' do
it { expect{file}.to_not raise_exception }
end
describe '2' do
# Test will pass if before block is uncommented
# Or if config.order = "random" is commented in spec_helper
# before { ActionMailer::Base.deliveries.clear }
it { expect{file}.to_not raise_exception }
end
end
endI've created a sample app here https://github.com/synth/jruby-rspec-tempfile-bug
I've also got multiple builds being tested on TravisCI here: https://travis-ci.org/synth/jruby-rspec-tempfile-bug
As you can see, some versions of MRI and JRuby are passing and some aren't. In particular, JRuby v9.1.5.0 is where I first encountered this bug. While this test also doesn't pass in MRI, its in JRuby that I experience the NullPointerException which is why I'm reporting it here. (I think MRI is failing due to some other dependency issue or something...)
As noted in the README of the sample app, the bug appears when two conditions are true:
- Rspec.config.order = "random"
- ActionMailer::Base.deliveries is not cleared in a before block
Very weird, I know. I would bet those things are somehow triggering something else under the covers though.
Let me know if I can provide more information or if I should go about creating a better test case.
Thanks!