rspec-given 3.1.1 → 3.2.0
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 +4 -4
- data/Gemfile.lock +15 -12
- data/README.md +18 -9
- data/examples/failing/natural_failing_spec.rb +3 -3
- data/examples/integration/and_spec.rb +1 -1
- data/spec/lib/given/binary_operation_spec.rb +9 -9
- data/spec/lib/given/evaluator_spec.rb +10 -10
- data/spec/lib/given/extensions_spec.rb +49 -49
- data/spec/lib/given/failure_spec.rb +5 -5
- data/spec/lib/given/file_cache_spec.rb +5 -5
- data/spec/lib/given/have_failed_spec.rb +47 -47
- data/spec/lib/given/line_extractor_spec.rb +7 -7
- data/spec/lib/given/module_methods_spec.rb +2 -2
- data/spec/lib/given/natural_assertion_spec.rb +50 -50
- data/spec/lib/given/options_spec.rb +23 -23
- data/spec/spec_helper.rb +5 -5
- data/spec/support/be_booleany.rb +15 -0
- metadata +6 -8
- data/README.old +0 -902
- data/test/before_test.rb +0 -22
- data/test/meme_test.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d5e73181cf61bc93071d7161a925ed327343dc9
|
4
|
+
data.tar.gz: 608ea8d31f28616d28f82724eb687c67b0f31d88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91305932206df20bc225b9e4c81ba5147c24ba288b687055bdc2265a7e8eba4e4085c39e37e0fb326b98274ceb6cb5ae69446bae063201dca032fe9fb5761749
|
7
|
+
data.tar.gz: 111ba753e7988ba157c844da3d3628713b3b13ec2567c25089bc890946c8eb91b90c35b3c505dbe9c8177f7484dc6783502b4ffef7e270217c854f158a09f6e0
|
data/Gemfile.lock
CHANGED
@@ -1,21 +1,24 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
-
diff-lcs (1.2.
|
5
|
-
minitest (
|
6
|
-
rake (
|
7
|
-
rspec (
|
8
|
-
rspec-core (
|
9
|
-
rspec-expectations (
|
10
|
-
rspec-mocks (
|
11
|
-
rspec-core (
|
12
|
-
|
4
|
+
diff-lcs (1.2.5)
|
5
|
+
minitest (4.3.2)
|
6
|
+
rake (0.9.6)
|
7
|
+
rspec (3.0.0.beta1)
|
8
|
+
rspec-core (= 3.0.0.beta1)
|
9
|
+
rspec-expectations (= 3.0.0.beta1)
|
10
|
+
rspec-mocks (= 3.0.0.beta1)
|
11
|
+
rspec-core (3.0.0.beta1)
|
12
|
+
rspec-support (= 3.0.0.beta1)
|
13
|
+
rspec-expectations (3.0.0.beta1)
|
13
14
|
diff-lcs (>= 1.1.3, < 2.0)
|
14
|
-
|
15
|
-
|
15
|
+
rspec-support (= 3.0.0.beta1)
|
16
|
+
rspec-mocks (3.0.0.beta1)
|
17
|
+
rspec-support (= 3.0.0.beta1)
|
18
|
+
rspec-support (3.0.0.beta1)
|
19
|
+
sorcerer (1.0.2)
|
16
20
|
|
17
21
|
PLATFORMS
|
18
|
-
java
|
19
22
|
ruby
|
20
23
|
|
21
24
|
DEPENDENCIES
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
| :----: |
|
5
5
|
| [](https://travis-ci.org/jimweirich/rspec-given) |
|
6
6
|
|
7
|
-
Covering rspec-given, minitest-given, and given-core, version 3.
|
7
|
+
Covering rspec-given, minitest-given, and given-core, version 3.2.0.
|
8
8
|
|
9
9
|
rspec-given and minitest-given are extensions to your favorite testing
|
10
10
|
framework to allow Given/When/Then notation when writing specs.
|
@@ -19,8 +19,7 @@ structure RSpec specifications.
|
|
19
19
|
|
20
20
|
## Status
|
21
21
|
|
22
|
-
* rspec-given
|
23
|
-
* minitest-given is experimental.
|
22
|
+
* rspec-given and minitest-given are ready for production use.
|
24
23
|
|
25
24
|
### RSpec/Given
|
26
25
|
|
@@ -267,8 +266,10 @@ E.g.
|
|
267
266
|
|
268
267
|
context "inner context" do
|
269
268
|
|
270
|
-
# At this point, the _When_ of the outer context
|
271
|
-
#
|
269
|
+
# At this point, the _When_ of the outer context will be run
|
270
|
+
# before the _When_ of then inner context (but after all the
|
271
|
+
# _Givens_ of all the contexts). You can think of the outer
|
272
|
+
# _When_ as a special given for the inner scope.
|
272
273
|
|
273
274
|
When { code specified in the inner context }
|
274
275
|
Then { assert something about the inner context }
|
@@ -309,12 +310,16 @@ specify that behavior:
|
|
309
310
|
|
310
311
|
```ruby
|
311
312
|
When(:result) { stack.pop }
|
312
|
-
Then { result.
|
313
|
+
Then { expect(result).to have_failed(UnderflowError, /empty/) }
|
313
314
|
```
|
314
315
|
|
315
|
-
|
316
|
+
The arguments to the 'have_failed' matcher are the same as
|
316
317
|
those given to the standard RSpec matcher 'raise_error'.
|
317
318
|
|
319
|
+
*NOTE:* Prior to RSpec 3, the .should method worked with the failed
|
320
|
+
result. In RSpec 3 the <code>.should</code> method is deprecated and
|
321
|
+
should not be used with the failed result.
|
322
|
+
|
318
323
|
### Then
|
319
324
|
|
320
325
|
The _Then_ clauses are the postconditions of the specification. These
|
@@ -625,7 +630,7 @@ context.
|
|
625
630
|
context "Outer" do
|
626
631
|
context "Inner" do
|
627
632
|
Then { a == b } # Natural Assertions
|
628
|
-
Then { a.should == b } # RSpec style
|
633
|
+
Then { a.should == b } # Deprecated RSpec style
|
629
634
|
Then { expect(a).to eq(b) } # RSpec style
|
630
635
|
Then { assert_equal b, a } # Minitest style
|
631
636
|
Then { a.must_equal b } # Minitest style
|
@@ -709,7 +714,7 @@ For example, the following two Then clauses are equivalent:
|
|
709
714
|
|
710
715
|
```ruby
|
711
716
|
# Using an RSpec matcher
|
712
|
-
Then { result.
|
717
|
+
Then { expect(result).to have_failed(StandardError, /message/) }
|
713
718
|
|
714
719
|
# Using natural assertions
|
715
720
|
Then { result == Failure(StandardError, /message/) }
|
@@ -844,6 +849,10 @@ License. See the MIT-LICENSE file in the source distribution.
|
|
844
849
|
|
845
850
|
# History
|
846
851
|
|
852
|
+
* Version 3.2.0
|
853
|
+
|
854
|
+
* Add support for RSpec 3 beta
|
855
|
+
|
847
856
|
* Version 3.1.0
|
848
857
|
|
849
858
|
* Add support for Precondition/Postcondition/Assert in non-spec
|
@@ -11,10 +11,10 @@ describe "Natural Assertions" do
|
|
11
11
|
Given(:null) { nil }
|
12
12
|
Then { foo+foo+2*foo == expected }
|
13
13
|
Then { nil == "HI" && true && :symbol && 1}
|
14
|
-
Then { foo.
|
14
|
+
Then { expect(foo).to eq(2) }
|
15
15
|
Then { foo != 1 }
|
16
|
-
Then { foo.
|
17
|
-
Then { foo.
|
16
|
+
Then { expect(foo).to_not == 1 }
|
17
|
+
Then { expect(foo).to be_nil }
|
18
18
|
Then { ary.empty? }
|
19
19
|
Then { !null.nil? }
|
20
20
|
Then { fail "OUCH" }
|
@@ -5,23 +5,23 @@ describe Given::BinaryOperation do
|
|
5
5
|
|
6
6
|
context "with a valid binary sexp" do
|
7
7
|
Given(:sexp) { [:binary, [:@ident, "a"], :==, [:@ident, "b"]] }
|
8
|
-
Then { binary.left.
|
9
|
-
Then { binary.operator.
|
10
|
-
Then { binary.right.
|
11
|
-
Then { binary.explain.
|
8
|
+
Then { expect(binary.left).to eq([:@ident, "a"]) }
|
9
|
+
Then { expect(binary.operator).to eq(:==) }
|
10
|
+
Then { expect(binary.right).to eq([:@ident, "b"]) }
|
11
|
+
Then { expect(binary.explain).to eq("to equal") }
|
12
12
|
end
|
13
13
|
|
14
14
|
context "with a valid binary sexp using ===" do
|
15
15
|
Given(:sexp) { [:binary, [:@ident, "a"], :===, [:@ident, "b"]] }
|
16
|
-
Then { binary.left.
|
17
|
-
Then { binary.operator.
|
18
|
-
Then { binary.right.
|
19
|
-
Then { binary.explain.
|
16
|
+
Then { expect(binary.left).to eq([:@ident, "a"]) }
|
17
|
+
Then { expect(binary.operator).to eq(:===) }
|
18
|
+
Then { expect(binary.right).to eq([:@ident, "b"]) }
|
19
|
+
Then { expect(binary.explain).to eq("to be matched by") }
|
20
20
|
end
|
21
21
|
|
22
22
|
context "with a non-binary sexp" do
|
23
23
|
Given(:sexp) { [:something_else] }
|
24
|
-
Then { binary.
|
24
|
+
Then { expect(binary).to be_nil }
|
25
25
|
end
|
26
26
|
|
27
27
|
end
|
@@ -6,10 +6,10 @@ describe "Environmental Access" do
|
|
6
6
|
Given(:a) { 2 }
|
7
7
|
FauxThen { X + a }
|
8
8
|
|
9
|
-
Then { block_result.
|
10
|
-
Then { ev.eval_string("X").
|
11
|
-
Then { ev.eval_string("a").
|
12
|
-
Then { ev.eval_string("X+a").
|
9
|
+
Then { expect(block_result).to eq(3) }
|
10
|
+
Then { expect(ev.eval_string("X")).to eq("1") }
|
11
|
+
Then { expect(ev.eval_string("a")).to eq("2") }
|
12
|
+
Then { expect(ev.eval_string("X+a")).to eq("3") }
|
13
13
|
end
|
14
14
|
|
15
15
|
module Nested
|
@@ -18,10 +18,10 @@ module Nested
|
|
18
18
|
use_natural_assertions false
|
19
19
|
Given(:a) { 2 }
|
20
20
|
FauxThen { X + a }
|
21
|
-
Then { block_result.
|
22
|
-
Then { ev.eval_string("a").
|
23
|
-
Then { ev.eval_string("X").
|
24
|
-
Then { ev.eval_string("a+X").
|
21
|
+
Then { expect(block_result).to eq(3) }
|
22
|
+
Then { expect(ev.eval_string("a")).to eq("2") }
|
23
|
+
Then { expect(ev.eval_string("X")).to eq("1") }
|
24
|
+
Then { expect(ev.eval_string("a+X")).to eq("3") }
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -29,6 +29,6 @@ describe "Evaluator with error object" do
|
|
29
29
|
use_natural_assertions false
|
30
30
|
FauxThen { 1 }
|
31
31
|
When(:result) { ev.eval_string("fail 'XYZ'") }
|
32
|
-
Then { result.class.
|
33
|
-
Then { result.inspect.
|
32
|
+
Then { expect(result.class).to eq(Given::EvalErr) }
|
33
|
+
Then { expect(result.inspect).to eq("RuntimeError: XYZ") }
|
34
34
|
end
|
@@ -6,20 +6,20 @@ describe Given::ClassExtensions do
|
|
6
6
|
describe "Given with var" do
|
7
7
|
context "with simple given" do
|
8
8
|
Given(:a) { 1 }
|
9
|
-
Then { a.
|
9
|
+
Then { expect(a).to eq(1) }
|
10
10
|
end
|
11
11
|
|
12
12
|
context "is lazy" do
|
13
13
|
Given(:a) { trace << :given; 1 }
|
14
|
-
Then { a.
|
15
|
-
Then { trace.
|
16
|
-
Then { a; trace.
|
14
|
+
Then { expect(a).to eq(1) }
|
15
|
+
Then { expect(trace).to eq([]) }
|
16
|
+
Then { a; expect(trace).to eq([:given]) }
|
17
17
|
|
18
18
|
context "when nested" do
|
19
19
|
Given(:a) { trace << :nested; 2 }
|
20
|
-
Then { a.
|
21
|
-
Then { trace.
|
22
|
-
Then { a; trace.
|
20
|
+
Then { expect(a).to eq(2) }
|
21
|
+
Then { expect(trace).to eq([]) }
|
22
|
+
Then { a; expect(trace).to eq([:nested]) }
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -27,11 +27,11 @@ describe Given::ClassExtensions do
|
|
27
27
|
describe "Given without var" do
|
28
28
|
context "is lazy" do
|
29
29
|
Given { trace << :given }
|
30
|
-
Then { trace.
|
30
|
+
Then { expect(trace).to eq([:given]) }
|
31
31
|
|
32
32
|
context "when nested" do
|
33
33
|
Given { trace << :nested }
|
34
|
-
Then { trace.
|
34
|
+
Then { expect(trace).to eq([:given, :nested]) }
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -39,20 +39,20 @@ describe Given::ClassExtensions do
|
|
39
39
|
describe "Given!" do
|
40
40
|
context "with simple given" do
|
41
41
|
Given!(:a) { 1 }
|
42
|
-
Then { a.
|
42
|
+
Then { expect(a).to eq(1) }
|
43
43
|
end
|
44
44
|
|
45
45
|
context "is not lazy" do
|
46
46
|
Given!(:a) { trace << :given; 1 }
|
47
|
-
Then { a.
|
48
|
-
Then { trace.
|
49
|
-
Then { a; trace.
|
47
|
+
Then { expect(a).to eq(1) }
|
48
|
+
Then { expect(trace).to eq([:given]) }
|
49
|
+
Then { a; expect(trace).to eq([:given]) }
|
50
50
|
end
|
51
51
|
|
52
52
|
context "when preceeded by a Given block" do
|
53
53
|
Given { trace << :given }
|
54
54
|
Given!(:other) { trace << :given_bang }
|
55
|
-
Then { trace.
|
55
|
+
Then { expect(trace).to eq([:given, :given_bang]) }
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -65,12 +65,12 @@ describe Given::ClassExtensions do
|
|
65
65
|
When(:result_outer) { trace << :when_result_outer }
|
66
66
|
|
67
67
|
Then {
|
68
|
-
trace.
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
68
|
+
expect(trace).to eq([
|
69
|
+
:before_outer, :before2_outer,
|
70
|
+
:given_outer, :given_bang_outer,
|
71
|
+
:when_outer,
|
72
|
+
:when_result_outer,
|
73
|
+
])
|
74
74
|
}
|
75
75
|
|
76
76
|
context "with a nested When" do
|
@@ -81,14 +81,14 @@ describe Given::ClassExtensions do
|
|
81
81
|
When { trace << :when_inner }
|
82
82
|
|
83
83
|
Then {
|
84
|
-
trace.
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
84
|
+
expect(trace).to eq([
|
85
|
+
:before_outer, :before2_outer,
|
86
|
+
:given_outer, :given_bang_outer,
|
87
|
+
:given_inner, :given_bang_inner,
|
88
|
+
:when_outer, :when_result_outer,
|
89
|
+
:before_inner,
|
90
|
+
:when_result_inner, :when_inner,
|
91
|
+
])
|
92
92
|
}
|
93
93
|
end
|
94
94
|
|
@@ -98,13 +98,13 @@ describe Given::ClassExtensions do
|
|
98
98
|
Given!(:x_inner) { trace << :given_bang_inner }
|
99
99
|
|
100
100
|
Then {
|
101
|
-
trace.
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
101
|
+
expect(trace).to eq([
|
102
|
+
:before_outer, :before2_outer,
|
103
|
+
:given_outer, :given_bang_outer,
|
104
|
+
:given_inner, :given_bang_inner,
|
105
|
+
:when_outer, :when_result_outer,
|
106
|
+
:before_inner,
|
107
|
+
])
|
108
108
|
}
|
109
109
|
end
|
110
110
|
end
|
@@ -112,62 +112,62 @@ describe Given::ClassExtensions do
|
|
112
112
|
describe "When without result" do
|
113
113
|
Given { trace << :given }
|
114
114
|
When { trace << :when }
|
115
|
-
Then { trace.
|
115
|
+
Then { expect(trace).to eq([:given, :when]) }
|
116
116
|
|
117
117
|
context "with nesting" do
|
118
118
|
Given { trace << :nested }
|
119
|
-
Then { trace.
|
119
|
+
Then { expect(trace).to eq([:given, :nested, :when]) }
|
120
120
|
end
|
121
121
|
|
122
122
|
context "with nesting of When" do
|
123
123
|
Given { trace << :nested }
|
124
124
|
When { trace << :when_nested }
|
125
|
-
Then { trace.
|
125
|
+
Then { expect(trace).to eq([:given, :nested, :when, :when_nested]) }
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
129
|
describe "When with result" do
|
130
130
|
Given { trace << :given }
|
131
131
|
When(:result) { trace << :when; :result }
|
132
|
-
Invariant { result.
|
132
|
+
Invariant { expect(result).to eq(:result) }
|
133
133
|
|
134
|
-
Then { trace.
|
134
|
+
Then { expect(trace).to eq([:given, :when]) }
|
135
135
|
|
136
136
|
context "with nesting" do
|
137
137
|
Given { trace << :nested }
|
138
|
-
Then { trace.
|
138
|
+
Then { expect(trace).to eq([:given, :nested, :when]) }
|
139
139
|
end
|
140
140
|
|
141
141
|
context "with nesting of When" do
|
142
142
|
Given { trace << :nested }
|
143
143
|
When { trace << :when_nested }
|
144
|
-
Then { trace.
|
144
|
+
Then { expect(trace).to eq([:given, :nested, :when, :when_nested]) }
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
148
|
describe "When with unreferenced result" do
|
149
149
|
Given { trace << :given }
|
150
150
|
When(:result) { trace << :when; :result }
|
151
|
-
Then { trace.
|
151
|
+
Then { expect(trace).to eq([:given, :when]) }
|
152
152
|
end
|
153
153
|
|
154
154
|
describe "Invariant with When" do
|
155
155
|
Given { trace << :given }
|
156
156
|
Invariant { trace << :invariant }
|
157
157
|
When { trace << :when }
|
158
|
-
Then { trace.
|
158
|
+
Then { expect(trace).to eq([:given, :when, :invariant]) }
|
159
159
|
end
|
160
160
|
|
161
161
|
describe "Invariant without When" do
|
162
162
|
Given { trace << :given }
|
163
163
|
Invariant { trace << :invariant }
|
164
|
-
Then { trace.
|
164
|
+
Then { expect(trace).to eq([:given, :invariant]) }
|
165
165
|
end
|
166
166
|
|
167
167
|
describe "Then" do
|
168
168
|
Given { trace << :given }
|
169
169
|
Then { trace << :then }
|
170
|
-
And { trace.
|
170
|
+
And { expect(trace).to eq([:given, :then]) }
|
171
171
|
end
|
172
172
|
|
173
173
|
describe "Then referencing givens" do
|
@@ -184,7 +184,7 @@ describe Given::ClassExtensions do
|
|
184
184
|
Given { trace << :given }
|
185
185
|
Then { trace << :then }
|
186
186
|
And { trace << :and}
|
187
|
-
And { trace.
|
187
|
+
And { expect(trace).to eq([:given, :then, :and]) }
|
188
188
|
end
|
189
189
|
|
190
190
|
end
|
@@ -196,9 +196,9 @@ describe "use_natural_assertions" do
|
|
196
196
|
When(:result) { CONTEXT.use_natural_assertions }
|
197
197
|
|
198
198
|
if ::Given::NATURAL_ASSERTIONS_SUPPORTED
|
199
|
-
Then { result.
|
199
|
+
Then { expect(result).to_not have_failed }
|
200
200
|
else
|
201
|
-
Then { result.
|
201
|
+
Then { expect(result).to have_failed(ArgumentError) }
|
202
202
|
end
|
203
203
|
end
|
204
204
|
end
|
@@ -8,7 +8,7 @@ describe Given::Failure do
|
|
8
8
|
Given(:exception) { StandardError.new("Oops") }
|
9
9
|
Given(:failure) { Given::Failure.new(exception) }
|
10
10
|
|
11
|
-
Then { failure.is_a?(Given::Failure).
|
11
|
+
Then { expect(failure.is_a?(Given::Failure)).to eq(true) }
|
12
12
|
|
13
13
|
describe "general operations" do
|
14
14
|
Then { expect { failure.to_s }.to raise_error(StandardError, "Oops") }
|
@@ -20,10 +20,10 @@ describe Given::Failure do
|
|
20
20
|
Then { expect { ! failure }.to raise_error(StandardError, "Oops") }
|
21
21
|
end
|
22
22
|
|
23
|
-
describe "
|
24
|
-
Then { failure.
|
25
|
-
Then { failure.
|
26
|
-
Then { failure.
|
23
|
+
describe "raising error" do
|
24
|
+
Then { expect(failure).to raise_error(StandardError, "Oops") }
|
25
|
+
Then { expect(failure).to raise_error(StandardError) }
|
26
|
+
Then { expect(failure).to raise_error }
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "== have_failed" do
|