minitest-mock_expectations 1.1.1 → 1.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9f39433eab710b34b5fab6078b743f1a345a0a242c2f3a31d3d8ea4564609c3
4
- data.tar.gz: 3a06f63076588965aa9a3ea2b0ceac73015dd3dacb6478d390efc09bd8ef846f
3
+ metadata.gz: 2adcab05aae81e343becab28c6f8c3181f92d81294de224656ea678cf96004d5
4
+ data.tar.gz: 2fe148fee3686d80e0509a5711f523aa5b407b7fd929e4719fef734972943a4a
5
5
  SHA512:
6
- metadata.gz: 1e7bfc343ab7fa29ec34c0bdcd90299dfd7113cf740fe0d937fe41f5217064b787607ae9c09da8134996cd36c398a839611381eef7a09dab5f5b83caad9057a3
7
- data.tar.gz: b54791b53a5b9c396445662c30a335131a22dd539da0724ab501a6a0bd398f5cd99b69a4489adbdac42b10869b846c0663f946a75e27080ceb6c0f927aacf1d3
6
+ metadata.gz: 236932920587374d39cc3837c54db5a9bb5464c86c45375152975cf95f72b6e7128ca6ec4617a682952b1f27360e545b7b22a18c524d2fa14dbdddcdcbc3c1d8
7
+ data.tar.gz: 3ef5fcf49a4b74aa1eb5f0d3427e37bad70a12c80591f79661291c9df3517eda76689732b327c0024930a2adb13f7067e0afadfdbcb1833eb84582851fdd2e31
@@ -0,0 +1,22 @@
1
+ name: CI
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ matrix:
10
+ ruby: [2.5.x, 2.6.x, 2.7.x]
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - name: Set up Ruby
14
+ uses: actions/setup-ruby@v1
15
+ with:
16
+ ruby-version: ${{ matrix.ruby }}
17
+ - name: Install dependencies
18
+ run: |
19
+ gem install bundler
20
+ bundle install
21
+ - name: Run tests
22
+ run: bundle exec rake test
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 1.1.2 / Aprir 24, 2020
2
+
3
+ * Fix `assert_called_with` with an array as expected argument.
4
+
5
+ * Fix COPYRIGHT HOLDER of LICENSE.txt.
6
+
1
7
  ### 1.1.1 / February 26, 2019
2
8
 
3
9
  ### 1.1.0 / February 26, 2019
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- minitest-mock_expectations (1.1.1)
4
+ minitest-mock_expectations (1.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  minitest (5.11.3)
10
- rake (10.5.0)
10
+ rake (12.3.3)
11
11
 
12
12
  PLATFORMS
13
13
  ruby
@@ -19,4 +19,4 @@ DEPENDENCIES
19
19
  rake
20
20
 
21
21
  BUNDLED WITH
22
- 2.0.1
22
+ 2.1.2
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018 bogdanvlviv
3
+ Copyright (c) 2018 David Heinemeier Hansson
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -136,6 +136,38 @@ assert_called_with(@post, :add_comment, [["Thanks for sharing this."], ["Thanks!
136
136
  end
137
137
  ```
138
138
 
139
+ ```ruby
140
+ assert_called_with(@post, :add_comment, [["Thanks for sharing this."]]) do
141
+ @post.add_comment(["Thanks for sharing this."])
142
+ end
143
+ ```
144
+
145
+ ```ruby
146
+ assert_called_with(@post, :add_comment, [["Thanks for sharing this.", "Thanks!"]]) do
147
+ @post.add_comment(["Thanks for sharing this.", "Thanks!"])
148
+ end
149
+ ```
150
+
151
+ ```ruby
152
+ assert_called_with(@post, :add_comment, [["Thanks for sharing this."], {body: "Thanks!"}]) do
153
+ @post.add_comment(["Thanks for sharing this."], {body: "Thanks!"})
154
+ end
155
+ ```
156
+
157
+ ```ruby
158
+ assert_called_with(@post, :add_comment, [[["Thanks for sharing this."]], [{body: "Thanks!"}]]) do
159
+ @post.add_comment(["Thanks for sharing this."])
160
+ @post.add_comment({body: "Thanks!"})
161
+ end
162
+ ```
163
+
164
+ ```ruby
165
+ assert_called_with(@post, :add_comment, [[["Thanks for sharing this."]], [["Thanks!"]]]) do
166
+ @post.add_comment(["Thanks for sharing this."])
167
+ @post.add_comment(["Thanks!"])
168
+ end
169
+ ```
170
+
139
171
  ### assert_called_on_instance_of(klass, method_name, message = nil, times: 1, returns: nil)
140
172
 
141
173
  Asserts that the method will be called on an instance of the `klass` in the block
@@ -98,10 +98,33 @@ module Minitest
98
98
  # @post.add_comment("Thanks for sharing this.")
99
99
  # @post.add_comment("Thanks!")
100
100
  # end
101
+ #
102
+ # assert_called_with(@post, :add_comment, [["Thanks for sharing this."]]) do
103
+ # @post.add_comment(["Thanks for sharing this."])
104
+ # end
105
+ #
106
+ # assert_called_with(@post, :add_comment, [["Thanks for sharing this.", "Thanks!"]]) do
107
+ # @post.add_comment(["Thanks for sharing this.", "Thanks!"])
108
+ # end
109
+ #
110
+ # assert_called_with(@post, :add_comment, [["Thanks for sharing this."], {body: "Thanks!"}]) do
111
+ # @post.add_comment(["Thanks for sharing this."], {body: "Thanks!"})
112
+ # end
113
+ #
114
+ # assert_called_with(@post, :add_comment, [[["Thanks for sharing this."]], [{body: "Thanks!"}]]) do
115
+ # @post.add_comment(["Thanks for sharing this."])
116
+ # @post.add_comment({body: "Thanks!"})
117
+ # end
118
+ #
119
+ # assert_called_with(@post, :add_comment, [[["Thanks for sharing this."]], [["Thanks!"]]]) do
120
+ # @post.add_comment(["Thanks for sharing this."])
121
+ # @post.add_comment(["Thanks!"])
122
+ # end
123
+ #
101
124
  def assert_called_with(object, method_name, arguments, returns: nil)
102
125
  mock = Minitest::Mock.new
103
126
 
104
- if arguments.all? { |argument| argument.is_a?(Array) }
127
+ if arguments.size > 1 && arguments.all? { |argument| argument.is_a?(Array) }
105
128
  arguments.each { |argument| mock.expect(:call, returns, argument) }
106
129
  else
107
130
  mock.expect(:call, returns, arguments)
@@ -1,5 +1,5 @@
1
1
  module Minitest
2
2
  module MockExpectations
3
- VERSION = "1.1.1"
3
+ VERSION = "1.1.2"
4
4
  end
5
5
  end
@@ -56,7 +56,7 @@ class Minitest::MockExpectations::AssertionsTest < Minitest::Test
56
56
  assert_equal "What is new in Rails 6.0", @post.title
57
57
  end
58
58
 
59
- def test_assert_called_failure
59
+ def test_assert_called_failure_because_method_has_not_been_called
60
60
  error = assert_raises(Minitest::Assertion) do
61
61
  assert_called(@post, :title) do
62
62
  @post.body
@@ -66,7 +66,18 @@ class Minitest::MockExpectations::AssertionsTest < Minitest::Test
66
66
  assert_equal "Expected title to be called 1 times, but was called 0 times.\nExpected: 1\n Actual: 0", error.message
67
67
  end
68
68
 
69
- def test_assert_called_with_message
69
+ def test_assert_called_failure_because_method_has_been_called_more_than_expected_times
70
+ error = assert_raises(Minitest::Assertion) do
71
+ assert_called(@post, :title) do
72
+ @post.title
73
+ @post.title
74
+ end
75
+ end
76
+
77
+ assert_equal "Expected title to be called 1 times, but was called 2 times.\nExpected: 1\n Actual: 2", error.message
78
+ end
79
+
80
+ def test_assert_called_failure_with_message
70
81
  error = assert_raises(Minitest::Assertion) do
71
82
  assert_called(@post, :title, "Message") do
72
83
  @post.body
@@ -82,7 +93,7 @@ class Minitest::MockExpectations::AssertionsTest < Minitest::Test
82
93
  end
83
94
  end
84
95
 
85
- def test_refute_called_failure
96
+ def test_refute_called_failure_because_method_has_been_called
86
97
  error = assert_raises(Minitest::Assertion) do
87
98
  refute_called(@post, :add_comment) do
88
99
  @post.add_comment("Thanks for sharing this.")
@@ -92,7 +103,7 @@ class Minitest::MockExpectations::AssertionsTest < Minitest::Test
92
103
  assert_equal "Expected add_comment to be called 0 times, but was called 1 times.\nExpected: 0\n Actual: 1", error.message
93
104
  end
94
105
 
95
- def test_refute_called_with_message
106
+ def test_refute_called_failure_with_message
96
107
  error = assert_raises(Minitest::Assertion) do
97
108
  refute_called(@post, :title, "Message") do
98
109
  @post.title
@@ -120,7 +131,7 @@ class Minitest::MockExpectations::AssertionsTest < Minitest::Test
120
131
  assert_equal "Thank you!", @post.add_comment("Thanks for sharing this.")
121
132
  end
122
133
 
123
- def test_assert_called_with_failure
134
+ def test_assert_called_with_failure_because_method_has_not_been_called_with_expected_arguments
124
135
  assert_raises(MockExpectationError) do
125
136
  assert_called_with(@post, :add_comment, ["Thanks for sharing this."]) do
126
137
  @post.add_comment("Thanks")
@@ -135,6 +146,36 @@ class Minitest::MockExpectations::AssertionsTest < Minitest::Test
135
146
  end
136
147
  end
137
148
 
149
+ def test_assert_called_with_an_array_as_expected_argument
150
+ assert_called_with(@post, :add_comment, [["Thanks for sharing this."]]) do
151
+ @post.add_comment(["Thanks for sharing this."])
152
+ end
153
+
154
+ assert_called_with(@post, :add_comment, [["Thanks for sharing this.", "Thanks!"]]) do
155
+ @post.add_comment(["Thanks for sharing this.", "Thanks!"])
156
+ end
157
+ end
158
+
159
+ def test_assert_called_with_multiple_expected_arguments_as_arrays
160
+ assert_called_with(@post, :add_comment, [[["Thanks for sharing this."]], [["Thanks!"]]]) do
161
+ @post.add_comment(["Thanks for sharing this."])
162
+ @post.add_comment(["Thanks!"])
163
+ end
164
+ end
165
+
166
+ def test_assert_called_with_expected_arguments_as_array_and_one_non_array_object
167
+ assert_called_with(@post, :add_comment, [["Thanks for sharing this."], {body: "Thanks!"}]) do
168
+ @post.add_comment(["Thanks for sharing this."], {body: "Thanks!"})
169
+ end
170
+ end
171
+
172
+ def test_assert_called_with_multiple_expected_arguments_as_array_and_one_non_array_object
173
+ assert_called_with(@post, :add_comment, [[["Thanks for sharing this."]], [{body: "Thanks!"}]]) do
174
+ @post.add_comment(["Thanks for sharing this."])
175
+ @post.add_comment({body: "Thanks!"})
176
+ end
177
+ end
178
+
138
179
  def test_assert_called_on_instance_of_with_defaults_to_expect_once
139
180
  assert_called_on_instance_of(Post, :title) do
140
181
  @post.title
@@ -162,7 +203,7 @@ class Minitest::MockExpectations::AssertionsTest < Minitest::Test
162
203
  assert_equal "What is new in Rails 6.0", @post.title
163
204
  end
164
205
 
165
- def test_assert_called_on_instance_of_failure
206
+ def test_assert_called_on_instance_of_failure_because_method_has_not_been_called
166
207
  error = assert_raises(Minitest::Assertion) do
167
208
  assert_called_on_instance_of(Post, :title) do
168
209
  @post.body
@@ -172,7 +213,18 @@ class Minitest::MockExpectations::AssertionsTest < Minitest::Test
172
213
  assert_equal "Expected title to be called 1 times, but was called 0 times.\nExpected: 1\n Actual: 0", error.message
173
214
  end
174
215
 
175
- def test_assert_called_on_instance_of_with_message
216
+ def test_assert_called_on_instance_of_failure_because_method_has_been_called_more_than_expected_times
217
+ error = assert_raises(Minitest::Assertion) do
218
+ assert_called_on_instance_of(Post, :title) do
219
+ @post.title
220
+ @post.title
221
+ end
222
+ end
223
+
224
+ assert_equal "Expected title to be called 1 times, but was called 2 times.\nExpected: 1\n Actual: 2", error.message
225
+ end
226
+
227
+ def test_assert_called_on_instance_of_failure_with_message
176
228
  error = assert_raises(Minitest::Assertion) do
177
229
  assert_called_on_instance_of(Post, :title, "Message") do
178
230
  @post.body
@@ -200,7 +252,7 @@ class Minitest::MockExpectations::AssertionsTest < Minitest::Test
200
252
  end
201
253
  end
202
254
 
203
- def test_refute_called_on_instance_of_failure
255
+ def test_refute_called_on_instance_of_failure_because_method_has_been_called
204
256
  error = assert_raises(Minitest::Assertion) do
205
257
  refute_called_on_instance_of(Post, :add_comment) do
206
258
  @post.add_comment("Thanks for sharing this.")
@@ -210,7 +262,7 @@ class Minitest::MockExpectations::AssertionsTest < Minitest::Test
210
262
  assert_equal "Expected add_comment to be called 0 times, but was called 1 times.\nExpected: 0\n Actual: 1", error.message
211
263
  end
212
264
 
213
- def test_refute_called_on_instance_of_with_message
265
+ def test_refute_called_on_instance_of_failure_with_message
214
266
  error = assert_raises(Minitest::Assertion) do
215
267
  refute_called_on_instance_of(Post, :title, "Message") do
216
268
  @post.title
@@ -228,7 +280,7 @@ class Minitest::MockExpectations::AssertionsTest < Minitest::Test
228
280
  end
229
281
  end
230
282
 
231
- def test_assert_called_on_instance_of_is_alias_for_refute_called
283
+ def test_assert_not_called_on_instance_of_is_alias_for_refute_called
232
284
  assert method(:assert_not_called_on_instance_of).eql?(method(:refute_called_on_instance_of))
233
285
  end
234
286
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-mock_expectations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - bogdanvlviv
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-26 00:00:00.000000000 Z
11
+ date: 2020-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -59,7 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - ".travis.yml"
62
+ - ".github/workflows/ci.yml"
63
63
  - CHANGELOG.md
64
64
  - Gemfile
65
65
  - Gemfile.lock
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  requirements: []
95
- rubygems_version: 3.0.1
95
+ rubygems_version: 3.1.2
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: Provides method call assertions for minitest
data/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.5.3
5
- - 2.6.1
6
- - ruby-head
7
- before_install: gem install bundler
8
-
9
- matrix:
10
- allow_failures:
11
- - rvm: ruby-head