rspec-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
- data/spec/lib/given/evaluator_spec.rb +3 -0
- data/spec/lib/given/failure_matcher_spec.rb +8 -2
- data/spec/lib/given/failure_spec.rb +6 -6
- 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: 5ca5bc4ebba5ec0c35f8d71a594441d748f8a7d4
|
4
|
+
data.tar.gz: a70613b7f9b6dacdbab6c5b9bd88e1d73d7d07e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09fe70ee6a76b187e6f3aa583bc5bb02faac92571ef7ae80ecfcf7c018b12f89b10f7c18508e01d4425ab888b9ead56abf5644b1ca2d967c6cc01860e82b1762
|
7
|
+
data.tar.gz: 1311f64f6f5db5514281cd43540053bb6b0e28554bf95489b56f96b0bc74271e09bbea217277dbf54a13d9b426e1d3b1cf60a0c9a4013f8847da43582081d6b0
|
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
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Environmental Access" do
|
4
|
+
use_natural_assertions false
|
4
5
|
X = 1
|
5
6
|
Given(:a) { 2 }
|
6
7
|
FauxThen { X + a }
|
@@ -14,6 +15,7 @@ end
|
|
14
15
|
module Nested
|
15
16
|
X = 1
|
16
17
|
describe "Environmental Access with Nested modules" do
|
18
|
+
use_natural_assertions false
|
17
19
|
Given(:a) { 2 }
|
18
20
|
FauxThen { X + a }
|
19
21
|
Then { block_result.should == 3 }
|
@@ -24,6 +26,7 @@ module Nested
|
|
24
26
|
end
|
25
27
|
|
26
28
|
describe "Evaluator with error object" do
|
29
|
+
use_natural_assertions false
|
27
30
|
FauxThen { 1 }
|
28
31
|
When(:result) { ev.eval_string("fail 'XYZ'") }
|
29
32
|
Then { result.class.should == Given::EvalErr }
|
@@ -8,6 +8,8 @@ module FailureMatcherSpec
|
|
8
8
|
NotMetError = RSpec::Expectations::ExpectationNotMetError
|
9
9
|
|
10
10
|
describe Given::FailureMatcher do
|
11
|
+
use_natural_assertions_if_supported
|
12
|
+
|
11
13
|
Given(:error) { CustomError.new("CUSTOM") }
|
12
14
|
|
13
15
|
Given(:failure_result) { Given::Failure.new(error) }
|
@@ -65,13 +67,17 @@ module FailureMatcherSpec
|
|
65
67
|
end
|
66
68
|
|
67
69
|
describe "==" do
|
68
|
-
Then { failure_result
|
70
|
+
Then { failure_result == Failure() }
|
71
|
+
Then { failure_result == Failure(CustomError) }
|
72
|
+
Then { Failure() == failure_result }
|
69
73
|
Then { Failure(CustomError) == failure_result }
|
70
74
|
end
|
71
75
|
|
72
76
|
describe "!=" do
|
73
77
|
Then { failure_result != Failure(SubError) }
|
74
|
-
Then { Failure(SubError)
|
78
|
+
Then { Failure(SubError) != failure_result }
|
79
|
+
Then { Failure() != nil }
|
80
|
+
Then { nil != Failure() }
|
75
81
|
end
|
76
82
|
end
|
77
83
|
end
|
@@ -2,7 +2,8 @@ require 'spec_helper'
|
|
2
2
|
require 'given/failure'
|
3
3
|
|
4
4
|
describe Given::Failure do
|
5
|
-
|
5
|
+
Given(:other_error) { Class.new(StandardError) }
|
6
|
+
Given(:custom_error) { Class.new(StandardError) }
|
6
7
|
|
7
8
|
Given(:exception) { StandardError.new("Oops") }
|
8
9
|
Given(:failure) { Given::Failure.new(exception) }
|
@@ -26,24 +27,23 @@ describe Given::Failure do
|
|
26
27
|
end
|
27
28
|
|
28
29
|
describe "== have_failed" do
|
30
|
+
use_natural_assertions_if_supported
|
29
31
|
Then { failure == have_failed(StandardError, "Oops") }
|
30
32
|
Then { failure == have_failed(StandardError) }
|
31
33
|
Then { failure == have_failed }
|
32
34
|
end
|
33
35
|
|
34
|
-
describe "!= have_failed" do
|
35
|
-
Then { failure != have_failed() }
|
36
|
-
end
|
37
|
-
|
38
36
|
describe "== Failure" do
|
37
|
+
use_natural_assertions_if_supported
|
39
38
|
Then { failure == Failure(StandardError, "Oops") }
|
40
39
|
Then { failure == Failure(StandardError) }
|
41
40
|
Then { failure == Failure() }
|
42
41
|
end
|
43
42
|
|
44
43
|
describe "!= Failure" do
|
44
|
+
use_natural_assertions_if_supported
|
45
45
|
Then { expect { failure != Object.new }.to raise_error(StandardError) }
|
46
|
-
Then { failure != Failure() }
|
46
|
+
Then { failure != Failure(other_error) }
|
47
47
|
end
|
48
48
|
|
49
49
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-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: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- examples/integration/invariant_spec.rb
|
92
92
|
- examples/integration/then_spec.rb
|
93
93
|
- examples/loader.rb
|
94
|
+
- examples/minitest/assert_raises_spec.rb
|
94
95
|
- examples/minitest_helper.rb
|
95
96
|
- examples/other/line_example.rb
|
96
97
|
- examples/stack/stack.rb
|