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

Make `assert_difference` return the result of the yielded block. #21754

Merged
merged 1 commit into from Sep 24, 2015

Conversation

Projects
None yet
2 participants
@lucasmazza
Member

lucasmazza commented Sep 24, 2015

With this we can perform new assertions on the returned value without having
to cache it with an outer variable or wrapping all subsequent assertions inside
the assert_difference block.

Before:

post = nil
assert_difference -> { Post.count }, 1 do
  Post.create
end

assert_predicate post, :persisted?

Now:

post = assert_difference -> { Post.count } do
  Post.create
end

assert_predicate post, :persisted?
@rafaelfranca

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Sep 24, 2015

Member

Could you add a CHANGELOG entry?

Member

rafaelfranca commented Sep 24, 2015

Could you add a CHANGELOG entry?

@lucasmazza

This comment has been minimized.

Show comment
Hide comment
@lucasmazza
Member

lucasmazza commented Sep 24, 2015

Make `assert_difference` return the result of the yielded block.
With this we can perform new assertions on the returned value without having
to cache it with an outer variable or wrapping all subsequent assertions inside
the `assert_difference` block.

Before:

```
post = nil
assert_difference -> { Post.count }, 1 do
  Post.create
end

assert_predicate post, :persisted?
```

Now:

```
post = assert_difference -> { Post.count } do
  Post.create
end

assert_predicate post, :persisted?
```

rafaelfranca added a commit that referenced this pull request Sep 24, 2015

Merge pull request #21754 from lucasmazza/lm-assert-difference
Make `assert_difference` return the result of the yielded block.

@rafaelfranca rafaelfranca merged commit adfb823 into rails:master Sep 24, 2015

1 check was pending

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details

@lucasmazza lucasmazza deleted the lucasmazza:lm-assert-difference branch Sep 24, 2015

@lucasmazza

This comment has been minimized.

Show comment
Hide comment
@lucasmazza
Member

lucasmazza commented Sep 24, 2015

@rafaelfranca thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment