rspec-given 2.4.4 → 3.0.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 +5 -2
- data/Gemfile.lock +6 -10
- data/README.md +223 -73
- data/README.old +226 -76
- data/Rakefile +26 -17
- data/TODO +13 -0
- data/examples/example_helper.rb +8 -1
- data/examples/integration/and_spec.rb +6 -11
- data/examples/integration/focused_line_spec.rb +2 -1
- data/examples/integration/given_spec.rb +19 -9
- data/examples/integration/invariant_spec.rb +6 -6
- data/examples/integration/then_spec.rb +0 -1
- data/examples/loader.rb +3 -0
- data/examples/minitest/assert_raises_spec.rb +25 -0
- data/examples/minitest_helper.rb +38 -0
- data/examples/stack/stack_spec.rb +2 -3
- data/lib/given.rb +2 -0
- data/lib/rspec/given.rb +1 -19
- data/rakelib/bundler_fix.rb +17 -0
- data/rakelib/gemspec.rake +161 -0
- data/rakelib/metrics.rake +30 -0
- data/rakelib/preview.rake +14 -0
- data/spec/lib/given/binary_operation_spec.rb +19 -0
- data/spec/lib/{rspec/given → given}/evaluator_spec.rb +4 -1
- data/spec/lib/{rspec/given → given}/ext/numeric_spec.rb +2 -2
- data/spec/lib/{rspec/given → given}/extensions_spec.rb +2 -2
- data/spec/lib/given/failure_matcher_spec.rb +83 -0
- data/spec/lib/given/failure_spec.rb +49 -0
- data/spec/lib/given/file_cache_spec.rb +26 -0
- data/spec/lib/{rspec/given → given}/fuzzy_number_spec.rb +2 -2
- data/spec/lib/{rspec/given → given}/have_failed_spec.rb +5 -4
- data/spec/lib/given/line_extractor_spec.rb +84 -0
- data/spec/lib/{rspec/given → given}/module_methods_spec.rb +2 -2
- data/spec/lib/{rspec/given → given}/natural_assertion_spec.rb +4 -36
- data/spec/lib/{rspec/given → given}/options_spec.rb +33 -33
- data/spec/spec_helper.rb +20 -0
- data/spec/support/faux_then.rb +2 -2
- data/spec/support/natural_assertion_control.rb +1 -1
- metadata +34 -41
- data/README +0 -679
- data/examples/integration/failing_spec.rb +0 -5
- data/lib/rspec/given/configure.rb +0 -20
- data/lib/rspec/given/core.rb +0 -9
- data/lib/rspec/given/evaluator.rb +0 -39
- data/lib/rspec/given/ext/numeric.rb +0 -32
- data/lib/rspec/given/extensions.rb +0 -262
- data/lib/rspec/given/failure.rb +0 -53
- data/lib/rspec/given/file_cache.rb +0 -19
- data/lib/rspec/given/fuzzy_number.rb +0 -70
- data/lib/rspec/given/fuzzy_shortcuts.rb +0 -1
- data/lib/rspec/given/have_failed.rb +0 -77
- data/lib/rspec/given/line_extractor.rb +0 -43
- data/lib/rspec/given/module_methods.rb +0 -70
- data/lib/rspec/given/monkey.rb +0 -41
- data/lib/rspec/given/natural_assertion.rb +0 -193
- data/lib/rspec/given/rspec1_given.rb +0 -11
- data/lib/rspec/given/version.rb +0 -10
- data/spec/lib/rspec/given/failure_spec.rb +0 -17
- data/spec/lib/rspec/given/file_cache_spec.rb +0 -28
- data/spec/lib/rspec/given/line_extractor_spec.rb +0 -86
- /data/spec/lib/{rspec/given → given}/ext/numeric_specifications.rb +0 -0
- /data/spec/lib/{rspec/given → given}/lexical_purity_spec.rb +0 -0
data/README.old
CHANGED
|
@@ -1,26 +1,119 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Given/When/Then for RSpec and Minitest
|
|
2
2
|
|
|
3
|
-
| Master |
|
|
4
|
-
| :----: |
|
|
5
|
-
| [](https://travis-ci.org/jimweirich/rspec-given) |
|
|
3
|
+
| Master | Minispec |
|
|
4
|
+
| :----: | :----: |
|
|
5
|
+
| [](https://travis-ci.org/jimweirich/rspec-given) | [](https://travis-ci.org/jimweirich/rspec-given) |
|
|
6
6
|
|
|
7
|
-
Covering rspec-given, version
|
|
7
|
+
Covering rspec-given, minitest-given, and given-core, version 3.0.0.beta.1.
|
|
8
8
|
|
|
9
|
-
rspec-given
|
|
10
|
-
|
|
11
|
-
work done on the Given framework.
|
|
9
|
+
rspec-given and minitest-given are extensions to your favorite testing
|
|
10
|
+
framework to allow Given/When/Then notation when writing specs.
|
|
12
11
|
|
|
13
12
|
# Why Given/When/Then
|
|
14
13
|
|
|
15
14
|
RSpec has done a great job of making specifications more readable for
|
|
16
|
-
humans.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
RSpec specifications.
|
|
15
|
+
humans. However, I really like the given/when/then nature of Cucumber
|
|
16
|
+
stories and would like to follow the same structure in my unit tests.
|
|
17
|
+
rspec-given (and now minitest-given) allows a simple given/when/then
|
|
18
|
+
structure RSpec specifications.
|
|
20
19
|
|
|
21
20
|
## Status
|
|
22
21
|
|
|
23
|
-
rspec-given is ready for production use.
|
|
22
|
+
* rspec-given is ready for production use.
|
|
23
|
+
* minitest-given is experimental.
|
|
24
|
+
|
|
25
|
+
### RSpec/Given
|
|
26
|
+
|
|
27
|
+
The rspec-given gem is the original given/when/then extension for
|
|
28
|
+
RSpec. It now depends on a given_core gem for the basic functionality
|
|
29
|
+
and then adds the RSpec specific code.
|
|
30
|
+
|
|
31
|
+
* rspec-given now requires RSpec version 2.12 or better.
|
|
32
|
+
|
|
33
|
+
### Minitest/Given
|
|
34
|
+
|
|
35
|
+
A new minitest-given gem allows Given/When/Then notation directly in
|
|
36
|
+
Minitest::Spec specifications.
|
|
37
|
+
|
|
38
|
+
To use minitest-given, just place the following require at the top of
|
|
39
|
+
the file (or in a convenient spec_helper).
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
require 'minitest/given'
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
All the features of rspec-given are available in minitest-given.
|
|
46
|
+
|
|
47
|
+
When switching from RSpec/Given to Minitest/Given, here are some
|
|
48
|
+
things to watch out for:
|
|
49
|
+
|
|
50
|
+
* You need to use Minitest version 4.3 or better (yes, Minitest 5.x
|
|
51
|
+
should work as well).
|
|
52
|
+
|
|
53
|
+
* Minitest/Given adds the missing "context" block to Minitest::Spec.
|
|
54
|
+
|
|
55
|
+
* Only one before block is allowed in any given Minitest::Spec
|
|
56
|
+
describe block. This doesn't effect the number of Givens you are
|
|
57
|
+
allowed to use, but it may surprise if you are use to RSpec.
|
|
58
|
+
|
|
59
|
+
### Auto Selecting
|
|
60
|
+
|
|
61
|
+
If you use natural assertions exclusively in your specs, it's quite
|
|
62
|
+
possible to write specs that run under both RSpec and Minitest::Spec.
|
|
63
|
+
|
|
64
|
+
Use this at the start of your spec file:
|
|
65
|
+
|
|
66
|
+
```ruby
|
|
67
|
+
if defined?(RSpec)
|
|
68
|
+
require 'rspec/given'
|
|
69
|
+
else
|
|
70
|
+
require 'minitest/autorun'
|
|
71
|
+
require 'minitest/given'
|
|
72
|
+
end
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
See
|
|
76
|
+
[stack_spec.rb](https://github.com/jimweirich/rspec-given/blob/minispec/examples/stack/stack_spec.rb)
|
|
77
|
+
and
|
|
78
|
+
[example_helper.rb](https://github.com/jimweirich/rspec-given/blob/minispec/examples/example_helper.rb)
|
|
79
|
+
|
|
80
|
+
## Installation
|
|
81
|
+
|
|
82
|
+
### If you are using bundler
|
|
83
|
+
|
|
84
|
+
Add `rspec-given` (or `minitest-given`) to the `:test` group in the `Gemfile`:
|
|
85
|
+
|
|
86
|
+
```ruby
|
|
87
|
+
group :test do
|
|
88
|
+
gem 'rspec-given'
|
|
89
|
+
end
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
```ruby
|
|
93
|
+
group :test do
|
|
94
|
+
gem 'minitest-given'
|
|
95
|
+
end
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Download and install:
|
|
99
|
+
|
|
100
|
+
`$ bundle`
|
|
101
|
+
|
|
102
|
+
Then just require `rspec/given` (or `minitest/given`) in the
|
|
103
|
+
`spec_helper` of your project and it is ready to go.
|
|
104
|
+
|
|
105
|
+
### If you are not using bundler
|
|
106
|
+
|
|
107
|
+
Install the gem:
|
|
108
|
+
|
|
109
|
+
`$ gem install rspec-given`
|
|
110
|
+
|
|
111
|
+
or
|
|
112
|
+
|
|
113
|
+
`$ gem install minitest-given`
|
|
114
|
+
|
|
115
|
+
Then just require `rspec/given` (or `minitest/given`) in the
|
|
116
|
+
`spec_helper` of your project and it is ready to go.
|
|
24
117
|
|
|
25
118
|
## Example
|
|
26
119
|
|
|
@@ -39,22 +132,22 @@ describe Stack do
|
|
|
39
132
|
end
|
|
40
133
|
|
|
41
134
|
Given(:stack) { stack_with(initial_contents) }
|
|
42
|
-
Invariant { stack.empty
|
|
135
|
+
Invariant { stack.empty? == (stack.depth == 0) }
|
|
43
136
|
|
|
44
137
|
context "with no items" do
|
|
45
138
|
Given(:initial_contents) { [] }
|
|
46
|
-
Then { stack.depth
|
|
139
|
+
Then { stack.depth == 0 }
|
|
47
140
|
|
|
48
141
|
context "when pushing" do
|
|
49
142
|
When { stack.push(:an_item) }
|
|
50
143
|
|
|
51
|
-
Then { stack.depth
|
|
52
|
-
Then { stack.top
|
|
144
|
+
Then { stack.depth == 1 }
|
|
145
|
+
Then { stack.top == :an_item }
|
|
53
146
|
end
|
|
54
147
|
|
|
55
148
|
context "when popping" do
|
|
56
149
|
When(:result) { stack.pop }
|
|
57
|
-
Then { result
|
|
150
|
+
Then { result == Failure(Stack::UnderflowError, /empty/) }
|
|
58
151
|
end
|
|
59
152
|
end
|
|
60
153
|
|
|
@@ -64,8 +157,8 @@ describe Stack do
|
|
|
64
157
|
context "when popping" do
|
|
65
158
|
When(:pop_result) { stack.pop }
|
|
66
159
|
|
|
67
|
-
Then { pop_result
|
|
68
|
-
Then { stack.depth
|
|
160
|
+
Then { pop_result == :an_item }
|
|
161
|
+
Then { stack.depth == 0 }
|
|
69
162
|
end
|
|
70
163
|
end
|
|
71
164
|
|
|
@@ -76,16 +169,16 @@ describe Stack do
|
|
|
76
169
|
context "when pushing" do
|
|
77
170
|
When { stack.push(:new_item) }
|
|
78
171
|
|
|
79
|
-
Then { stack.top
|
|
80
|
-
Then { stack.depth
|
|
172
|
+
Then { stack.top == :new_item }
|
|
173
|
+
Then { stack.depth == original_depth + 1 }
|
|
81
174
|
end
|
|
82
175
|
|
|
83
176
|
context "when popping" do
|
|
84
177
|
When(:pop_result) { stack.pop }
|
|
85
178
|
|
|
86
|
-
Then { pop_result
|
|
87
|
-
Then { stack.top
|
|
88
|
-
Then { stack.depth
|
|
179
|
+
Then { pop_result == :top_item }
|
|
180
|
+
Then { stack.top == :second_item }
|
|
181
|
+
Then { stack.depth == original_depth - 1 }
|
|
89
182
|
end
|
|
90
183
|
end
|
|
91
184
|
end
|
|
@@ -252,7 +345,7 @@ should use an empty _Then_ clause, like this:
|
|
|
252
345
|
#### Then examples:
|
|
253
346
|
|
|
254
347
|
```ruby
|
|
255
|
-
Then { stack.
|
|
348
|
+
Then { stack.empty? }
|
|
256
349
|
```
|
|
257
350
|
|
|
258
351
|
After the related block for the _When_ clause is run, the stack should
|
|
@@ -299,9 +392,9 @@ stick with _Then_ clauses.
|
|
|
299
392
|
#### Then/And examples:
|
|
300
393
|
|
|
301
394
|
```ruby
|
|
302
|
-
Then { pop_result
|
|
303
|
-
And { stack.top
|
|
304
|
-
And { stack.depth
|
|
395
|
+
Then { pop_result == :top_item } # Required
|
|
396
|
+
And { stack.top == :second_item } # No Setup rerun
|
|
397
|
+
And { stack.depth == original_depth - 1 } # ... for these
|
|
305
398
|
```
|
|
306
399
|
|
|
307
400
|
### Invariant
|
|
@@ -365,29 +458,56 @@ clauses and _before_ blocks.
|
|
|
365
458
|
|
|
366
459
|
## Natural Assertions
|
|
367
460
|
|
|
368
|
-
**NOTE:** <em>Natural assertions are currently an experimental feature
|
|
369
|
-
of RSpec/Given. They are currently disabled by default, but can be
|
|
370
|
-
enabled by a simple configuration option (see "use_natural_assertions"
|
|
371
|
-
below).</em>
|
|
372
|
-
|
|
373
461
|
RSpec/Given now supports the use of "natural assertions" in _Then_,
|
|
374
462
|
_And_, and _Invariant_ blocks. Natural assertions are just Ruby
|
|
375
463
|
conditionals, without the _should_ or _expect_ methods that RSpec
|
|
376
|
-
provides. Here are the Then/And examples
|
|
377
|
-
|
|
464
|
+
provides. Here are the Then/And examples showing natural assertions:
|
|
465
|
+
|
|
466
|
+
### Using Natural Assertions
|
|
467
|
+
|
|
468
|
+
```ruby
|
|
469
|
+
Then { stack.top == :second_item }
|
|
470
|
+
Then { stack.depth == original_depth - 1 }
|
|
471
|
+
Then { result == Failure(Stack::UnderflowError, /empty/) }
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
### Using RSpec expect().to
|
|
475
|
+
|
|
476
|
+
```ruby
|
|
477
|
+
Then { expect(stack.top).to eq(:second_item) }
|
|
478
|
+
Then { expect(stack.depth).to eq(original_depth - 1) }
|
|
479
|
+
Then { expect(result).to have_failed(Stack::UnderflowError, /empty/) }
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
### Using Minitest asserts
|
|
483
|
+
|
|
484
|
+
```ruby
|
|
485
|
+
Then { assert_equal :second_item, stack.top }
|
|
486
|
+
Then { assert_equal original_depth - 1, stack.depth }
|
|
487
|
+
Then {
|
|
488
|
+
assert_raises(Stack::UnderflowError, /empty/) do
|
|
489
|
+
result.call()
|
|
490
|
+
end
|
|
491
|
+
}
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
### Using Minitest expectations
|
|
378
495
|
|
|
379
496
|
```ruby
|
|
380
|
-
Then {
|
|
381
|
-
|
|
382
|
-
|
|
497
|
+
Then { stack.top.must_equal :second_item }
|
|
498
|
+
Then { stack.depth.must_equal original_depth - 1}
|
|
499
|
+
Then { result.must_raise(Stack::UnderflowError, /empty/) }
|
|
383
500
|
```
|
|
384
501
|
|
|
385
|
-
|
|
386
|
-
context basis, to be recognized.
|
|
502
|
+
### Disabling Natural Assertions
|
|
387
503
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
504
|
+
Natural assertions may be disabled, either globally or on a per
|
|
505
|
+
context basis. See the **configuration** section below to see how to
|
|
506
|
+
disable natural assertions project wide.
|
|
507
|
+
|
|
508
|
+
Here's a heads up: If you use natural assertions, but configure Given
|
|
509
|
+
to disable them, then all your specs will mysteriously pass. This is
|
|
510
|
+
why the **red** part of _Red/Green/Refactor_ is so important.
|
|
391
511
|
|
|
392
512
|
### Failure Messages with Natural Assertions
|
|
393
513
|
|
|
@@ -398,7 +518,7 @@ analsysis of the expression that failed.
|
|
|
398
518
|
For example, given the following failing specification:
|
|
399
519
|
|
|
400
520
|
```ruby
|
|
401
|
-
|
|
521
|
+
Given.use_natural_assertions
|
|
402
522
|
|
|
403
523
|
describe "Natural Assertions" do
|
|
404
524
|
Given(:foo) { 1 }
|
|
@@ -432,6 +552,19 @@ Natural assertions will give additional information (e.g. "expected:
|
|
|
432
552
|
comparison operators (==, !=, <, <=, >, >=) or matching operators (=~,
|
|
433
553
|
!~).
|
|
434
554
|
|
|
555
|
+
### Checking for exceptions with Natural Assertions
|
|
556
|
+
|
|
557
|
+
If you wish to see if the result of a _When_ clause is an exception,
|
|
558
|
+
you can use the following:
|
|
559
|
+
|
|
560
|
+
```ruby
|
|
561
|
+
When(:result) { stack.pop }
|
|
562
|
+
Then { result == Failure(UnderflowError, /empty/) }
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
The <code>Failure()</code> method accepts the same arguments as
|
|
566
|
+
<code>have_failed</code> and <code>raise_error</code>.
|
|
567
|
+
|
|
435
568
|
### Caveats on Natural Assertions
|
|
436
569
|
|
|
437
570
|
Keep the following in mind when using natural assertions.
|
|
@@ -480,23 +613,22 @@ like this is good:
|
|
|
480
613
|
```
|
|
481
614
|
|
|
482
615
|
It is good to note that non-idempotent assertions will also cause
|
|
483
|
-
problems with And clauses.
|
|
616
|
+
problems with And and Invariant clauses.
|
|
484
617
|
|
|
485
618
|
### Mixing Natural Assertions and RSpec Assertions
|
|
486
619
|
|
|
487
|
-
Natural assertions
|
|
488
|
-
intermixed in a single test suite, even within a single
|
|
489
|
-
|
|
490
|
-
must be explicitly enabled before they will be considered.
|
|
491
|
-
|
|
492
|
-
To enable natural assertions in a context, call the
|
|
493
|
-
_use_natural_assertions_ method in that context. For example:
|
|
620
|
+
Natural assertions, RSpec should assertions and Minitest assertions
|
|
621
|
+
can be intermixed in a single test suite, even within a single
|
|
622
|
+
context.
|
|
494
623
|
|
|
495
624
|
```ruby
|
|
496
625
|
context "Outer" do
|
|
497
|
-
use_natural_assertions
|
|
498
|
-
|
|
499
626
|
context "Inner" do
|
|
627
|
+
Then { a == b } # Natural Assertions
|
|
628
|
+
Then { a.should == b } # RSpec style
|
|
629
|
+
Then { expect(a).to eq(b) } # RSpec style
|
|
630
|
+
Then { assert_equal b, a } # Minitest style
|
|
631
|
+
Then { a.must_equal b } # Minitest style
|
|
500
632
|
end
|
|
501
633
|
|
|
502
634
|
context "Disabled" do
|
|
@@ -509,7 +641,7 @@ Both the _Outer_ and _Inner_ contexts will use natural assertions. The
|
|
|
509
641
|
_Disabled_ context overrides the setting inherited from _Outer_ and
|
|
510
642
|
will not process natural assertions.
|
|
511
643
|
|
|
512
|
-
See the **configuration** section below to see how to
|
|
644
|
+
See the **configuration** section below to see how to disable natural
|
|
513
645
|
assertions project wide.
|
|
514
646
|
|
|
515
647
|
### Matchers and Natural Assertions
|
|
@@ -554,7 +686,7 @@ There are several ways of creating fuzzy numbers:
|
|
|
554
686
|
|
|
555
687
|
* <code>about(n)</code> -- Same as <code>about(n).epsilon(10)</code>.
|
|
556
688
|
|
|
557
|
-
When the file <code>
|
|
689
|
+
When the file <code>given/fuzzy_shortcuts</code> is required,
|
|
558
690
|
the following unicode shortcut methods are added to Numeric to create
|
|
559
691
|
fuzzy numbers.
|
|
560
692
|
|
|
@@ -571,7 +703,7 @@ fuzzy numbers.
|
|
|
571
703
|
|
|
572
704
|
The RSpec matcher used for detecting exceptions will work with natural
|
|
573
705
|
assertions out of the box. Just check for equality against the
|
|
574
|
-
<code>
|
|
706
|
+
<code>Failure()</code> method return value.
|
|
575
707
|
|
|
576
708
|
For example, the following two Then clauses are equivalent:
|
|
577
709
|
|
|
@@ -580,7 +712,7 @@ For example, the following two Then clauses are equivalent:
|
|
|
580
712
|
Then { result.should have_failed(StandardError, /message/) }
|
|
581
713
|
|
|
582
714
|
# Using natural assertions
|
|
583
|
-
Then { result ==
|
|
715
|
+
Then { result == Failure(StandardError, /message/) }
|
|
584
716
|
```
|
|
585
717
|
|
|
586
718
|
### Processing Natural Assertions
|
|
@@ -594,7 +726,9 @@ following are true:
|
|
|
594
726
|
1. The block returns false (blocks that return true pass the
|
|
595
727
|
assertion and don't need a failure message).
|
|
596
728
|
|
|
597
|
-
1. The block does not use
|
|
729
|
+
1. The block does not use the native frameworks assertions or
|
|
730
|
+
expectations (e.g. RSpec's _should_ or _expect_ methods, or
|
|
731
|
+
Minitest's _assert\_xxx_ or _must\_xxx_ methods).
|
|
598
732
|
|
|
599
733
|
Detecting that last point (the use of _should_ and _expect_) is done
|
|
600
734
|
by modifying the RSpec runtime to report uses of _should_ and
|
|
@@ -604,11 +738,11 @@ _expect_.
|
|
|
604
738
|
|
|
605
739
|
Natural assertions use the Ripper library to parse the failing
|
|
606
740
|
condition and find all the sub-expression values upon a failure.
|
|
607
|
-
Currently Ripper is not supported on JRuby 1.7.
|
|
608
|
-
said that Ripper support is coming soon and may arrive
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
741
|
+
Currently Ripper is not fully supported on JRuby 1.7.4. Charles Nutter
|
|
742
|
+
has said that Ripper support is coming soon and may arrive soon. Until
|
|
743
|
+
then, natural assertions are disabled when running under JRuby. Never
|
|
744
|
+
fear, JRuby supports all the other features of rspec-given and will
|
|
745
|
+
work just fine.
|
|
612
746
|
|
|
613
747
|
### Further Reading
|
|
614
748
|
|
|
@@ -619,9 +753,6 @@ Conover](http://rubygems.org/profiles/sconoversf).
|
|
|
619
753
|
|
|
620
754
|
## Configuration
|
|
621
755
|
|
|
622
|
-
Just require 'rspec/given' in the spec helper of your project and it
|
|
623
|
-
is ready to go.
|
|
624
|
-
|
|
625
756
|
If the RSpec format option document, html or textmate is chosen,
|
|
626
757
|
RSpec/Given will automatically add additional source code information to
|
|
627
758
|
the examples to produce better looking output. If you don't care about
|
|
@@ -629,7 +760,7 @@ the pretty output and wish to disable source code caching
|
|
|
629
760
|
unconditionally, then add the following line to your spec helper file:
|
|
630
761
|
|
|
631
762
|
```ruby
|
|
632
|
-
|
|
763
|
+
Given.source_caching_disabled = true
|
|
633
764
|
```
|
|
634
765
|
|
|
635
766
|
Natural assertions are disabled by default. To globally configure
|
|
@@ -637,20 +768,39 @@ natural assertions, add one of the following lines to your spec_helper
|
|
|
637
768
|
file:
|
|
638
769
|
|
|
639
770
|
```ruby
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
771
|
+
Given.use_natural_assertions # Enable natural assertions
|
|
772
|
+
Given.use_natural_assertions true # Same as above
|
|
773
|
+
Given.use_natural_assertions false # Disable natural assertions
|
|
774
|
+
Given.use_natural_assertions :always # Always process natural assertions
|
|
775
|
+
# ... even when should/expect are detected
|
|
645
776
|
```
|
|
646
777
|
|
|
647
778
|
# License
|
|
648
779
|
|
|
649
|
-
|
|
650
|
-
file in the source distribution.
|
|
780
|
+
rspec-given, minitest-given and given_core are available under the MIT
|
|
781
|
+
License. See the MIT-LICENSE file in the source distribution.
|
|
651
782
|
|
|
652
783
|
# History
|
|
653
784
|
|
|
785
|
+
* Version 3.0.0
|
|
786
|
+
|
|
787
|
+
* Support for minitest added.
|
|
788
|
+
|
|
789
|
+
* Introduced gem given_core to contain the common logic between the
|
|
790
|
+
RSpec and Minitest versions. Both the rspec-given gem and the
|
|
791
|
+
minitest-given gem have a dependency on given_core.
|
|
792
|
+
|
|
793
|
+
* Natural assertions are now enabled by default.
|
|
794
|
+
|
|
795
|
+
* Version 2.4.4
|
|
796
|
+
|
|
797
|
+
* Support for RSpec 2.13 added.
|
|
798
|
+
|
|
799
|
+
* Version 2.4.3
|
|
800
|
+
|
|
801
|
+
* Better natural assertion messages when dealing with multi-line
|
|
802
|
+
output.
|
|
803
|
+
|
|
654
804
|
* Version 2.4.2
|
|
655
805
|
|
|
656
806
|
* Minor adjustment to natural assertion error messages to better
|
data/Rakefile
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/ruby -wKU
|
|
2
2
|
|
|
3
3
|
require 'rake/clean'
|
|
4
|
-
require './lib/
|
|
5
|
-
require './lib/
|
|
4
|
+
require './lib/given/version'
|
|
5
|
+
require './lib/given/module_methods'
|
|
6
6
|
|
|
7
7
|
CLEAN.include("pkg/rspec-given-*").exclude("pkg/*.gem")
|
|
8
8
|
CLOBBER.include("*.gemspec", "html", "README", "README.old")
|
|
9
9
|
|
|
10
10
|
# README Formatting --------------------------------------------------
|
|
11
11
|
|
|
12
|
-
task :default => :
|
|
12
|
+
task :default => :examples
|
|
13
13
|
|
|
14
14
|
def version
|
|
15
|
-
|
|
15
|
+
Given::VERSION
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def tag_name
|
|
@@ -44,10 +44,10 @@ end
|
|
|
44
44
|
# Running examples ---------------------------------------------------
|
|
45
45
|
|
|
46
46
|
desc "Run all the examples"
|
|
47
|
-
task :examples => [:specs, :
|
|
47
|
+
task :examples => [:specs, :rs_examples]
|
|
48
48
|
|
|
49
49
|
desc "Run the RSpec 2 specs and examples"
|
|
50
|
-
task :
|
|
50
|
+
task :examples => [:specs, :rs_examples, :mt_examples]
|
|
51
51
|
|
|
52
52
|
desc "Run the specs"
|
|
53
53
|
task :specs do
|
|
@@ -55,28 +55,37 @@ task :specs do
|
|
|
55
55
|
sh "rspec spec"
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
-
desc "Run the examples in RSpec 1"
|
|
59
|
-
task :examples1 => [:verify_rspec1] do
|
|
60
|
-
puts "Running examples (with RSpec2)"
|
|
61
|
-
sh "spec examples/stack/stack_spec1.rb"
|
|
62
|
-
end
|
|
63
|
-
|
|
64
58
|
EXAMPLES = FileList['examples/**/*_spec.rb'].
|
|
65
59
|
exclude('examples/failing/*.rb').
|
|
60
|
+
exclude('examples/minitest/*.rb').
|
|
66
61
|
exclude('examples/integration/failing/*.rb')
|
|
67
62
|
|
|
68
|
-
|
|
63
|
+
MT_EXAMPLES = FileList['examples/minitest/**/*_spec.rb']
|
|
64
|
+
|
|
65
|
+
unless Given::NATURAL_ASSERTIONS_SUPPORTED
|
|
69
66
|
EXAMPLES.exclude("examples/stack/*.rb")
|
|
70
67
|
end
|
|
71
68
|
|
|
72
69
|
FAILING_EXAMPLES = FileList['examples/failing/**/*_spec.rb']
|
|
73
70
|
|
|
71
|
+
desc "Run the RSpec specs and examples"
|
|
72
|
+
task :rs => [:specs, :rs_examples]
|
|
73
|
+
|
|
74
|
+
desc "Run the Minitest tests and examples"
|
|
75
|
+
task :mt => [:specs, :mt_examples]
|
|
76
|
+
|
|
74
77
|
desc "Run the examples in RSpec 2"
|
|
75
|
-
task :
|
|
78
|
+
task :rs_examples => [:verify_rspec2] do
|
|
76
79
|
puts "Running examples (with RSpec2)"
|
|
77
80
|
sh "rspec #{EXAMPLES}"
|
|
78
81
|
end
|
|
79
82
|
|
|
83
|
+
desc "Run the examples in Minitest"
|
|
84
|
+
task :mt_examples do
|
|
85
|
+
puts "Running examples (with Minitest)"
|
|
86
|
+
sh "ruby -Ilib:examples examples/loader.rb #{EXAMPLES} #{MT_EXAMPLES}"
|
|
87
|
+
end
|
|
88
|
+
|
|
80
89
|
desc "Run failing examples"
|
|
81
90
|
task :failing => [:verify_rspec2] do
|
|
82
91
|
puts "Running failing examples (with RSpec2)"
|
|
@@ -114,7 +123,7 @@ task :readme => ["README.md"] do
|
|
|
114
123
|
end
|
|
115
124
|
|
|
116
125
|
desc "Generate an RDoc README"
|
|
117
|
-
file "README.md" => ["examples/stack/stack_spec.rb", "lib/
|
|
126
|
+
file "README.md" => ["examples/stack/stack_spec.rb", "lib/given/version.rb"] do
|
|
118
127
|
open("README.md") do |ins|
|
|
119
128
|
open("README.tmp", "w") do |outs|
|
|
120
129
|
state = :copy
|
|
@@ -122,7 +131,7 @@ file "README.md" => ["examples/stack/stack_spec.rb", "lib/rspec/given/version.rb
|
|
|
122
131
|
case state
|
|
123
132
|
when :copy
|
|
124
133
|
if line =~ /rspec-given, version +\d+(\.(\d+|beta))+/i
|
|
125
|
-
line.gsub!(/version +\d+(\.(\d+|beta))+/i, "version #{
|
|
134
|
+
line.gsub!(/version +\d+(\.(\d+|beta))+/i, "version #{Given::VERSION}")
|
|
126
135
|
outs.puts line
|
|
127
136
|
elsif line =~ /^<pre>/
|
|
128
137
|
state = :insert
|
|
@@ -212,7 +221,7 @@ if RDOC_ENABLED
|
|
|
212
221
|
rdoc.options = [
|
|
213
222
|
'--line-numbers',
|
|
214
223
|
'--main' , 'doc/main.rdoc',
|
|
215
|
-
'--title', '
|
|
224
|
+
'--title', 'Given - Given/When/Then Extensions for RSpec'
|
|
216
225
|
]
|
|
217
226
|
rdoc.options << '-SHN' << '-f' << 'darkfish' if DARKFISH_ENABLED
|
|
218
227
|
|
data/TODO
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Things to do to improve the minitest integration
|
|
2
|
+
|
|
3
|
+
TODO:
|
|
4
|
+
|
|
5
|
+
* Make a separate gem for minitest (do we need one for given-core?)
|
|
6
|
+
|
|
7
|
+
DONE:
|
|
8
|
+
|
|
9
|
+
* Handle have_failed in minitest
|
|
10
|
+
* General cleanup making sure files go where they need.
|
|
11
|
+
* Implement assertion counting for minitest
|
|
12
|
+
* Figure out why the minitest example count is so low.
|
|
13
|
+
* Move stuff out of minitest_helper to appropriate file.
|
data/examples/example_helper.rb
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
require 'rspec/given'
|
|
2
1
|
require 'example_helper'
|
|
3
2
|
|
|
4
3
|
describe "And" do
|
|
@@ -6,30 +5,26 @@ describe "And" do
|
|
|
6
5
|
Given(:info) { [] }
|
|
7
6
|
|
|
8
7
|
describe "And is called after Then" do
|
|
9
|
-
Given(:m) { double("mock") }
|
|
10
|
-
Given { m.should_receive(:and_ran) }
|
|
11
8
|
Then { info << "T" }
|
|
12
|
-
And {
|
|
13
|
-
|
|
14
|
-
m.and_ran
|
|
15
|
-
}
|
|
9
|
+
And { info << "A" }
|
|
10
|
+
And { given_assert_equal ["T", "A"], info }
|
|
16
11
|
end
|
|
17
12
|
|
|
18
13
|
describe "And is called only once with multiple Thens" do
|
|
19
14
|
Then { info << "T" }
|
|
20
15
|
Then { info << "T2" }
|
|
21
|
-
And { info
|
|
16
|
+
And { given_assert(info == ["T"] || info == ["T2"]) }
|
|
22
17
|
end
|
|
23
18
|
|
|
24
19
|
describe "Inherited Ands are not run" do
|
|
25
20
|
Then { info << "T-OUTER" }
|
|
26
21
|
And { info << "A-OUTER" }
|
|
27
|
-
And {
|
|
22
|
+
And { given_assert_equal ["T-OUTER", "A-OUTER"], info }
|
|
28
23
|
|
|
29
24
|
context "inner" do
|
|
30
25
|
Then { info << "T-INNER" }
|
|
31
26
|
And { info << "A-INNER" }
|
|
32
|
-
And {
|
|
27
|
+
And { given_assert_equal ["T-INNER", "A-INNER"], info }
|
|
33
28
|
end
|
|
34
29
|
end
|
|
35
30
|
|
|
@@ -42,7 +37,7 @@ describe "And" do
|
|
|
42
37
|
|
|
43
38
|
it "should define a message" do
|
|
44
39
|
message = self.class.instance_eval { @message }
|
|
45
|
-
|
|
40
|
+
given_assert_match(/and.*without.*then/i, message)
|
|
46
41
|
end
|
|
47
42
|
end
|
|
48
43
|
|