File tree 4 files changed +72
-0
lines changed
4 files changed +72
-0
lines changed Original file line number Diff line number Diff line change @@ -324,6 +324,7 @@ group :development, :test do
324
324
gem 'spinach-rerun-reporter' , '~> 0.0.2'
325
325
gem 'rspec_profiling' , '~> 0.0.5'
326
326
gem 'rspec-set' , '~> 0.1.3'
327
+ gem 'rspec-parameterized'
327
328
328
329
# Prevent occasions where minitest is not bundled in packaged versions of ruby (see #3826)
329
330
gem 'minitest' , '~> 5.7.0'
Original file line number Diff line number Diff line change 2
2
remote: https://rubygems.org/
3
3
specs:
4
4
RedCloth (4.3.2 )
5
+ abstract_type (0.0.7 )
5
6
ace-rails-ap (4.1.2 )
6
7
actionmailer (4.2.8 )
7
8
actionpack (= 4.2.8 )
41
42
tzinfo (~> 1.1 )
42
43
acts-as-taggable-on (4.0.0 )
43
44
activerecord (>= 4.0 )
45
+ adamantium (0.2.0 )
46
+ ice_nine (~> 0.11.0 )
47
+ memoizable (~> 0.4.0 )
44
48
addressable (2.3.8 )
45
49
after_commit_queue (1.3.0 )
46
50
activerecord (>= 3.0 )
124
128
coercible (1.0.0 )
125
129
descendants_tracker (~> 0.0.1 )
126
130
colorize (0.7.7 )
131
+ concord (0.1.5 )
132
+ adamantium (~> 0.2.0 )
133
+ equalizer (~> 0.0.9 )
127
134
concurrent-ruby (1.0.5 )
128
135
concurrent-ruby-ext (1.0.5 )
129
136
concurrent-ruby (= 1.0.5 )
470
477
mime-types (>= 1.16 , < 4 )
471
478
mail_room (0.9.1 )
472
479
memoist (0.15.0 )
480
+ memoizable (0.4.2 )
481
+ thread_safe (~> 0.3 , >= 0.3.1 )
473
482
method_source (0.8.2 )
474
483
mime-types (2.99.3 )
475
484
mimemagic (0.3.0 )
610
619
premailer-rails (1.9.7 )
611
620
actionmailer (>= 3 , < 6 )
612
621
premailer (~> 1.7 , >= 1.7.9 )
622
+ proc_to_ast (0.1.0 )
623
+ coderay
624
+ parser
625
+ unparser
626
+ procto (0.0.3 )
613
627
prometheus-client-mmap (0.7.0.beta11 )
614
628
mmap2 (~> 2.2 , >= 2.2.7 )
615
629
pry (0.10.4 )
718
732
chunky_png
719
733
rqrcode-rails3 (0.1.7 )
720
734
rqrcode (>= 0.4.2 )
735
+ rspec (3.6.0 )
736
+ rspec-core (~> 3.6.0 )
737
+ rspec-expectations (~> 3.6.0 )
738
+ rspec-mocks (~> 3.6.0 )
721
739
rspec-core (3.6.0 )
722
740
rspec-support (~> 3.6.0 )
723
741
rspec-expectations (3.6.0 )
726
744
rspec-mocks (3.6.0 )
727
745
diff-lcs (>= 1.2.0 , < 2.0 )
728
746
rspec-support (~> 3.6.0 )
747
+ rspec-parameterized (0.4.0 )
748
+ binding_of_caller
749
+ parser
750
+ proc_to_ast
751
+ rspec (>= 2.13 , < 4 )
752
+ unparser
729
753
rspec-rails (3.6.0 )
730
754
actionpack (>= 3.0 )
731
755
activesupport (>= 3.0 )
892
916
get_process_mem (~> 0 )
893
917
unicorn (>= 4 , < 6 )
894
918
uniform_notifier (1.10.0 )
919
+ unparser (0.2.6 )
920
+ abstract_type (~> 0.0.7 )
921
+ adamantium (~> 0.2.0 )
922
+ concord (~> 0.1.5 )
923
+ diff-lcs (~> 1.3 )
924
+ equalizer (~> 0.0.9 )
925
+ parser (>= 2.3.1.2 , < 2.5 )
926
+ procto (~> 0.0.2 )
895
927
url_safe_base64 (0.2.2 )
896
928
validates_hostname (1.0.6 )
897
929
activerecord (>= 3.0 )
@@ -1094,6 +1126,7 @@ DEPENDENCIES
1094
1126
responders (~> 2.0 )
1095
1127
rouge (~> 2.0 )
1096
1128
rqrcode-rails3 (~> 0.1.7 )
1129
+ rspec-parameterized
1097
1130
rspec-rails (~> 3.6.0 )
1098
1131
rspec-retry (~> 0.4.5 )
1099
1132
rspec-set (~> 0.1.3 )
Original file line number Diff line number Diff line change 279
279
- Avoid scenario titles that add no information, such as "successfully".
280
280
- Avoid scenario titles that repeat the feature title.
281
281
282
+ ### Table-based / Parameterized tests
283
+
284
+ This style of testing is used to exercise one piece of code with a comprehensive
285
+ range of inputs. By specifying the test case once, alongside a table of inputs
286
+ and the expected output for each, your tests can be made easier to read and more
287
+ compact.
288
+
289
+ We use the [ rspec-parameterized] ( https://github.com/tomykaira/rspec-parameterized )
290
+ gem. A short example, using the table syntax and checking Ruby equality for a
291
+ range of inputs, might look like this:
292
+
293
+ ``` ruby
294
+ describe " #==" do
295
+ using Rspec ::Parameterized ::TableSyntax
296
+
297
+ let(:project1 ) { create(:project ) }
298
+ let(:project2 ) { create(:project ) }
299
+ where(:a , :b , :result ) do
300
+ 1 | 1 | true
301
+ 1 | 2 | false
302
+ true | true | true
303
+ true | false | false
304
+ project1 | project1 | true
305
+ project2 | project2 | true
306
+ project 1 | project2 | false
307
+ end
308
+
309
+ with_them do
310
+ it { expect(a == b).to eq(result) }
311
+
312
+ it ' is isomorphic' do
313
+ expect(b == a).to eq(result)
314
+ end
315
+ end
316
+ end
317
+ ```
318
+
282
319
### Matchers
283
320
284
321
Custom matchers should be created to clarify the intent and/or hide the
Original file line number Diff line number Diff line change 8
8
require 'rspec/rails'
9
9
require 'shoulda/matchers'
10
10
require 'rspec/retry'
11
+ require 'rspec-parameterized'
11
12
12
13
rspec_profiling_is_configured =
13
14
ENV [ 'RSPEC_PROFILING_POSTGRES_URL' ] . present? ||
You can’t perform that action at this time.
0 commit comments