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

find_in_batches should not mutate its argument #13878

Merged
merged 1 commit into from
Jan 30, 2014

Conversation

marcandre
Copy link
Contributor

@rafaelfranca
Copy link
Member

Of course it should not. 👍

@@ -153,6 +153,12 @@ def test_find_in_batches_should_not_ignore_the_default_scope_if_it_is_other_then
assert_equal special_posts_ids, posts.map(&:id)
end

def test_find_in_batches_should_not_modify_passed_options
assert_nothing_raised do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We avoid to use assert_nothing_raised. Can we assert that a enumerable is returned?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely understand why assert_nothing_raised should be used very sparingly, I've seen many cases where it shouldn't.

I don't believe this is one of them though.

Note that testing that an Enumerable is returned is wrong for two reasons.

  1. It doesn't actually work, because the argument is mutated only when consuming it!
  2. I believe it puts the focus on the wrong thing. This test is not about what is returned, but about the fact that it doesn't blow up when given a frozen argument. We know what should be the effect and what should be returned, that's already covered in other tests.

I probably should blog about this, but here are the conditions for usage of assert_nothing_raised:

  1. What is in the block is not present in any other test.
  2. The test is solely about the fact that something doesn't blow up; in particular there are no other assertions in the test.

Then, and only then, one should use assert_nothing_raised. This is the case here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your reasons but assert_nothing_raised doesn't do anything. It can be used for documentation reasons but it doesn't assert any value. If an exception is raised, the test will fail with ou without assert_nothing_raised.

I'll accept it as it is since this is a minor thing.

@ghost ghost assigned rafaelfranca Jan 30, 2014
rafaelfranca added a commit that referenced this pull request Jan 30, 2014
find_in_batches should not mutate its argument
@rafaelfranca rafaelfranca merged commit 7f5466d into rails:master Jan 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants