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

Upgraded from 1.0 to 2.0. #611

Closed
riniculous opened this issue May 15, 2023 · 9 comments
Closed

Upgraded from 1.0 to 2.0. #611

riniculous opened this issue May 15, 2023 · 9 comments
Assignees

Comments

@riniculous
Copy link

riniculous commented May 15, 2023

Mocha 2.0. minitest '5.10.3'. rails 6.1.
In test helper have

require 'minitest/unit'
require 'mocha/minitest'

Any ideas?

NoMethodError: undefined method `pop' for nil:NilClass
    mocha (2.0.0) lib/mocha/mockery.rb:54:in `ensure in teardown'
    mocha (2.0.0) lib/mocha/mockery.rb:54:in `teardown'
    mocha (2.0.0) lib/mocha/hooks.rb:39:in `mocha_teardown'
    mocha (2.0.0) lib/mocha/integration/mini_test/adapter.rb:47:in `after_teardown'
    activesupport (6.1.6) lib/active_support/testing/time_helpers.rb:72:in `after_teardown'
    activesupport (6.1.6) lib/active_support/current_attributes/test_helper.rb:10:in `after_teardown'
    activerecord (6.1.6) lib/active_record/test_fixtures.rb:15:in `after_teardown'
    activesupport (6.1.6) lib/active_support/testing/setup_and_teardown.rb:51:in `after_teardown'
    minitest (5.16.3) lib/minitest/test.rb:103:in `block (4 levels) in run'
    minitest (5.16.3) lib/minitest/test.rb:195:in `capture_exceptions'
    minitest (5.16.3) lib/minitest/test.rb:102:in `block (3 levels) in run'
    minitest (5.16.3) lib/minitest/test.rb:101:in `each'
    minitest (5.16.3) lib/minitest/test.rb:101:in `block (2 levels) in run'
    minitest (5.16.3) lib/minitest.rb:296:in `time_it'
    minitest (5.16.3) lib/minitest/test.rb:94:in `block in run'
    minitest (5.16.3) lib/minitest.rb:391:in `on_signal'
    minitest (5.16.3) lib/minitest/test.rb:243:in `with_info_handler'
    minitest (5.16.3) lib/minitest/test.rb:93:in `run'
    minitest (5.16.3) lib/minitest.rb:1059:in `run_one_method'
    minitest (5.16.3) lib/minitest.rb:365:in `run_one_method'
    minitest (5.16.3) lib/minitest.rb:352:in `block (2 levels) in run'
    minitest (5.16.3) lib/minitest.rb:351:in `each'
    minitest (5.16.3) lib/minitest.rb:351:in `block in run'
    minitest (5.16.3) lib/minitest.rb:391:in `on_signal'
    minitest (5.16.3) lib/minitest.rb:378:in `with_info_handler'
    minitest (5.16.3) lib/minitest.rb:350:in `run'
    railties (6.1.6) lib/rails/test_unit/line_filtering.rb:10:in `run'
    minitest (5.16.3) lib/minitest.rb:182:in `block in __run'
    minitest (5.16.3) lib/minitest.rb:182:in `map'
    minitest (5.16.3) lib/minitest.rb:182:in `__run'
    minitest (5.16.3) lib/minitest.rb:159:in `run'
    minitest (5.16.3) lib/minitest.rb:83:in `block in autorun'
@floehopper
Copy link
Member

I hope you don't mind but I tidied up the formatting in the issue description.

Upgraded from 1.0 to 2.0

Can you confirm this means you've upgraded mocha from v1.0 to v2.0?

Mocha v1.0 was released in 2014, i.e. 9 years ago! Do you really mean you have upgraded from v1.0 -> v2.0? If so, can you try upgrading to the latest v1.x release first, i.e. v1.16.1. Also I'd recommend upgrading to the latest v2.x release, i.e. v2.0.2, not v2.0.0.

NoMethodError: undefined method `pop' for nil:NilClass

What command generated this ☝️ stack trace?

The stack trace suggests mocha's setup is not getting called correctly. Do you have any other test-related gems installed? Can you post your Gemfile?

What version of Ruby are you using?

@floehopper
Copy link
Member

Also can you try running the tests with the MOCHA_OPTIONS env var set to "debug" and post the output?

@riniculous
Copy link
Author

riniculous commented May 15, 2023 via email

@floehopper
Copy link
Member

Are there any test setup methods or blocks in test_helper.rb or its associated files?

@riniculous
Copy link
Author

i saw a post talking about
require 'mocha/setup'
but dont see that in this code... Is that needed?

@riniculous
Copy link
Author

OK.. got it working... So basically fixtures being loaded beforehand had some bad data.
Caused the error test_helper to error out. Which caused the mocha/minitest to not load.. which caused the stack trace error above.
There was so much output i never saw the very first error of the fixture data.

@floehopper
Copy link
Member

I'm glad you got to the bottom of it! And thanks for letting me know and closing the issue. 😄

@alexdunae
Copy link

I also ran into this same error...

NoMethodError: undefined method `pop' for nil:NilClass

        @instances.pop
                  ^^^^
    /home/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/mocha-2.2.0/lib/mocha/mockery.rb:54:in `ensure in teardown'
    /home/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/mocha-2.2.0/lib/mocha/mockery.rb:54:in `teardown'
    /home/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/mocha-2.2.0/lib/mocha/hooks.rb:39:in `mocha_teardown'
    /home/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/mocha-2.2.0/lib/mocha/integration/minitest/adapter.rb:47:in `after_teardown'
    /home/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/activesupport-7.1.3.2/lib/active_support/testing/time_helpers.rb:71:in `after_teardown'
    /home/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/actioncable-7.1.3.2/lib/action_cable/test_helper.rb:17:in `after_teardown'
    /home/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/activerecord-7.1.3.2/lib/active_record/test_fixtures.rb:15:in `after_teardown'
    /home/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/activesupport-7.1.3.2/lib/active_support/testing/setup_and_teardown.rb:51:in `after_teardown'
    /home/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/activejob-7.1.3.2/lib/active_job/test_helper.rb:54:in `after_teardown'

And the note from @riniculous about fixtures helped get me on my way.

I had been saving cassettes in test/fixtures/vcr_cassettes but that was causing them to be loaded as regular Rails fixtures.

Moving the cassettes directory out of test/fixtures solved the problem.

@floehopper
Copy link
Member

@alexdunae Thanks for reporting this - I've opened #646 to see if we can provide a more useful error message in this scenario.

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

3 participants