metaskills / minitest-spec-rails

:bento: Make Rails Use MiniTest::Spec!

Home Page:http://github.com/metaskills/minitest-spec-rails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rspec-rails and Minitest-spec-rails

cristi opened this issue · comments

hi @metaskills, I don't think this is the best place to ask, but this same question has been asked on SO without an answer, so here goes:

I'm in the situation where I need to have both minitest and rspec in the same project (don't ask :) )

I have everything mostly running, but there is one weird behaviour which I can find a way around. It looks like the minitest describe blocks are being ignored. So the its that are in the root of the file are running, but the ones that are inside a describe block are ignored.

I could get rid of the describe blocks, but maybe there is an alternative. Any suggestions are welcome. Thank you!

Yea.... given that both RSpec & Minitest want to extend Kernel the only thing I can think of is you have to have both doing a require: false in your Gemfile and then in each test helper being explicit about the require for each test platform. Does that help?

yep, that was my conclusion after reading for a few hours and trying out different things. I'm on the require: false route right now, getting closer, just need to convince rswag, the last piece of the puzzle (and the reason we need rspec in the first place). Thanks for the reply, much appreciated, closing this

For future reference, I came across this answer from a different direction. This post describes the symptoms that lead me to this solution.

Our project includes RSpec and Minitest-Spec-Rails. Minitest tests were suddenly failing because the helpers in test_helper.rb were not being found when the test ran.

The first clue is that rspec was appearing in the backtrace:

...
9: from /xxx/vendor/bundle/ruby/gems/minitest-spec-rails-5.4.0/lib/minitest-spec-rails/dsl.rb:14:in `describe'
8: from /xxxx/vendor/bundle/ruby/gems/rspec-core-3.10.1/lib/rspec/core/dsl.rb:84:in `block (2 levels) in expose_example_group_alias_globally'
7: from /xxx/vendor/bundle/ruby/gems/rspec-core-3.10.1/lib/rspec/core/dsl.rb:43:in `block in expose_example_group_alias'
...
3: from /xxx/vendor/bundle/ruby/gems/minitest-spec-rails-5.4.0/lib/minitest-spec-rails/dsl.rb:14:in `block in describe'
2: from /xxx/vendor/bundle/ruby/gems/minitest-spec-rails-5.4.0/lib/minitest-spec-rails/dsl.rb:14:in `class_eval'
1: from /xxx/test/serializers/store_props_serializer_test.rb:72:in `block in <class:StorePropsSerializerTest>'
/xxx/vendor/bundle/ruby/gems/rspec-core-3.10.1/lib/rspec/core/example_group.rb:749:in `method_missing': undefined local variable or method `use_vcr_cassette' for RSpec::ExampleGroups::BundleStore:Class (NameError)

Examining the ancestors within the test shows that rspec was indeed being used instead of minitest-spec-rails:

[RSpec::ExampleGroups::BundleStore,
 RSpec::Core::ExampleGroup,
 RSpec::Matchers,
...
 ActiveSupport::ForkTracker::CoreExtPrivate,
 ActiveSupport::ForkTracker::CoreExt,
 ActiveSupport::ToJsonWithActiveSupportEncoder,
 Object,
 Mocha::ObjectMethods,
 Mocha::Inspect::ObjectMethods,
 Mocha::ParameterMatchers::InstanceMethods,
 Minitest::Expectations,
 Nori::CoreExt::Object,
 PP::ObjectMixin,
 ActiveSupport::Tryable,
 JSON::Ext::Generator::GeneratorMethods::Object,
 ActiveSupport::Dependencies::Loadable,
 Kernel,
 BasicObject]

Diffing the changes on Gemfile showed that I removed require: false from rspec-rails, hence RSpec was overriding Minitest. Restoring require: false got things working again. This is the correct ancestors chain:

[#<Class:0x000055e3b70e7248>,
...
 ActiveSupport::Testing::ConstantLookup,
 MiniTestSpecRails::DSL,
 Minitest::Spec::DSL::InstanceMethods,
 MiniTestSpecRails::Init::ActiveSupportBehavior,
 ActiveSupport::Testing::FileFixtures,
 ...
 Minitest::Test,
 ...
 Object,
 Mocha::ObjectMethods,
 Mocha::Inspect::ObjectMethods,
 Mocha::ParameterMatchers::InstanceMethods,
 Minitest::Expectations,
 Nori::CoreExt::Object,
 PP::ObjectMixin,
 ActiveSupport::Tryable,
 JSON::Ext::Generator::GeneratorMethods::Object,
 ActiveSupport::Dependencies::Loadable,
 Kernel,
 BasicObject]