aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-01-04 23:14:51 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-01-04 23:14:51 +0900
commitcb86b95b609c8aa52411322f5a8e0f128696e068 (patch)
tree5f0f5d3af1d1606829be90d37ff014d5c890933c /activesupport
parent652258e41a882acccdb9a3ce211dbf356e738b28 (diff)
parentaf0361da0ac7e5b7703e772ce69c21c3315a54d0 (diff)
downloadrails-cb86b95b609c8aa52411322f5a8e0f128696e068.tar.gz
rails-cb86b95b609c8aa52411322f5a8e0f128696e068.tar.bz2
rails-cb86b95b609c8aa52411322f5a8e0f128696e068.zip
Merge pull request #31011 from danielma/dma/assert-changes-with-to-should-still-assert-change
`assert_changes` should always assert some change
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG.md8
-rw-r--r--activesupport/lib/active_support/testing/assertions.rb11
-rw-r--r--activesupport/test/test_case_test.rb11
3 files changed, 24 insertions, 6 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index fccaeb5d32..3f77b191f9 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -1,10 +1,16 @@
+* `assert_changes` will always assert that the expression changes,
+ regardless of `from:` and `to:` argument combinations.
+
+ *Daniel Ma*
+
* Allow the hash function used to generate non-sensitive digests, such as the
ETag header, to be specified with `config.active_support.hash_digest_class`.
The object provided must respond to `#hexdigest`, e.g. `Digest::SHA1`.
*Dmitri Dolguikh*
-
+
+
## Rails 5.2.0.beta2 (November 28, 2017) ##
* No changes.
diff --git a/activesupport/lib/active_support/testing/assertions.rb b/activesupport/lib/active_support/testing/assertions.rb
index b24aa36ede..6f69c48674 100644
--- a/activesupport/lib/active_support/testing/assertions.rb
+++ b/activesupport/lib/active_support/testing/assertions.rb
@@ -156,11 +156,12 @@ module ActiveSupport
after = exp.call
- if to == UNTRACKED
- error = "#{expression.inspect} didn't change"
- error = "#{message}.\n#{error}" if message
- assert before != after, error
- else
+ error = "#{expression.inspect} didn't change"
+ error = "#{error}. It was already #{to}" if before == to
+ error = "#{message}.\n#{error}" if message
+ assert before != after, error
+
+ unless to == UNTRACKED
error = "#{expression.inspect} didn't change to #{to}"
error = "#{message}.\n#{error}" if message
assert to === after, error
diff --git a/activesupport/test/test_case_test.rb b/activesupport/test/test_case_test.rb
index 84e4953fe2..79b75a001a 100644
--- a/activesupport/test/test_case_test.rb
+++ b/activesupport/test/test_case_test.rb
@@ -156,6 +156,16 @@ class AssertDifferenceTest < ActiveSupport::TestCase
end
end
+ def test_assert_changes_with_to_option_but_no_change_has_special_message
+ error = assert_raises Minitest::Assertion do
+ assert_changes "@object.num", to: 0 do
+ # no changes
+ end
+ end
+
+ assert_equal "\"@object.num\" didn't change. It was already 0", error.message
+ end
+
def test_assert_changes_with_wrong_to_option
assert_raises Minitest::Assertion do
assert_changes "@object.num", to: 2 do
@@ -218,6 +228,7 @@ class AssertDifferenceTest < ActiveSupport::TestCase
def test_assert_changes_with_message
error = assert_raises Minitest::Assertion do
assert_changes "@object.num", "@object.num should 1", to: 1 do
+ @object.decrement
end
end