better_assert_difference 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -4
- data/lib/better_assert_difference.rb +6 -2
- data/lib/better_assert_difference/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7b5b903c053c442c1c61a6fe9883422d3d43234
|
4
|
+
data.tar.gz: baf2fb15c8b167b86e3a98eaedc00b66ad547b5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6bad4fb9ac72ab210a3ba03181066ac6bc66ba8e1945cbb23f494a89080a0d5c434be39ebc69f9d5045838373a0a02f1d83c95fb467cbe53779723c8f445a71
|
7
|
+
data.tar.gz: 61def753fb6c64014f4b872fd9a113b19a5062d3275c8e5bf2b35670f213eb55b5dfb9c1e6aa0f9ae5101ee616e3ef33bc8e69b1699592d445dc1495887e7416
|
data/README.md
CHANGED
@@ -48,9 +48,11 @@ You can use `assert_difference` just as usual with string expressions or procs:
|
|
48
48
|
```
|
49
49
|
|
50
50
|
#### Implicit call of `count` on ActiveRecord relations
|
51
|
-
Most of the time you'll want to execute `count` on ActiveRecord::Relation objects, this call is now implicit and you won't have to
|
52
|
-
use a string expression or a proc.
|
51
|
+
Most of the time you'll want to execute `count` on ActiveRecord::Relation objects, this call is now implicit and you won't have to use a string expression or a proc.
|
53
52
|
```ruby
|
53
|
+
assert_difference(Foo, 3) do
|
54
|
+
# block omitted
|
55
|
+
end
|
54
56
|
assert_difference(Foo.where(bar: true)) do
|
55
57
|
# block omitted
|
56
58
|
end
|
@@ -68,8 +70,8 @@ Specify an expected difference for each expression:
|
|
68
70
|
assert_difference will list all the assertions that have failed, not just the first one.
|
69
71
|
```console
|
70
72
|
Test failure:
|
71
|
-
@items.select(&:nil?).count didn't change by 2
|
72
|
-
@items.count didn't change by 3
|
73
|
+
@items.select(&:nil?).count didn't change by 2 (before: 0, after: 1)
|
74
|
+
@items.count didn't change by 3 (before: 2, after: 5)
|
73
75
|
```
|
74
76
|
## Contributing
|
75
77
|
|
@@ -31,11 +31,15 @@ module BetterAssertDifference
|
|
31
31
|
errors = []
|
32
32
|
before.zip(after, expression_to_diff) do |before_value, after_value, (exp, diff)|
|
33
33
|
next if before_value + diff == after_value
|
34
|
-
error
|
34
|
+
error = "[#{expression_to_diff.find_index { |expression, _| expression == exp }}] " if expression_to_diff.size > 1
|
35
|
+
error = "#{error}#{exp.inspect} didn't change by #{diff} {before: #{before_value}, after: #{after_value}}"
|
35
36
|
error = "#{message}.\n#{error}" if message
|
36
37
|
errors << error
|
37
38
|
end
|
38
|
-
|
39
|
+
if errors.any?
|
40
|
+
errors.unshift "#{errors.size} assertion#{errors.length > 1 ? 's' : ''} failed:"
|
41
|
+
fail errors.join("\n")
|
42
|
+
end
|
39
43
|
|
40
44
|
retval
|
41
45
|
end
|