Conversation
|
Could you share warnings you saw? It seems that the added test without your fix don't show any warnings. |
|
Sorry, I was ahead of myself. The warning comes from Rails with Minitest. I set up this Rails app with an index controller: class IndexController < ApplicationController
module Text
def self.text
"hello, world"
end
end
def index
render plain: Text.text
end
end
class IndexControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
stub(IndexController::Text).text { "stub" }
get root_url
assert_response 200
assert_equal "stub", response.body
end
endExpectedTest works without warnings: When I use RR, that is using the class IndexControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
stub(IndexController::Text).text { "stub" }
get root_url
assert_received(IndexController::Text) do |expect|
expect.text
end
end
endI should get ActualWith this patch |
|
Thanks. It seems that the following change is enough: diff --git a/lib/rr/integrations/minitest_4.rb b/lib/rr/integrations/minitest_4.rb
index 8e73aa8..90bacfc 100644
--- a/lib/rr/integrations/minitest_4.rb
+++ b/lib/rr/integrations/minitest_4.rb
@@ -3,6 +3,7 @@ module RR
class MiniTest4
module Mixin
def assert_received(subject, &block)
+ self.assertions += 1
block.call(received(subject)).call
end
endWhat do you think about this? |
|
Of course. I will move the change to minitest4. Updated. I kept the test case to test the assertions count on minitest5. |
kou
left a comment
There was a problem hiding this comment.
Could you update the PR description to explain what warning was shown before we merge this?
test/integration/test_minitest.rb
Outdated
| end | ||
|
|
||
| result = test_class.new(:test_assert_received).run | ||
| assert_empty result.failures |
There was a problem hiding this comment.
Do we need this? (Is it important in this test?)
test/integration/test_minitest.rb
Outdated
|
|
||
| result = test_class.new(:test_assert_received).run | ||
| assert_empty result.failures | ||
| assert_equal 1, result.assertions |
There was a problem hiding this comment.
| assert_equal 1, result.assertions | |
| assert_equal(1, result.assertions) |
|
(We'll use the PR description for commit message.) |
|
Thanks for the context! Updated. |
|
Would you want another PR to support open struct? RR looks to be quite backward compatible to me. If you want to keep the backwards compatible promise, I suggest the 'defined?' check for now. |
I've already fixed it :-) |
This PR updates Minitest assertion counts when using
assert_received, aligning with a recent update in Rails 7.2. From Rails 7.2, tests without assertions emit warnings like "Test is missing assertions". This update no longer triggers Rails' warnings.