minitest-given 3.0.0.beta.3 → 3.0.0.beta.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +83 -55
- data/Rakefile +4 -1
- data/examples/loader.rb +0 -1
- data/examples/minitest/assert_raises_spec.rb +25 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 669e03394bda8c007546ee125f5df18d2290be83
|
4
|
+
data.tar.gz: 6282eed5233e6c6a5a044e91536475778ab93065
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6327e8424e6d1a79138cb62c3d8a26f65fd37f62ff919a016ba32e5b80c14816a8c3aacbe3fbe6c58ba0cb3717029aaa280b1b0d467022bedf45a7e2ad4e974
|
7
|
+
data.tar.gz: cc526134b165db9db94534b9e02c643f0c942fe877e2bf000fc5c46fad9b6836bba58f804603c13c254ab16504c3d00a77e822a902dec7888023b05282ecf93e
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# Given/When/Then for RSpec and Minitest
|
2
2
|
|
3
3
|
| Master |
|
4
4
|
| :----: |
|
@@ -28,7 +28,7 @@ The rspec-given gem is the original given/when/then extension for
|
|
28
28
|
RSpec. It now depends on a given_core gem for the basic functionality
|
29
29
|
and then adds the RSpec specific code.
|
30
30
|
|
31
|
-
* rspec-given now
|
31
|
+
* rspec-given now requires RSpec version 2.12 or better.
|
32
32
|
|
33
33
|
### Minitest/Given
|
34
34
|
|
@@ -58,7 +58,7 @@ things to watch out for:
|
|
58
58
|
|
59
59
|
### Auto Selecting
|
60
60
|
|
61
|
-
If you
|
61
|
+
If you use natural assertions exclusively in your specs, it's quite
|
62
62
|
possible to write specs that run under both RSpec and Minitest::Spec.
|
63
63
|
|
64
64
|
Use this at the start of your spec file:
|
@@ -94,22 +94,22 @@ describe Stack do
|
|
94
94
|
end
|
95
95
|
|
96
96
|
Given(:stack) { stack_with(initial_contents) }
|
97
|
-
Invariant { stack.empty
|
97
|
+
Invariant { stack.empty? == (stack.depth == 0) }
|
98
98
|
|
99
99
|
context "with no items" do
|
100
100
|
Given(:initial_contents) { [] }
|
101
|
-
Then { stack.depth
|
101
|
+
Then { stack.depth == 0 }
|
102
102
|
|
103
103
|
context "when pushing" do
|
104
104
|
When { stack.push(:an_item) }
|
105
105
|
|
106
|
-
Then { stack.depth
|
107
|
-
Then { stack.top
|
106
|
+
Then { stack.depth == 1 }
|
107
|
+
Then { stack.top == :an_item }
|
108
108
|
end
|
109
109
|
|
110
110
|
context "when popping" do
|
111
111
|
When(:result) { stack.pop }
|
112
|
-
Then { result
|
112
|
+
Then { result == Failure(Stack::UnderflowError, /empty/) }
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
@@ -119,8 +119,8 @@ describe Stack do
|
|
119
119
|
context "when popping" do
|
120
120
|
When(:pop_result) { stack.pop }
|
121
121
|
|
122
|
-
Then { pop_result
|
123
|
-
Then { stack.depth
|
122
|
+
Then { pop_result == :an_item }
|
123
|
+
Then { stack.depth == 0 }
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
@@ -131,16 +131,16 @@ describe Stack do
|
|
131
131
|
context "when pushing" do
|
132
132
|
When { stack.push(:new_item) }
|
133
133
|
|
134
|
-
Then { stack.top
|
135
|
-
Then { stack.depth
|
134
|
+
Then { stack.top == :new_item }
|
135
|
+
Then { stack.depth == original_depth + 1 }
|
136
136
|
end
|
137
137
|
|
138
138
|
context "when popping" do
|
139
139
|
When(:pop_result) { stack.pop }
|
140
140
|
|
141
|
-
Then { pop_result
|
142
|
-
Then { stack.top
|
143
|
-
Then { stack.depth
|
141
|
+
Then { pop_result == :top_item }
|
142
|
+
Then { stack.top == :second_item }
|
143
|
+
Then { stack.depth == original_depth - 1 }
|
144
144
|
end
|
145
145
|
end
|
146
146
|
end
|
@@ -307,7 +307,7 @@ should use an empty _Then_ clause, like this:
|
|
307
307
|
#### Then examples:
|
308
308
|
|
309
309
|
```ruby
|
310
|
-
Then { stack.
|
310
|
+
Then { stack.empty? }
|
311
311
|
```
|
312
312
|
|
313
313
|
After the related block for the _When_ clause is run, the stack should
|
@@ -354,9 +354,9 @@ stick with _Then_ clauses.
|
|
354
354
|
#### Then/And examples:
|
355
355
|
|
356
356
|
```ruby
|
357
|
-
Then { pop_result
|
358
|
-
And { stack.top
|
359
|
-
And { stack.depth
|
357
|
+
Then { pop_result == :top_item } # Required
|
358
|
+
And { stack.top == :second_item } # No Setup rerun
|
359
|
+
And { stack.depth == original_depth - 1 } # ... for these
|
360
360
|
```
|
361
361
|
|
362
362
|
### Invariant
|
@@ -420,29 +420,56 @@ clauses and _before_ blocks.
|
|
420
420
|
|
421
421
|
## Natural Assertions
|
422
422
|
|
423
|
-
**NOTE:** <em>Natural assertions are currently an experimental feature
|
424
|
-
of RSpec/Given. They are currently disabled by default, but can be
|
425
|
-
enabled by a simple configuration option (see "use_natural_assertions"
|
426
|
-
below).</em>
|
427
|
-
|
428
423
|
RSpec/Given now supports the use of "natural assertions" in _Then_,
|
429
424
|
_And_, and _Invariant_ blocks. Natural assertions are just Ruby
|
430
425
|
conditionals, without the _should_ or _expect_ methods that RSpec
|
431
|
-
provides. Here are the Then/And examples
|
432
|
-
|
426
|
+
provides. Here are the Then/And examples showing natural assertions:
|
427
|
+
|
428
|
+
### Using Natural Assertions
|
429
|
+
|
430
|
+
```ruby
|
431
|
+
Then { stack.top == :second_item }
|
432
|
+
Then { stack.depth == original_depth - 1 }
|
433
|
+
Then { result == Failure(Stack::UnderflowError, /empty/) }
|
434
|
+
```
|
435
|
+
|
436
|
+
### Using RSpec expect().to
|
433
437
|
|
434
438
|
```ruby
|
435
|
-
Then {
|
436
|
-
|
437
|
-
|
439
|
+
Then { expect(stack.top).to eq(:second_item) }
|
440
|
+
Then { expect(stack.depth).to eq(original_depth - 1) }
|
441
|
+
Then { expect(result).to have_failed(Stack::UnderflowError, /empty/) }
|
438
442
|
```
|
439
443
|
|
440
|
-
|
441
|
-
context basis, to be recognized.
|
444
|
+
### Using Minitest asserts
|
442
445
|
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
+
```ruby
|
447
|
+
Then { assert_equal :second_item, stack.top }
|
448
|
+
Then { assert_equal original_depth - 1, stack.depth }
|
449
|
+
Then {
|
450
|
+
assert_raises(Stack::UnderflowError, /empty/) do
|
451
|
+
result.call()
|
452
|
+
end
|
453
|
+
}
|
454
|
+
```
|
455
|
+
|
456
|
+
### Using Minitest expectations
|
457
|
+
|
458
|
+
```ruby
|
459
|
+
Then { stack.top.must_equal :second_item }
|
460
|
+
Then { stack.depth.must_equal original_depth - 1}
|
461
|
+
Then { result.must_raise(Stack::UnderflowError, /empty/) }
|
462
|
+
```
|
463
|
+
|
464
|
+
### Disabling Natural Assertions
|
465
|
+
|
466
|
+
Natural assertions may be disabled, either globally or on a per
|
467
|
+
context basis. See the **configuration** section below to see how to
|
468
|
+
disable natural assertions project wide.
|
469
|
+
|
470
|
+
Here's a heads up: If you use natural assertions, but configure Given
|
471
|
+
to disable them, then all your specs will mysteriously pass. This is
|
472
|
+
why the **red** part of _Red/Green/Refactor_ is so important.
|
446
473
|
|
447
474
|
### Failure Messages with Natural Assertions
|
448
475
|
|
@@ -552,19 +579,18 @@ problems with And clauses.
|
|
552
579
|
|
553
580
|
### Mixing Natural Assertions and RSpec Assertions
|
554
581
|
|
555
|
-
Natural assertions
|
556
|
-
intermixed in a single test suite, even within a single
|
557
|
-
|
558
|
-
must be explicitly enabled before they will be considered.
|
559
|
-
|
560
|
-
To enable natural assertions in a context, call the
|
561
|
-
_use_natural_assertions_ method in that context. For example:
|
582
|
+
Natural assertions, RSpec should assertions and Minitest assertions
|
583
|
+
can be intermixed in a single test suite, even within a single
|
584
|
+
context.
|
562
585
|
|
563
586
|
```ruby
|
564
587
|
context "Outer" do
|
565
|
-
use_natural_assertions
|
566
|
-
|
567
588
|
context "Inner" do
|
589
|
+
Then { a == b } # Natural Assertions
|
590
|
+
Then { a.should == b } # RSpec style
|
591
|
+
Then { expect(a).to eq(b) } # RSpec style
|
592
|
+
Then { assert_equal b, a } # Minitest style
|
593
|
+
Then { a.must_equal b } # Minitest style
|
568
594
|
end
|
569
595
|
|
570
596
|
context "Disabled" do
|
@@ -577,7 +603,7 @@ Both the _Outer_ and _Inner_ contexts will use natural assertions. The
|
|
577
603
|
_Disabled_ context overrides the setting inherited from _Outer_ and
|
578
604
|
will not process natural assertions.
|
579
605
|
|
580
|
-
See the **configuration** section below to see how to
|
606
|
+
See the **configuration** section below to see how to disable natural
|
581
607
|
assertions project wide.
|
582
608
|
|
583
609
|
### Matchers and Natural Assertions
|
@@ -622,7 +648,7 @@ There are several ways of creating fuzzy numbers:
|
|
622
648
|
|
623
649
|
* <code>about(n)</code> -- Same as <code>about(n).epsilon(10)</code>.
|
624
650
|
|
625
|
-
When the file <code>
|
651
|
+
When the file <code>given/fuzzy_shortcuts</code> is required,
|
626
652
|
the following unicode shortcut methods are added to Numeric to create
|
627
653
|
fuzzy numbers.
|
628
654
|
|
@@ -648,7 +674,7 @@ For example, the following two Then clauses are equivalent:
|
|
648
674
|
Then { result.should have_failed(StandardError, /message/) }
|
649
675
|
|
650
676
|
# Using natural assertions
|
651
|
-
Then { result ==
|
677
|
+
Then { result == Failure(StandardError, /message/) }
|
652
678
|
```
|
653
679
|
|
654
680
|
### Processing Natural Assertions
|
@@ -662,7 +688,9 @@ following are true:
|
|
662
688
|
1. The block returns false (blocks that return true pass the
|
663
689
|
assertion and don't need a failure message).
|
664
690
|
|
665
|
-
1. The block does not use
|
691
|
+
1. The block does not use the native frameworks assertions or
|
692
|
+
expectations (e.g. RSpec's _should_ or _expect_ methods, or
|
693
|
+
Minitest's _assert\_xxx_ or _must\_xxx_ methods).
|
666
694
|
|
667
695
|
Detecting that last point (the use of _should_ and _expect_) is done
|
668
696
|
by modifying the RSpec runtime to report uses of _should_ and
|
@@ -672,11 +700,11 @@ _expect_.
|
|
672
700
|
|
673
701
|
Natural assertions use the Ripper library to parse the failing
|
674
702
|
condition and find all the sub-expression values upon a failure.
|
675
|
-
Currently Ripper is not supported on JRuby 1.7.
|
676
|
-
said that Ripper support is coming soon and may arrive
|
677
|
-
|
678
|
-
|
679
|
-
|
703
|
+
Currently Ripper is not fully supported on JRuby 1.7.4. Charles Nutter
|
704
|
+
has said that Ripper support is coming soon and may arrive soon. Until
|
705
|
+
then, natural assertions are disabled when running under JRuby. Never
|
706
|
+
fear, JRuby supports all the other features of rspec-given and will
|
707
|
+
work just fine.
|
680
708
|
|
681
709
|
### Further Reading
|
682
710
|
|
@@ -697,7 +725,7 @@ the pretty output and wish to disable source code caching
|
|
697
725
|
unconditionally, then add the following line to your spec helper file:
|
698
726
|
|
699
727
|
```ruby
|
700
|
-
|
728
|
+
Given.source_caching_disabled = true
|
701
729
|
```
|
702
730
|
|
703
731
|
Natural assertions are disabled by default. To globally configure
|
@@ -714,8 +742,8 @@ file:
|
|
714
742
|
|
715
743
|
# License
|
716
744
|
|
717
|
-
|
718
|
-
file in the source distribution.
|
745
|
+
rspec-given, minitest-given and given_core are available under the MIT
|
746
|
+
License. See the MIT-LICENSE file in the source distribution.
|
719
747
|
|
720
748
|
# History
|
721
749
|
|
data/Rakefile
CHANGED
@@ -57,8 +57,11 @@ end
|
|
57
57
|
|
58
58
|
EXAMPLES = FileList['examples/**/*_spec.rb'].
|
59
59
|
exclude('examples/failing/*.rb').
|
60
|
+
exclude('examples/minitest/*.rb').
|
60
61
|
exclude('examples/integration/failing/*.rb')
|
61
62
|
|
63
|
+
MT_EXAMPLES = FileList['examples/minitest/**/*_spec.rb']
|
64
|
+
|
62
65
|
unless Given::NATURAL_ASSERTIONS_SUPPORTED
|
63
66
|
EXAMPLES.exclude("examples/stack/*.rb")
|
64
67
|
end
|
@@ -80,7 +83,7 @@ end
|
|
80
83
|
desc "Run the examples in Minitest"
|
81
84
|
task :mt_examples do
|
82
85
|
puts "Running examples (with Minitest)"
|
83
|
-
sh "ruby -Ilib:examples examples/loader.rb #{EXAMPLES}"
|
86
|
+
sh "ruby -Ilib:examples examples/loader.rb #{EXAMPLES} #{MT_EXAMPLES}"
|
84
87
|
end
|
85
88
|
|
86
89
|
desc "Run failing examples"
|
data/examples/loader.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'minitest/given'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
describe "stacks" do
|
5
|
+
context "when it fails" do
|
6
|
+
When(:result) { fail StandardError, "Oops" }
|
7
|
+
|
8
|
+
Then { result.must_raise(StandardError, /oops/i) }
|
9
|
+
Then {
|
10
|
+
assert_raises(StandardError, /oops/i) do
|
11
|
+
result.die
|
12
|
+
end
|
13
|
+
}
|
14
|
+
Then { result == Failure() }
|
15
|
+
Then { result == Failure(StandardError) }
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when it does not fail" do
|
19
|
+
When(:result) { :ok }
|
20
|
+
|
21
|
+
Then { result != Failure() }
|
22
|
+
Then { result != Failure(StandardError) }
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-given
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.beta.
|
4
|
+
version: 3.0.0.beta.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Weirich
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.0.0.beta.
|
19
|
+
version: 3.0.0.beta.4
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.0.0.beta.
|
26
|
+
version: 3.0.0.beta.4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,6 +74,7 @@ files:
|
|
74
74
|
- examples/integration/invariant_spec.rb
|
75
75
|
- examples/integration/then_spec.rb
|
76
76
|
- examples/loader.rb
|
77
|
+
- examples/minitest/assert_raises_spec.rb
|
77
78
|
- examples/minitest_helper.rb
|
78
79
|
- examples/other/line_example.rb
|
79
80
|
- examples/stack/stack.rb
|