rspec-change_collection 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Changelog.md +4 -0
- data/Gemfile +27 -0
- data/Gemfile.lock +294 -0
- data/LICENSE.txt +28 -0
- data/README.md +43 -0
- data/Rakefile +13 -0
- data/lib/rspec/change_collection.rb +172 -0
- data/lib/rspec/change_collection/version.rb +5 -0
- data/rspec-change_collection.gemspec +26 -0
- data/script/test_all +13 -0
- data/spec/rspec/change_collection_spec.rb +233 -0
- data/spec/spec_helper.rb +15 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 35c1ee5d89f409e7c505ae39bbeabbfd5cd24ed2
|
4
|
+
data.tar.gz: 8f0ff47697b3bfc820986294caac6ff53e77a150
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e5ca1c7ff55c451e9de650af42801839f8932d4e9936f224376b76d2f956731a4d61e60774a5399cf9d93b358bbcfa1a1bd7c6dc9b947961f54abc481da91d06
|
7
|
+
data.tar.gz: 125a3c749b10661f0ca74c0f9069d47be24acfd08ec52e026e77b807d8d80439e1c885232b872279594488e634f6c33da6cc0acb848b6eb476c7adc22bd708f3
|
data/.gitignore
ADDED
data/Changelog.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in rspec-change_collection.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
%w[rspec rspec-core rspec-expectations rspec-mocks rspec-support].each do |lib|
|
7
|
+
branch = ENV.fetch('BRANCH','master')
|
8
|
+
next if branch == '2-99-maintenance' && lib == 'rspec-support'
|
9
|
+
library_path = File.expand_path("../../#{lib}", __FILE__)
|
10
|
+
if File.exist?(library_path)
|
11
|
+
gem lib, :path => library_path
|
12
|
+
else
|
13
|
+
gem lib, :git => "git://github.com/rspec/#{lib}.git",
|
14
|
+
:branch => branch
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# test coverage
|
19
|
+
# gem 'simplecov', :require => false
|
20
|
+
|
21
|
+
gem 'coveralls', :require => false, :platform => :mri_20
|
22
|
+
|
23
|
+
eval File.read('Gemfile-custom') if File.exist?('Gemfile-custom')
|
24
|
+
|
25
|
+
platform :rbx do
|
26
|
+
gem 'rubysl'
|
27
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,294 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/rspec/rspec-core.git
|
3
|
+
revision: e0a8404b0ab3f7803eedca9572f3fbfbea915bd6
|
4
|
+
branch: master
|
5
|
+
specs:
|
6
|
+
rspec-core (3.1.0.pre)
|
7
|
+
rspec-support (= 3.1.0.pre)
|
8
|
+
|
9
|
+
GIT
|
10
|
+
remote: git://github.com/rspec/rspec-expectations.git
|
11
|
+
revision: e4674ca2440d22ecfe59be6fe351396dbe9b4369
|
12
|
+
branch: master
|
13
|
+
specs:
|
14
|
+
rspec-expectations (3.1.0.pre)
|
15
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
16
|
+
rspec-support (= 3.1.0.pre)
|
17
|
+
|
18
|
+
GIT
|
19
|
+
remote: git://github.com/rspec/rspec-mocks.git
|
20
|
+
revision: 873d755efe61d500444c230dc3b7f4f9d24aed43
|
21
|
+
branch: master
|
22
|
+
specs:
|
23
|
+
rspec-mocks (3.1.0.pre)
|
24
|
+
rspec-support (= 3.1.0.pre)
|
25
|
+
|
26
|
+
GIT
|
27
|
+
remote: git://github.com/rspec/rspec-support.git
|
28
|
+
revision: ba5b67666514d5808da13ddaafefc8c597e553e1
|
29
|
+
branch: master
|
30
|
+
specs:
|
31
|
+
rspec-support (3.1.0.pre)
|
32
|
+
|
33
|
+
GIT
|
34
|
+
remote: git://github.com/rspec/rspec.git
|
35
|
+
revision: 2b826653e1f55f63e4f99d8dd1f14b5d35d0a0b7
|
36
|
+
branch: master
|
37
|
+
specs:
|
38
|
+
rspec (3.1.0.pre)
|
39
|
+
rspec-core (= 3.1.0.pre)
|
40
|
+
rspec-expectations (= 3.1.0.pre)
|
41
|
+
rspec-mocks (= 3.1.0.pre)
|
42
|
+
|
43
|
+
PATH
|
44
|
+
remote: .
|
45
|
+
specs:
|
46
|
+
rspec-change_collection (1.0.0)
|
47
|
+
rspec-core (>= 2.99.0.beta1)
|
48
|
+
rspec-expectations (>= 2.99.0.beta1)
|
49
|
+
|
50
|
+
GEM
|
51
|
+
remote: https://rubygems.org/
|
52
|
+
specs:
|
53
|
+
coveralls (0.7.0)
|
54
|
+
multi_json (~> 1.3)
|
55
|
+
rest-client
|
56
|
+
simplecov (>= 0.7)
|
57
|
+
term-ansicolor
|
58
|
+
thor
|
59
|
+
diff-lcs (1.2.5)
|
60
|
+
docile (1.1.5)
|
61
|
+
ffi2-generators (0.1.1)
|
62
|
+
mime-types (2.3)
|
63
|
+
multi_json (1.10.1)
|
64
|
+
netrc (0.7.7)
|
65
|
+
rake (10.1.1)
|
66
|
+
rest-client (1.7.2)
|
67
|
+
mime-types (>= 1.16, < 3.0)
|
68
|
+
netrc (~> 0.7)
|
69
|
+
rubysl (2.0.15)
|
70
|
+
rubysl-abbrev (~> 2.0)
|
71
|
+
rubysl-base64 (~> 2.0)
|
72
|
+
rubysl-benchmark (~> 2.0)
|
73
|
+
rubysl-bigdecimal (~> 2.0)
|
74
|
+
rubysl-cgi (~> 2.0)
|
75
|
+
rubysl-cgi-session (~> 2.0)
|
76
|
+
rubysl-cmath (~> 2.0)
|
77
|
+
rubysl-complex (~> 2.0)
|
78
|
+
rubysl-continuation (~> 2.0)
|
79
|
+
rubysl-coverage (~> 2.0)
|
80
|
+
rubysl-csv (~> 2.0)
|
81
|
+
rubysl-curses (~> 2.0)
|
82
|
+
rubysl-date (~> 2.0)
|
83
|
+
rubysl-delegate (~> 2.0)
|
84
|
+
rubysl-digest (~> 2.0)
|
85
|
+
rubysl-drb (~> 2.0)
|
86
|
+
rubysl-e2mmap (~> 2.0)
|
87
|
+
rubysl-english (~> 2.0)
|
88
|
+
rubysl-enumerator (~> 2.0)
|
89
|
+
rubysl-erb (~> 2.0)
|
90
|
+
rubysl-etc (~> 2.0)
|
91
|
+
rubysl-expect (~> 2.0)
|
92
|
+
rubysl-fcntl (~> 2.0)
|
93
|
+
rubysl-fiber (~> 2.0)
|
94
|
+
rubysl-fileutils (~> 2.0)
|
95
|
+
rubysl-find (~> 2.0)
|
96
|
+
rubysl-forwardable (~> 2.0)
|
97
|
+
rubysl-getoptlong (~> 2.0)
|
98
|
+
rubysl-gserver (~> 2.0)
|
99
|
+
rubysl-io-console (~> 2.0)
|
100
|
+
rubysl-io-nonblock (~> 2.0)
|
101
|
+
rubysl-io-wait (~> 2.0)
|
102
|
+
rubysl-ipaddr (~> 2.0)
|
103
|
+
rubysl-irb (~> 2.0)
|
104
|
+
rubysl-logger (~> 2.0)
|
105
|
+
rubysl-mathn (~> 2.0)
|
106
|
+
rubysl-matrix (~> 2.0)
|
107
|
+
rubysl-mkmf (~> 2.0)
|
108
|
+
rubysl-monitor (~> 2.0)
|
109
|
+
rubysl-mutex_m (~> 2.0)
|
110
|
+
rubysl-net-ftp (~> 2.0)
|
111
|
+
rubysl-net-http (~> 2.0)
|
112
|
+
rubysl-net-imap (~> 2.0)
|
113
|
+
rubysl-net-pop (~> 2.0)
|
114
|
+
rubysl-net-protocol (~> 2.0)
|
115
|
+
rubysl-net-smtp (~> 2.0)
|
116
|
+
rubysl-net-telnet (~> 2.0)
|
117
|
+
rubysl-nkf (~> 2.0)
|
118
|
+
rubysl-observer (~> 2.0)
|
119
|
+
rubysl-open-uri (~> 2.0)
|
120
|
+
rubysl-open3 (~> 2.0)
|
121
|
+
rubysl-openssl (~> 2.0)
|
122
|
+
rubysl-optparse (~> 2.0)
|
123
|
+
rubysl-ostruct (~> 2.0)
|
124
|
+
rubysl-pathname (~> 2.0)
|
125
|
+
rubysl-prettyprint (~> 2.0)
|
126
|
+
rubysl-prime (~> 2.0)
|
127
|
+
rubysl-profile (~> 2.0)
|
128
|
+
rubysl-profiler (~> 2.0)
|
129
|
+
rubysl-pstore (~> 2.0)
|
130
|
+
rubysl-pty (~> 2.0)
|
131
|
+
rubysl-rational (~> 2.0)
|
132
|
+
rubysl-readline (~> 2.0)
|
133
|
+
rubysl-resolv (~> 2.0)
|
134
|
+
rubysl-rexml (~> 2.0)
|
135
|
+
rubysl-rinda (~> 2.0)
|
136
|
+
rubysl-rss (~> 2.0)
|
137
|
+
rubysl-scanf (~> 2.0)
|
138
|
+
rubysl-securerandom (~> 2.0)
|
139
|
+
rubysl-set (~> 2.0)
|
140
|
+
rubysl-shellwords (~> 2.0)
|
141
|
+
rubysl-singleton (~> 2.0)
|
142
|
+
rubysl-socket (~> 2.0)
|
143
|
+
rubysl-stringio (~> 2.0)
|
144
|
+
rubysl-strscan (~> 2.0)
|
145
|
+
rubysl-sync (~> 2.0)
|
146
|
+
rubysl-syslog (~> 2.0)
|
147
|
+
rubysl-tempfile (~> 2.0)
|
148
|
+
rubysl-thread (~> 2.0)
|
149
|
+
rubysl-thwait (~> 2.0)
|
150
|
+
rubysl-time (~> 2.0)
|
151
|
+
rubysl-timeout (~> 2.0)
|
152
|
+
rubysl-tmpdir (~> 2.0)
|
153
|
+
rubysl-tsort (~> 2.0)
|
154
|
+
rubysl-un (~> 2.0)
|
155
|
+
rubysl-uri (~> 2.0)
|
156
|
+
rubysl-weakref (~> 2.0)
|
157
|
+
rubysl-webrick (~> 2.0)
|
158
|
+
rubysl-xmlrpc (~> 2.0)
|
159
|
+
rubysl-yaml (~> 2.0)
|
160
|
+
rubysl-zlib (~> 2.0)
|
161
|
+
rubysl-abbrev (2.0.4)
|
162
|
+
rubysl-base64 (2.0.0)
|
163
|
+
rubysl-benchmark (2.0.1)
|
164
|
+
rubysl-bigdecimal (2.0.2)
|
165
|
+
rubysl-cgi (2.0.1)
|
166
|
+
rubysl-cgi-session (2.0.1)
|
167
|
+
rubysl-cmath (2.0.0)
|
168
|
+
rubysl-complex (2.0.0)
|
169
|
+
rubysl-continuation (2.0.0)
|
170
|
+
rubysl-coverage (2.0.3)
|
171
|
+
rubysl-csv (2.0.2)
|
172
|
+
rubysl-english (~> 2.0)
|
173
|
+
rubysl-curses (2.0.1)
|
174
|
+
rubysl-date (2.0.6)
|
175
|
+
rubysl-delegate (2.0.1)
|
176
|
+
rubysl-digest (2.0.3)
|
177
|
+
rubysl-drb (2.0.1)
|
178
|
+
rubysl-e2mmap (2.0.0)
|
179
|
+
rubysl-english (2.0.0)
|
180
|
+
rubysl-enumerator (2.0.0)
|
181
|
+
rubysl-erb (2.0.1)
|
182
|
+
rubysl-etc (2.0.3)
|
183
|
+
ffi2-generators (~> 0.1)
|
184
|
+
rubysl-expect (2.0.0)
|
185
|
+
rubysl-fcntl (2.0.4)
|
186
|
+
ffi2-generators (~> 0.1)
|
187
|
+
rubysl-fiber (2.0.0)
|
188
|
+
rubysl-fileutils (2.0.3)
|
189
|
+
rubysl-find (2.0.1)
|
190
|
+
rubysl-forwardable (2.0.1)
|
191
|
+
rubysl-getoptlong (2.0.0)
|
192
|
+
rubysl-gserver (2.0.0)
|
193
|
+
rubysl-socket (~> 2.0)
|
194
|
+
rubysl-thread (~> 2.0)
|
195
|
+
rubysl-io-console (2.0.0)
|
196
|
+
rubysl-io-nonblock (2.0.0)
|
197
|
+
rubysl-io-wait (2.0.0)
|
198
|
+
rubysl-ipaddr (2.0.0)
|
199
|
+
rubysl-irb (2.0.4)
|
200
|
+
rubysl-e2mmap (~> 2.0)
|
201
|
+
rubysl-mathn (~> 2.0)
|
202
|
+
rubysl-readline (~> 2.0)
|
203
|
+
rubysl-thread (~> 2.0)
|
204
|
+
rubysl-logger (2.0.0)
|
205
|
+
rubysl-mathn (2.0.0)
|
206
|
+
rubysl-matrix (2.1.0)
|
207
|
+
rubysl-e2mmap (~> 2.0)
|
208
|
+
rubysl-mkmf (2.0.1)
|
209
|
+
rubysl-fileutils (~> 2.0)
|
210
|
+
rubysl-shellwords (~> 2.0)
|
211
|
+
rubysl-monitor (2.0.0)
|
212
|
+
rubysl-mutex_m (2.0.0)
|
213
|
+
rubysl-net-ftp (2.0.1)
|
214
|
+
rubysl-net-http (2.0.4)
|
215
|
+
rubysl-cgi (~> 2.0)
|
216
|
+
rubysl-erb (~> 2.0)
|
217
|
+
rubysl-singleton (~> 2.0)
|
218
|
+
rubysl-net-imap (2.0.1)
|
219
|
+
rubysl-net-pop (2.0.1)
|
220
|
+
rubysl-net-protocol (2.0.1)
|
221
|
+
rubysl-net-smtp (2.0.1)
|
222
|
+
rubysl-net-telnet (2.0.0)
|
223
|
+
rubysl-nkf (2.0.1)
|
224
|
+
rubysl-observer (2.0.0)
|
225
|
+
rubysl-open-uri (2.0.0)
|
226
|
+
rubysl-open3 (2.0.0)
|
227
|
+
rubysl-openssl (2.1.0)
|
228
|
+
rubysl-optparse (2.0.1)
|
229
|
+
rubysl-shellwords (~> 2.0)
|
230
|
+
rubysl-ostruct (2.0.4)
|
231
|
+
rubysl-pathname (2.0.0)
|
232
|
+
rubysl-prettyprint (2.0.3)
|
233
|
+
rubysl-prime (2.0.1)
|
234
|
+
rubysl-profile (2.0.0)
|
235
|
+
rubysl-profiler (2.0.1)
|
236
|
+
rubysl-pstore (2.0.0)
|
237
|
+
rubysl-pty (2.0.2)
|
238
|
+
rubysl-rational (2.0.1)
|
239
|
+
rubysl-readline (2.0.2)
|
240
|
+
rubysl-resolv (2.1.0)
|
241
|
+
rubysl-rexml (2.0.2)
|
242
|
+
rubysl-rinda (2.0.1)
|
243
|
+
rubysl-rss (2.0.0)
|
244
|
+
rubysl-scanf (2.0.0)
|
245
|
+
rubysl-securerandom (2.0.0)
|
246
|
+
rubysl-set (2.0.1)
|
247
|
+
rubysl-shellwords (2.0.0)
|
248
|
+
rubysl-singleton (2.0.0)
|
249
|
+
rubysl-socket (2.0.1)
|
250
|
+
rubysl-stringio (2.0.0)
|
251
|
+
rubysl-strscan (2.0.0)
|
252
|
+
rubysl-sync (2.0.0)
|
253
|
+
rubysl-syslog (2.0.1)
|
254
|
+
ffi2-generators (~> 0.1)
|
255
|
+
rubysl-tempfile (2.0.1)
|
256
|
+
rubysl-thread (2.0.2)
|
257
|
+
rubysl-thwait (2.0.0)
|
258
|
+
rubysl-time (2.0.3)
|
259
|
+
rubysl-timeout (2.0.0)
|
260
|
+
rubysl-tmpdir (2.0.1)
|
261
|
+
rubysl-tsort (2.0.1)
|
262
|
+
rubysl-un (2.0.0)
|
263
|
+
rubysl-fileutils (~> 2.0)
|
264
|
+
rubysl-optparse (~> 2.0)
|
265
|
+
rubysl-uri (2.0.0)
|
266
|
+
rubysl-weakref (2.0.0)
|
267
|
+
rubysl-webrick (2.0.0)
|
268
|
+
rubysl-xmlrpc (2.0.0)
|
269
|
+
rubysl-yaml (2.0.4)
|
270
|
+
rubysl-zlib (2.0.1)
|
271
|
+
simplecov (0.8.2)
|
272
|
+
docile (~> 1.1.0)
|
273
|
+
multi_json
|
274
|
+
simplecov-html (~> 0.8.0)
|
275
|
+
simplecov-html (0.8.0)
|
276
|
+
term-ansicolor (1.3.0)
|
277
|
+
tins (~> 1.0)
|
278
|
+
thor (0.19.1)
|
279
|
+
tins (1.3.0)
|
280
|
+
|
281
|
+
PLATFORMS
|
282
|
+
ruby
|
283
|
+
|
284
|
+
DEPENDENCIES
|
285
|
+
bundler (~> 1.3)
|
286
|
+
coveralls
|
287
|
+
rake (~> 10.1.0)
|
288
|
+
rspec!
|
289
|
+
rspec-change_collection!
|
290
|
+
rspec-core!
|
291
|
+
rspec-expectations!
|
292
|
+
rspec-mocks!
|
293
|
+
rspec-support!
|
294
|
+
rubysl
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Andrew Brown
|
4
|
+
Copyright (c) 2013 Peter Alfvin
|
5
|
+
Copyright (c) 2012 David Chelimsky, Myron Marston
|
6
|
+
Copyright (c) 2006 David Chelimsky, The RSpec Development Team
|
7
|
+
Copyright (c) 2005 Steven Baker
|
8
|
+
|
9
|
+
MIT License
|
10
|
+
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
12
|
+
a copy of this software and associated documentation files (the
|
13
|
+
"Software"), to deal in the Software without restriction, including
|
14
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
15
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
16
|
+
permit persons to whom the Software is furnished to do so, subject to
|
17
|
+
the following conditions:
|
18
|
+
|
19
|
+
The above copyright notice and this permission notice shall be
|
20
|
+
included in all copies or substantial portions of the Software.
|
21
|
+
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
23
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
24
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
25
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
26
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
27
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
28
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# RSpec::ChangeCollection [![Build Status](https://travis-ci.org/dontfidget/rspec-change_collection.png)](https://travis-ci.org/dontfidget/rspec-change_collection)
|
2
|
+
|
3
|
+
RSpec::ChangeCollection provides the `to_include` and `to_exclude` methods to the `change` for blocks that return a collection.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rspec-change_collection'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rspec-change_collection
|
18
|
+
|
19
|
+
And require it as:
|
20
|
+
|
21
|
+
require 'rspec/change_collection'
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Use the `to_include` and `to_exclude` methods to make assertions about the effect of an rspec `change` block.
|
26
|
+
|
27
|
+
Both `to_include` and `to_exclude` accept objects or blocks. You can pass it a list of objects:
|
28
|
+
|
29
|
+
array = []
|
30
|
+
expect { array << 1 << 2 }.to change { array }.to_include 1, 2
|
31
|
+
|
32
|
+
And you can use block to make claims about any of the items before and after the change:
|
33
|
+
|
34
|
+
array = [1]
|
35
|
+
expect { array << 2 }.to change { array }.to_include(&:even?)
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
require 'rspec/change_collection/version'
|
2
|
+
require 'rspec/core'
|
3
|
+
require 'rspec/expectations'
|
4
|
+
|
5
|
+
module RSpec::Matchers
|
6
|
+
module ChangeCollection
|
7
|
+
class Change < RSpec::Matchers::BuiltIn::Change
|
8
|
+
def initialize(receiver=nil, message=nil, &block)
|
9
|
+
@expected_to_include = []
|
10
|
+
@expected_to_exclude = []
|
11
|
+
|
12
|
+
@missing_original_items = []
|
13
|
+
@extra_original_items = []
|
14
|
+
|
15
|
+
@missing_final_items = []
|
16
|
+
@extra_final_items = []
|
17
|
+
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
def matches?(*)
|
22
|
+
@parent_matches = super
|
23
|
+
|
24
|
+
if expect_collection_to_change?
|
25
|
+
actual_before = @change_details.actual_before
|
26
|
+
actual_after = @change_details.actual_after
|
27
|
+
|
28
|
+
if actual_before.respond_to?(:to_ary)
|
29
|
+
@missing_original_items = extract_items(@expected_to_exclude) - actual_before
|
30
|
+
@missing_original_items += reject_procs(actual_before, @expected_to_exclude)
|
31
|
+
@extra_original_items = select_items(actual_before, @expected_to_include) & actual_before
|
32
|
+
end
|
33
|
+
|
34
|
+
if actual_after.respond_to?(:to_ary)
|
35
|
+
@missing_final_items = extract_items(@expected_to_include) - actual_after
|
36
|
+
@missing_final_items += reject_procs(actual_after, @expected_to_include)
|
37
|
+
@extra_final_items = select_items(actual_after, @expected_to_exclude) & actual_after
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
@parent_matches && ![
|
42
|
+
@missing_original_items,
|
43
|
+
@extra_original_items,
|
44
|
+
@missing_final_items,
|
45
|
+
@extra_final_items
|
46
|
+
].map(&:empty?).include?(false)
|
47
|
+
end
|
48
|
+
|
49
|
+
def failure_message
|
50
|
+
if @parent_matches
|
51
|
+
message = ""
|
52
|
+
else
|
53
|
+
message = super
|
54
|
+
end
|
55
|
+
|
56
|
+
if expect_collection_to_change?
|
57
|
+
array_messages = []
|
58
|
+
append_array_message = lambda do |message, values|
|
59
|
+
array_messages << "#{message}#{values.inspect}" if values.length > 0
|
60
|
+
end
|
61
|
+
append_array_message.call(
|
62
|
+
"the original collection should have included: ",
|
63
|
+
@missing_original_items
|
64
|
+
)
|
65
|
+
append_array_message.call(
|
66
|
+
"the original collection should not have included: ",
|
67
|
+
@extra_original_items
|
68
|
+
)
|
69
|
+
append_array_message.call(
|
70
|
+
"the final collection should have included: ",
|
71
|
+
@missing_final_items
|
72
|
+
)
|
73
|
+
append_array_message.call(
|
74
|
+
"the final collection should not have included: ",
|
75
|
+
@extra_final_items
|
76
|
+
)
|
77
|
+
append_array_message.call(
|
78
|
+
"the original collection was: ",
|
79
|
+
@change_details.actual_before
|
80
|
+
)
|
81
|
+
append_array_message.call(
|
82
|
+
"the final collection was: ",
|
83
|
+
@change_details.actual_after
|
84
|
+
)
|
85
|
+
message << "\n#{array_messages.join "\n"}\n" unless array_messages.empty?
|
86
|
+
message
|
87
|
+
end
|
88
|
+
|
89
|
+
message
|
90
|
+
end
|
91
|
+
|
92
|
+
def failure_message_when_negated
|
93
|
+
return "Matcher does not support negation" if expect_collection_to_change?
|
94
|
+
super
|
95
|
+
end
|
96
|
+
|
97
|
+
def to_include(*items, &block)
|
98
|
+
check_arguments(__method__, *items, &block)
|
99
|
+
@expected_to_include << items
|
100
|
+
@expected_to_include << block if block
|
101
|
+
self
|
102
|
+
end
|
103
|
+
|
104
|
+
def to_exclude(*items, &block)
|
105
|
+
check_arguments(__method__, *items, &block)
|
106
|
+
@expected_to_exclude << items
|
107
|
+
@expected_to_exclude << block if block
|
108
|
+
self
|
109
|
+
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
def callable?(rule)
|
114
|
+
rule.respond_to?(:call)
|
115
|
+
end
|
116
|
+
|
117
|
+
def extract_items(rules)
|
118
|
+
rules.reject { |rule| callable?(rule) }.flatten(1)
|
119
|
+
end
|
120
|
+
|
121
|
+
def reject_procs(items, rules)
|
122
|
+
rules.select { |rule| callable?(rule) }.reject { |proc| items.any? { |item| proc.call(item) }}
|
123
|
+
end
|
124
|
+
|
125
|
+
def select_items(items, rules)
|
126
|
+
items.select { |item| item_in_rules?(item, rules) }
|
127
|
+
end
|
128
|
+
|
129
|
+
def item_in_rules?(item, rules)
|
130
|
+
rules.any? do |rule|
|
131
|
+
if callable?(rule)
|
132
|
+
rule.call(item)
|
133
|
+
else
|
134
|
+
rule.include?(item)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def expect_collection_to_change?
|
140
|
+
[@expected_to_include, @expected_to_exclude].map(&:empty?).include?(false)
|
141
|
+
end
|
142
|
+
|
143
|
+
def safe_sort(array)
|
144
|
+
array.sort rescue array
|
145
|
+
end
|
146
|
+
|
147
|
+
def check_arguments(method, *items, &block)
|
148
|
+
if block && !items.empty?
|
149
|
+
raise(
|
150
|
+
ArgumentError,
|
151
|
+
"`#{method}` requires either objects " \
|
152
|
+
"(`to_include(obj1, obj2, ...)`) or a block (`to_include { }`) but not both. "
|
153
|
+
)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def change_with_collection(receiver=nil, message=nil, &block)
|
160
|
+
RSpec::Matchers::ChangeCollection::Change.new(receiver, message, &block)
|
161
|
+
end
|
162
|
+
|
163
|
+
alias_method :change_without_collection, :change_with_collection
|
164
|
+
alias_method :change, :change_with_collection
|
165
|
+
end
|
166
|
+
|
167
|
+
RSpec.configure do |rspec|
|
168
|
+
rspec.extend RSpec::Matchers::ChangeCollection
|
169
|
+
rspec.backtrace_exclusion_patterns << %r(/lib/rspec/change_collection)
|
170
|
+
end
|
171
|
+
|
172
|
+
RSpec::SharedContext.send(:include, RSpec::Matchers::ChangeCollection)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rspec/change_collection/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rspec-change_collection"
|
8
|
+
spec.version = RSpec::ChangeCollection::VERSION
|
9
|
+
spec.authors = ["Andrew S. Brown"]
|
10
|
+
spec.email = ["andrew@dontfidget.com"]
|
11
|
+
spec.description = %q{RSpec extension gem for attribute matching}
|
12
|
+
spec.summary = %q{Provides "change_collection" method formally part of rspec-core}
|
13
|
+
spec.homepage = "https://github.com/dontfidget/rspec-change_collection"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'rspec-core', '>= 2.99.0.beta1'
|
22
|
+
spec.add_runtime_dependency 'rspec-expectations', '>= 2.99.0.beta1'
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.1.0'
|
25
|
+
|
26
|
+
end
|
data/script/test_all
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -e -x
|
4
|
+
|
5
|
+
# idea taken from: http://blog.headius.com/2010/03/jruby-startup-time-tips.html
|
6
|
+
export JRUBY_OPTS='-X-C' # disable JIT since these processes are so short lived
|
7
|
+
|
8
|
+
# force jRuby to use client mode JVM or a compilation mode thats as close as possible,
|
9
|
+
# idea taken from https://github.com/jruby/jruby/wiki/Improving-startup-time
|
10
|
+
export JAVA_OPTS='-client -XX:+TieredCompilation -XX:TieredStopAtLevel=1'
|
11
|
+
|
12
|
+
echo "Running rspec specs"
|
13
|
+
bin/rspec spec --format progress --profile
|
@@ -0,0 +1,233 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
describe ChangeCollection do
|
5
|
+
shared_examples_for :original_change do
|
6
|
+
it "detects simple changes" do
|
7
|
+
array = []
|
8
|
+
expect {
|
9
|
+
array = [1]
|
10
|
+
}.to change { array }
|
11
|
+
end
|
12
|
+
|
13
|
+
it "raises exceptions when expectations are not met" do
|
14
|
+
array = []
|
15
|
+
expect {
|
16
|
+
expect {
|
17
|
+
array << 1
|
18
|
+
}.not_to change { array.length }
|
19
|
+
}.to raise_exception(RSpec::Expectations::ExpectationNotMetError)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "provides the 'from' and 'to' change helpers" do
|
23
|
+
array = []
|
24
|
+
expect {
|
25
|
+
expect {
|
26
|
+
array << 1
|
27
|
+
}.to change { array.length }.from(0).to(2)
|
28
|
+
}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "provides the 'by' change helper" do
|
32
|
+
array = []
|
33
|
+
expect {
|
34
|
+
expect {
|
35
|
+
array << 1
|
36
|
+
}.to change { array.length }.by(2)
|
37
|
+
}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#to_include" do
|
42
|
+
it_behaves_like :original_change
|
43
|
+
|
44
|
+
it "succeeds when items have been added to the collection" do
|
45
|
+
array = []
|
46
|
+
expect {
|
47
|
+
array += [1]
|
48
|
+
}.to change { array} .to_include(1)
|
49
|
+
end
|
50
|
+
it "succeeds when multiple items have been added to the collection" do
|
51
|
+
array = []
|
52
|
+
expect {
|
53
|
+
array += [1, 2]
|
54
|
+
}.to change { array }.to_include(1,2)
|
55
|
+
end
|
56
|
+
it "still succeeds when the items are arrays" do
|
57
|
+
array = []
|
58
|
+
expect {
|
59
|
+
array << [1]
|
60
|
+
}.to change { array }.to_include([1])
|
61
|
+
end
|
62
|
+
it "fails when items have not been added to the collection" do
|
63
|
+
array = []
|
64
|
+
expect {
|
65
|
+
expect {
|
66
|
+
}.to change { array }.to_include(1)
|
67
|
+
}.to raise_error(RSpec::Expectations::ExpectationNotMetError,
|
68
|
+
/the final collection should have included.*\[1\]/)
|
69
|
+
end
|
70
|
+
it "fails when any item has not been added to the collection" do
|
71
|
+
array = []
|
72
|
+
expect {
|
73
|
+
expect {
|
74
|
+
array += [1]
|
75
|
+
}.to change { array }.to_include(1,2)
|
76
|
+
}.to raise_error(RSpec::Expectations::ExpectationNotMetError,
|
77
|
+
/the final collection should have included.*\[2\]/)
|
78
|
+
end
|
79
|
+
it "fails when an item to include was already included" do
|
80
|
+
array = [1]
|
81
|
+
expect {
|
82
|
+
expect {
|
83
|
+
}.to change { array }.to_include(1)
|
84
|
+
}.to raise_error(RSpec::Expectations::ExpectationNotMetError,
|
85
|
+
/the original collection should not have included.*\[1\]/)
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "with a block" do
|
89
|
+
it "passes if initial condition is not met by non-empty-array and final condition is met" do
|
90
|
+
array = [1,3]
|
91
|
+
expect {
|
92
|
+
array << 2
|
93
|
+
}.to change { array }.to_include(&:even?)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "passes if initial condition is not met by empty array and final condition is met" do
|
97
|
+
array = []
|
98
|
+
expect {
|
99
|
+
array << 2
|
100
|
+
}.to change { array }.to_include(&:even?)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "fails if initial condition is not met and final condition is still not met" do
|
104
|
+
array = [1,3]
|
105
|
+
expect {
|
106
|
+
expect {
|
107
|
+
array << 5
|
108
|
+
}.to change { array }.to_include(&:even?)
|
109
|
+
}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "fails if there is no change in array" do
|
113
|
+
array = [1,3]
|
114
|
+
expect {
|
115
|
+
expect {
|
116
|
+
# nop
|
117
|
+
}.to change { array }.to_include(&:even?)
|
118
|
+
}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "fails if also passed an item" do
|
122
|
+
array = []
|
123
|
+
expect {
|
124
|
+
expect {
|
125
|
+
# nop
|
126
|
+
}.to change { array }.to_include(1, &:even?)
|
127
|
+
}.to raise_error(ArgumentError)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "#to_exclude" do
|
133
|
+
it_behaves_like :original_change
|
134
|
+
|
135
|
+
it "passes if the specified item has been removed from the collection" do
|
136
|
+
array = [1]
|
137
|
+
expect {
|
138
|
+
array = []
|
139
|
+
}.to change { array }.to_exclude(1)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "passes if all of multiple specified items have been removed from the collection" do
|
143
|
+
array = [1,2]
|
144
|
+
expect {
|
145
|
+
array = []
|
146
|
+
}.to change { array }.to_exclude(1,2)
|
147
|
+
end
|
148
|
+
|
149
|
+
it "fails if any specified item has not been removed from the collection" do
|
150
|
+
array = [1,2]
|
151
|
+
expect {
|
152
|
+
expect {
|
153
|
+
array = [1]
|
154
|
+
}.to change { array }.to_exclude(1,2)
|
155
|
+
}.to raise_error(RSpec::Expectations::ExpectationNotMetError,
|
156
|
+
/the final collection should not have included.*\[1\]/)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "fails if a specified item was never in the collection" do
|
160
|
+
array = []
|
161
|
+
expect {
|
162
|
+
expect {
|
163
|
+
}.to change { array }.to_exclude(1)
|
164
|
+
}.to raise_error(RSpec::Expectations::ExpectationNotMetError,
|
165
|
+
/the original collection should have included.*\[1\]/)
|
166
|
+
end
|
167
|
+
|
168
|
+
it "fails if any specified item was never in the collection" do
|
169
|
+
array = [1]
|
170
|
+
expect {
|
171
|
+
expect {
|
172
|
+
array = []
|
173
|
+
}.to change { array }.to_exclude(1,2)
|
174
|
+
}.to raise_error(RSpec::Expectations::ExpectationNotMetError,
|
175
|
+
/the original collection should have included.*\[2\]/)
|
176
|
+
end
|
177
|
+
|
178
|
+
describe "with a block" do
|
179
|
+
it "passes if initial condition is met and final condition is met" do
|
180
|
+
array = [1,2,3]
|
181
|
+
expect {
|
182
|
+
array -= [2]
|
183
|
+
}.to change { array }.to_exclude(&:even?)
|
184
|
+
end
|
185
|
+
|
186
|
+
it "fails if initial condition is not met by non-empty collection" do
|
187
|
+
array = [1,3]
|
188
|
+
expect {
|
189
|
+
expect {
|
190
|
+
array -= [3]
|
191
|
+
}.to change { array }.to_exclude(&:even?)
|
192
|
+
}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
193
|
+
end
|
194
|
+
|
195
|
+
it "fails if initial condition is not met by empty collection" do
|
196
|
+
array = []
|
197
|
+
expect {
|
198
|
+
expect {
|
199
|
+
array << 3
|
200
|
+
}.to change { array }.to_exclude(&:even?)
|
201
|
+
}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
202
|
+
end
|
203
|
+
|
204
|
+
it "fails if final condition is not met" do
|
205
|
+
array = [1,2,3]
|
206
|
+
expect {
|
207
|
+
expect {
|
208
|
+
array -= [3]
|
209
|
+
}.to change { array }.to_exclude(&:even?)
|
210
|
+
}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
211
|
+
end
|
212
|
+
|
213
|
+
it "fails if there is no change" do
|
214
|
+
array = [2]
|
215
|
+
expect {
|
216
|
+
expect {
|
217
|
+
# nop
|
218
|
+
}.to change { array }.to_exclude(&:even?)
|
219
|
+
}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
220
|
+
end
|
221
|
+
|
222
|
+
it "fails if also passed an item" do
|
223
|
+
array = []
|
224
|
+
expect {
|
225
|
+
expect {
|
226
|
+
# nop
|
227
|
+
}.to change { array }.to_include(1, &:even?)
|
228
|
+
}.to raise_error(ArgumentError)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rspec/change_collection'
|
2
|
+
|
3
|
+
Dir['./spec/support/**/*'].each {|f| require f}
|
4
|
+
|
5
|
+
class NullFormatter
|
6
|
+
private
|
7
|
+
def method_missing(method, *args, &block)
|
8
|
+
# ignore
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.run_all_when_everything_filtered = true
|
14
|
+
config.order = 'random'
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-change_collection
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew S. Brown
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.99.0.beta1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.99.0.beta1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-expectations
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.99.0.beta1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.99.0.beta1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 10.1.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 10.1.0
|
69
|
+
description: RSpec extension gem for attribute matching
|
70
|
+
email:
|
71
|
+
- andrew@dontfidget.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Changelog.md
|
78
|
+
- Gemfile
|
79
|
+
- Gemfile.lock
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- lib/rspec/change_collection.rb
|
84
|
+
- lib/rspec/change_collection/version.rb
|
85
|
+
- rspec-change_collection.gemspec
|
86
|
+
- script/test_all
|
87
|
+
- spec/rspec/change_collection_spec.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
homepage: https://github.com/dontfidget/rspec-change_collection
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.2.2
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Provides "change_collection" method formally part of rspec-core
|
113
|
+
test_files:
|
114
|
+
- spec/rspec/change_collection_spec.rb
|
115
|
+
- spec/spec_helper.rb
|