-
-
Save palkan/bf2c983ac9bfa701223fc0a87d273de7 to your computer and use it in GitHub Desktop.
It could be defined anywhere but must be populated before you use it
I created a file shared_user.rb
in path spec/support/shared_contexts
, and created another file shared_attachment.rb
in the same path. Now, when I call fixture(:user)
inside shared_attachment.rb
, it gives me error: *** LocalJumpError Exception: no block given (yield)
. What am I missing here?
You should include shared_user
before (or inside) shared_attachment
; this error means that no fixture has been registered.
Thanks @palkan - is there an equivalent for shared_context
of Rspec in Minitest?
I tried to use this AnyFixture but unfortunately the fixture is cleared/deleted after first case is ran
(i.e with a test of 5 cases, 1st one calls the fixture correctly, but then it is deleted and other cases can't reuse it) - since you have Minitest in the guide I thought maybe I missed something?
Thank you
Hey @aelkoussy!
In Minitest, you can use Ruby modules to share functionality. However, you're likely need smth like before(:all) / after(:all)
—that can be achieved through some patching. See our Minitest before_all integration, for example: https://github.com/test-prof/test-prof/blob/17d674dfe9bbccab45a436f64bb1e1cc774e8572/lib/test_prof/recipes/minitest/before_all.rb#L158-L172
Hey @palkan, thanks a lot! :) I will give it a try, I tried the gem https://github.com/jeremyevans/minitest-hooks and tried setting the fixture in a before(:all)
block but it was always removed after first test... to keep it as simple I defined the fixture in a before(:all) in the same test file but it works for 1 test and for others the fixture is not found
I thought I missed something but given your comment, I am now suspecting something custom in our code is clearing the database after each test - will check and thanks for the great work! 🎉
I will try to add more info here if I find a solution.
The
:user
fixture need to be in same shared_context or it can refer another in different file? Can you share an example?