spectrum 0.0.1 → 0.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 +7 -0
- data/HISTORY.md +56 -0
- data/LICENSE.txt +22 -0
- data/README.md +255 -0
- data/lib/spectrum/describe.rb +55 -0
- data/lib/spectrum/feature/advice.rb +31 -0
- data/lib/spectrum/feature/feature.rb +192 -0
- data/lib/spectrum/feature/featurette.rb +68 -0
- data/lib/spectrum/feature/scenario.rb +203 -0
- data/lib/spectrum/feature/step.rb +50 -0
- data/lib/spectrum/feature.rb +45 -0
- data/lib/spectrum/spec/context.rb +409 -0
- data/lib/spectrum/spec/example.rb +231 -0
- data/lib/spectrum/spec/hooks.rb +83 -0
- data/lib/spectrum/testcase/test_case.rb +328 -0
- data/lib/spectrum/testcase/test_proc.rb +143 -0
- data/lib/spectrum/testcase.rb +28 -0
- data/lib/spectrum/version.rb +3 -0
- data/lib/spectrum/world.rb +15 -0
- data/lib/spectrum.rb +14 -138
- metadata +71 -72
- data/History.txt +0 -93
- data/Install.txt +0 -18
- data/Licence.txt +0 -27
- data/README.txt +0 -35
- data/lib/spectrum/cmyk.rb +0 -281
- data/lib/spectrum/css.rb +0 -28
- data/lib/spectrum/grayscale.rb +0 -212
- data/lib/spectrum/hsl.rb +0 -221
- data/lib/spectrum/palette/adobecolor.rb +0 -272
- data/lib/spectrum/palette/gimp.rb +0 -116
- data/lib/spectrum/palette/monocontrast.rb +0 -180
- data/lib/spectrum/palette.rb +0 -16
- data/lib/spectrum/rgb/metallic.rb +0 -43
- data/lib/spectrum/rgb-colors.rb +0 -355
- data/lib/spectrum/rgb.rb +0 -453
- data/lib/spectrum/yiq.rb +0 -84
- data/test/test_adobecolor.rb +0 -419
- data/test/test_all.rb +0 -23
- data/test/test_cmyk.rb +0 -128
- data/test/test_color.rb +0 -141
- data/test/test_css.rb +0 -29
- data/test/test_gimp.rb +0 -101
- data/test/test_grayscale.rb +0 -121
- data/test/test_hsl.rb +0 -153
- data/test/test_monocontrast.rb +0 -142
- data/test/test_rgb.rb +0 -344
- data/test/test_yiq.rb +0 -73
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 954031655d24d867fcf4cc00dbfc3ca7136777c7e897b8ef51d3af8027317222
|
|
4
|
+
data.tar.gz: e28f1a337cad5253eaa4fdbc8fe1124fe04b0abf27c4cbc92795494a0e47ee9b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 40d58c7e53cdf7805eed9dfedf0a2b89f2d0582e18135250d30da07c01c2224b4d825d11b214b75397d5f1aa9224b12ebc7096b4917fa4cee850a35ea701568c
|
|
7
|
+
data.tar.gz: 1336d72a9fd518768c65e2a62e3d182495aef6a5c8629184e6ad9f1b15e9d28451b8d3416b61d277add3ba63136d8455635fa08f4c49f10357f9800f6cf4728d
|
data/HISTORY.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# HISTORY
|
|
2
|
+
|
|
3
|
+
## 0.2.0 | 2026-11-24
|
|
4
|
+
|
|
5
|
+
Spectrum brings three test frameworks together as one library of test
|
|
6
|
+
structures: Citron (test cases), Spectroscope (specifications) and Lime
|
|
7
|
+
(features). Each is loaded on its own, and all run on Rubytest. Spectrum
|
|
8
|
+
needs Ruby 2.7 or newer.
|
|
9
|
+
|
|
10
|
+
The gem named `spectrum` was an unrelated colour library in 2012, a copy
|
|
11
|
+
of the `color` gem, released as 0.0.1 and 0.1.0 (since yanked). This
|
|
12
|
+
release shares nothing with it but the name, and starts at 0.2.0 because
|
|
13
|
+
those numbers are taken.
|
|
14
|
+
|
|
15
|
+
Changes from the separate gems:
|
|
16
|
+
|
|
17
|
+
* `require 'spectrum/testcase'` in place of `citron`, `spectrum/describe` in place
|
|
18
|
+
of `spectroscope`, `spectrum/feature` in place of `lime`. The classes are
|
|
19
|
+
`Spectrum::TestCase`, `Spectrum::Spec::Context` and `Example`, and
|
|
20
|
+
`Spectrum::Feature`; a featurette includes `Spectrum::Featurette`.
|
|
21
|
+
* `Spectrum::World` is one module for all three. A method defined in it is
|
|
22
|
+
available inside every test, example and step.
|
|
23
|
+
* No assertion library is required or assumed.
|
|
24
|
+
|
|
25
|
+
Test cases:
|
|
26
|
+
|
|
27
|
+
* Each test runs in an instance of its own. Before, the tests of a case
|
|
28
|
+
shared one, and with it their instance variables.
|
|
29
|
+
* Teardown runs when a test fails.
|
|
30
|
+
* A test without a block is reported as still to be done.
|
|
31
|
+
* A parameterized test made with `ok` has its arguments in its label.
|
|
32
|
+
* `skip` with a block restores the earlier setting when the block ends.
|
|
33
|
+
|
|
34
|
+
Specifications:
|
|
35
|
+
|
|
36
|
+
* Before and after hooks apply to the contexts within a context wherever
|
|
37
|
+
they are written, not only to those defined after them. After hooks
|
|
38
|
+
run when an example fails, innermost context first.
|
|
39
|
+
* Fix `skip`, which raised a NameError. It takes a reason and then
|
|
40
|
+
labels, patterns or tags to match, or a block; with neither it skips
|
|
41
|
+
the whole context. `omit` takes the same criteria.
|
|
42
|
+
* Fix a context's hooks leaking into its sibling contexts.
|
|
43
|
+
* Fix `its` with a chain of methods, such as `its("first.size")`.
|
|
44
|
+
* A mistyped method inside an example is a NameError, rather than being
|
|
45
|
+
sent to the subject or reported as a missing `described_class`.
|
|
46
|
+
* Examples run in a plain object instead of a Module.
|
|
47
|
+
|
|
48
|
+
Features:
|
|
49
|
+
|
|
50
|
+
* A step without a definition is reported as still to be done. Before,
|
|
51
|
+
it passed.
|
|
52
|
+
* When a step fails, the steps after it in the scenario are not run.
|
|
53
|
+
* A step definition has to match the whole of a step's description,
|
|
54
|
+
and only the first definition that matches is run. Before, every
|
|
55
|
+
definition that matched any part of it ran.
|
|
56
|
+
* Add `And`, for a further step of the same type as the one before.
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
(BSD-2-Clause License)
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
|
4
|
+
modification, are permitted provided that the following conditions are met:
|
|
5
|
+
|
|
6
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
7
|
+
this list of conditions and the following disclaimer.
|
|
8
|
+
|
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
10
|
+
notice, this list of conditions and the following disclaimer in the
|
|
11
|
+
documentation and/or other materials provided with the distribution.
|
|
12
|
+
|
|
13
|
+
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
14
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
16
|
+
COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
17
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
18
|
+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
19
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
|
20
|
+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
21
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
22
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
# Spectrum
|
|
2
|
+
|
|
3
|
+
[Source Code](https://github.com/rubyworks/spectrum) /
|
|
4
|
+
[Report Issue](https://github.com/rubyworks/spectrum/issues)
|
|
5
|
+
|
|
6
|
+
Spectrum is a library of test structures: the words that organize tests
|
|
7
|
+
into cases, specifications or features. Pick the one you like to write
|
|
8
|
+
in; each is loaded on its own.
|
|
9
|
+
|
|
10
|
+
| Require | Structure |
|
|
11
|
+
|---|---|
|
|
12
|
+
| `spectrum/testcase` | `TestCase "..." do`, `test "..." do`, `setup`, `teardown` |
|
|
13
|
+
| `spectrum/describe` | `describe "..." do`, `it "..." do`, `before`, `after`, `let` |
|
|
14
|
+
| `spectrum/feature` | `Feature "..." do`, `Scenario "..." do`, `Given`, `When`, `Then` |
|
|
15
|
+
|
|
16
|
+
Spectrum does two things and leaves the rest to others:
|
|
17
|
+
|
|
18
|
+
* **Running** is done by [Rubytest](https://github.com/rubyworks/rubytest).
|
|
19
|
+
Every structure builds test objects that Rubytest understands, so its
|
|
20
|
+
command line, report formats and filters work with all of them.
|
|
21
|
+
* **Asserting** is left to an assertion library. Spectrum is the
|
|
22
|
+
counterpart of [Assay](https://github.com/rubyworks/assay), which
|
|
23
|
+
offers a choice of assertion notations in the same way, but anything
|
|
24
|
+
that raises an assertion Rubytest recognizes will do.
|
|
25
|
+
|
|
26
|
+
So a project chooses one of each:
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
# test/helper.rb
|
|
30
|
+
require 'spectrum/describe' # how tests are organized
|
|
31
|
+
require 'assay/ae/should' # how they assert
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
$ rubytest -Ilib -r ./test/helper test/*_spec.rb
|
|
35
|
+
|
|
36
|
+
The examples below use Assay's AE notation.
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## Test cases
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
require 'spectrum/testcase'
|
|
43
|
+
|
|
44
|
+
TestCase Array do
|
|
45
|
+
|
|
46
|
+
setup do
|
|
47
|
+
@list = [1, 2, 3]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
test "has a size" do
|
|
51
|
+
@list.size.assert == 3
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
context "#join" do
|
|
55
|
+
test "joins the elements" do
|
|
56
|
+
@list.join.assert == "123"
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
* `TestCase` is also spelled `test_case` or `testcase`, and `test`,
|
|
64
|
+
`context`, `setup`, `teardown` and `skip` may be capitalized.
|
|
65
|
+
* Each test runs in an instance of its own, after `setup` and before
|
|
66
|
+
`teardown`. A context inherits its parent's.
|
|
67
|
+
* Methods defined in a test case are helpers for its tests.
|
|
68
|
+
* A test without a block is reported as still to be done.
|
|
69
|
+
|
|
70
|
+
A test whose block takes arguments is parameterized, and each `ok`
|
|
71
|
+
after it makes a test of it:
|
|
72
|
+
|
|
73
|
+
```ruby
|
|
74
|
+
test "is even" do |x|
|
|
75
|
+
x.assert.even?
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
ok 2
|
|
79
|
+
ok 4
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
To skip tests, with a reason:
|
|
83
|
+
|
|
84
|
+
```ruby
|
|
85
|
+
skip "waiting on the new parser" do
|
|
86
|
+
test "parses the new syntax" do
|
|
87
|
+
...
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
## Specifications
|
|
94
|
+
|
|
95
|
+
```ruby
|
|
96
|
+
require 'spectrum/describe'
|
|
97
|
+
|
|
98
|
+
describe Array do
|
|
99
|
+
|
|
100
|
+
let(:list) { [1, 2, 3] }
|
|
101
|
+
|
|
102
|
+
before :each do
|
|
103
|
+
@calls = 0
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
it "has a size" do
|
|
107
|
+
list.size.should == 3
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
describe "#join" do
|
|
111
|
+
it "joins the elements" do
|
|
112
|
+
list.join.should == "123"
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it "is something to get to"
|
|
117
|
+
|
|
118
|
+
end
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
* `describe` is also `context` within a specification, and `it` is
|
|
122
|
+
also `example`.
|
|
123
|
+
* `before` and `after` take `:each` (the default) or `:all`, and for
|
|
124
|
+
`:each` may be limited to examples matching a label, pattern or tag:
|
|
125
|
+
`before :each, /database/ do`.
|
|
126
|
+
* `let` and `let!` define values, `subject` the subject, and `its` an
|
|
127
|
+
example about a method of the subject.
|
|
128
|
+
* `shared_examples_for "..."` defines examples that
|
|
129
|
+
`it_behaves_like "..."` brings in.
|
|
130
|
+
* `pending "reason"` inside an example, or an example without a block,
|
|
131
|
+
reports it as still to be done.
|
|
132
|
+
* `skip "reason", /pattern/` skips the examples of the context that
|
|
133
|
+
match, and `skip "reason"` all of them. `omit /pattern/` leaves them
|
|
134
|
+
out altogether.
|
|
135
|
+
|
|
136
|
+
When a specification describes a class, a method the example doesn't
|
|
137
|
+
have is sent to a new instance of that class:
|
|
138
|
+
|
|
139
|
+
```ruby
|
|
140
|
+
describe Array do
|
|
141
|
+
it "starts out empty" do
|
|
142
|
+
size.should == 0
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
## Features
|
|
149
|
+
|
|
150
|
+
```ruby
|
|
151
|
+
require 'spectrum/feature'
|
|
152
|
+
|
|
153
|
+
Feature "Addition" do
|
|
154
|
+
To "avoid silly mistakes"
|
|
155
|
+
As "a math idiot"
|
|
156
|
+
I "need to calculate the sum of numbers"
|
|
157
|
+
|
|
158
|
+
Scenario "Add two numbers" do
|
|
159
|
+
Given "I have entered 50 into the calculator"
|
|
160
|
+
And "I have entered 70 into the calculator"
|
|
161
|
+
When "I press add"
|
|
162
|
+
Then "the result should be 120 on the screen"
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
Given 'I have entered (\d+) into the calculator' do |n|
|
|
166
|
+
@calculator ||= Calculator.new
|
|
167
|
+
@calculator.push n.to_i
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
When 'I press add' do
|
|
171
|
+
@result = @calculator.add
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
Then 'the result should be (\d+) on the screen' do |n|
|
|
175
|
+
@result.assert == n.to_i
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
A scenario lists its steps; the feature defines them. A step is run by
|
|
181
|
+
the first definition of its kind whose description matches the whole
|
|
182
|
+
step, ignoring case and the amount of whitespace. Text in parentheses
|
|
183
|
+
is a regular expression, and what it matches is passed to the block.
|
|
184
|
+
|
|
185
|
+
* Each step is reported as a test. If a step fails, the ones after it
|
|
186
|
+
in the scenario are not run.
|
|
187
|
+
* A step with no definition is reported as still to be done.
|
|
188
|
+
* Each scenario runs in a scope of its own.
|
|
189
|
+
* `skip "reason"` skips the scenario that follows.
|
|
190
|
+
|
|
191
|
+
Step definitions can be shared between features by putting them in a
|
|
192
|
+
module that includes `Spectrum::Featurette`:
|
|
193
|
+
|
|
194
|
+
```ruby
|
|
195
|
+
module CalculatorSteps
|
|
196
|
+
include Spectrum::Featurette
|
|
197
|
+
|
|
198
|
+
When 'I press add' do
|
|
199
|
+
@result = @calculator.add
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
Feature "Addition" do
|
|
204
|
+
include CalculatorSteps
|
|
205
|
+
...
|
|
206
|
+
end
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Files in a `featurettes` directory next to a feature are loaded
|
|
210
|
+
automatically.
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
## Helpers for every test
|
|
214
|
+
|
|
215
|
+
A method defined in `Spectrum::World` is available inside every test,
|
|
216
|
+
example and step, whichever structure it is written in.
|
|
217
|
+
|
|
218
|
+
```ruby
|
|
219
|
+
module Spectrum::World
|
|
220
|
+
def fixture(name)
|
|
221
|
+
File.read("test/fixtures/#{name}")
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
## Where it came from
|
|
228
|
+
|
|
229
|
+
Spectrum combines three earlier gems, which it replaces:
|
|
230
|
+
|
|
231
|
+
| Before | Now |
|
|
232
|
+
|---|---|
|
|
233
|
+
| gem `citron`, `require 'citron'` | `require 'spectrum/testcase'` |
|
|
234
|
+
| gem `spectroscope`, `require 'spectroscope'` | `require 'spectrum/describe'` |
|
|
235
|
+
| gem `lime`, `require 'lime'` | `require 'spectrum/feature'` |
|
|
236
|
+
|
|
237
|
+
The words are the same. What changed is listed in
|
|
238
|
+
[HISTORY.md](HISTORY.md); in short, several things that silently did
|
|
239
|
+
the wrong thing now don't.
|
|
240
|
+
|
|
241
|
+
[Lemon](https://github.com/rubyworks/lemon), the strict unit test
|
|
242
|
+
framework, is a separate gem and also runs on Rubytest.
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
## Installation
|
|
246
|
+
|
|
247
|
+
$ gem install spectrum
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
## License & Copyright
|
|
251
|
+
|
|
252
|
+
Copyright (c) 2011 Rubyworks
|
|
253
|
+
|
|
254
|
+
Spectrum is distributed under the terms of the BSD-2-Clause license. See
|
|
255
|
+
LICENSE.txt for details.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require_relative '../spectrum'
|
|
2
|
+
|
|
3
|
+
module Spectrum
|
|
4
|
+
|
|
5
|
+
# The specification structure: `describe` and `it`.
|
|
6
|
+
#
|
|
7
|
+
module Spec
|
|
8
|
+
require_relative 'spec/hooks'
|
|
9
|
+
require_relative 'spec/example'
|
|
10
|
+
require_relative 'spec/context'
|
|
11
|
+
|
|
12
|
+
# The words the specification structure adds to the toplevel.
|
|
13
|
+
#
|
|
14
|
+
module DSL
|
|
15
|
+
#
|
|
16
|
+
# Define an example group.
|
|
17
|
+
#
|
|
18
|
+
def describe(topic, *tags, &block)
|
|
19
|
+
settings = {:tags => tags}
|
|
20
|
+
if Module === topic
|
|
21
|
+
settings[:subject] = topic
|
|
22
|
+
settings[:label] = topic.name
|
|
23
|
+
else
|
|
24
|
+
settings[:label] = topic
|
|
25
|
+
end
|
|
26
|
+
context = Spectrum::Spec::Context.new(settings, &block)
|
|
27
|
+
$TEST_SUITE << context
|
|
28
|
+
context
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
#
|
|
32
|
+
# Define examples that several groups can share, to be brought in
|
|
33
|
+
# with `it_behaves_like`.
|
|
34
|
+
#
|
|
35
|
+
def shared_examples_for(label, &block)
|
|
36
|
+
Spectrum::Spec.shared_examples[label] = block
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
alias :shared_examples :shared_examples_for
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
#
|
|
43
|
+
# Store for shared examples.
|
|
44
|
+
#
|
|
45
|
+
# @return [Hash] shared examples
|
|
46
|
+
#
|
|
47
|
+
def self.shared_examples
|
|
48
|
+
@shared_examples ||= {}
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
extend Spectrum::Spec::DSL
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module Spectrum
|
|
2
|
+
class Feature
|
|
3
|
+
|
|
4
|
+
# The step definitions of a feature: for each of `given`, `when` and
|
|
5
|
+
# `then`, a table of description patterns and their procedures.
|
|
6
|
+
#
|
|
7
|
+
class Advice
|
|
8
|
+
|
|
9
|
+
#
|
|
10
|
+
attr :table
|
|
11
|
+
|
|
12
|
+
#
|
|
13
|
+
def initialize
|
|
14
|
+
@table = Hash.new{ |h,k| h[k] = {} }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
#
|
|
18
|
+
def initialize_copy(original)
|
|
19
|
+
@table = Hash.new{ |h,k| h[k] = {} }
|
|
20
|
+
original.table.each{ |type, defs| @table[type] = defs.dup }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
#
|
|
24
|
+
def [](type)
|
|
25
|
+
@table[type.to_sym]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
module Spectrum
|
|
2
|
+
|
|
3
|
+
# Features contain scenarios, and the step definitions the scenarios
|
|
4
|
+
# are run by: the _given_, _when_ and _then_ procedures.
|
|
5
|
+
#
|
|
6
|
+
class Feature
|
|
7
|
+
|
|
8
|
+
# Brief description of the feature.
|
|
9
|
+
attr :label
|
|
10
|
+
|
|
11
|
+
# The descriptive details of the feature, defined using
|
|
12
|
+
# the `To`, `As` and `We` methods.
|
|
13
|
+
attr :story
|
|
14
|
+
|
|
15
|
+
# List of scenarios.
|
|
16
|
+
attr :scenarios
|
|
17
|
+
|
|
18
|
+
# The step definitions.
|
|
19
|
+
attr :advice
|
|
20
|
+
|
|
21
|
+
# Module the feature's block is evaluated in. Methods defined
|
|
22
|
+
# there are helpers for the step procedures.
|
|
23
|
+
attr :scope
|
|
24
|
+
|
|
25
|
+
#
|
|
26
|
+
def initialize(settings={}, &block)
|
|
27
|
+
@label = settings[:label]
|
|
28
|
+
|
|
29
|
+
@advice = Advice.new
|
|
30
|
+
@story = []
|
|
31
|
+
@scenarios = []
|
|
32
|
+
|
|
33
|
+
@scope = Scope.new(self, &block)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Convenience method for accessing advice, aka step definitions.
|
|
37
|
+
def [](key)
|
|
38
|
+
@advice[key]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Iterate over each scenario.
|
|
42
|
+
def each(&block)
|
|
43
|
+
scenarios.each(&block)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Number of scenarios.
|
|
47
|
+
def size
|
|
48
|
+
scenarios.size
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# The type is "Feature". This is used by Rubytest in test output.
|
|
52
|
+
def type
|
|
53
|
+
'Feature'
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
#
|
|
57
|
+
def to_s
|
|
58
|
+
(["#{label}"] + story).join("\n")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
#
|
|
62
|
+
# Take on the step definitions of a featurette.
|
|
63
|
+
#
|
|
64
|
+
def update(mixin)
|
|
65
|
+
[:given, :when, :then].each do |type|
|
|
66
|
+
@advice[type].update(mixin[type] || {})
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# The module a feature's block is evaluated in.
|
|
71
|
+
#
|
|
72
|
+
class Scope < Module
|
|
73
|
+
|
|
74
|
+
#
|
|
75
|
+
def initialize(feature, &block)
|
|
76
|
+
super(&nil)
|
|
77
|
+
@_feature = feature
|
|
78
|
+
@_skip = false
|
|
79
|
+
module_eval(&block) if block
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
#
|
|
83
|
+
def To(description)
|
|
84
|
+
@_feature.story << "To " + description
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
alias :to :To
|
|
88
|
+
|
|
89
|
+
#
|
|
90
|
+
def As(description)
|
|
91
|
+
@_feature.story << "As " + description
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
alias :as :As
|
|
95
|
+
|
|
96
|
+
#
|
|
97
|
+
def We(description)
|
|
98
|
+
@_feature.story << "We " + description
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
alias :we :We
|
|
102
|
+
|
|
103
|
+
#
|
|
104
|
+
def I(description)
|
|
105
|
+
@_feature.story << "I " + description
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
alias :i :I
|
|
109
|
+
|
|
110
|
+
#
|
|
111
|
+
# Define a Scenario.
|
|
112
|
+
#
|
|
113
|
+
def Scenario(label, &procedure)
|
|
114
|
+
scenario = Scenario.new(
|
|
115
|
+
@_feature,
|
|
116
|
+
:skip => @_skip,
|
|
117
|
+
:label => label,
|
|
118
|
+
&procedure
|
|
119
|
+
)
|
|
120
|
+
@_feature.scenarios << scenario
|
|
121
|
+
@_skip = false
|
|
122
|
+
scenario
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
alias :scenario :Scenario
|
|
126
|
+
|
|
127
|
+
# Given ...
|
|
128
|
+
#
|
|
129
|
+
# @param [String] description
|
|
130
|
+
# A brief description of the _given_ criteria.
|
|
131
|
+
#
|
|
132
|
+
def Given(description, &procedure)
|
|
133
|
+
@_feature[:given][description] = procedure
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
alias :given :Given
|
|
137
|
+
|
|
138
|
+
# When ...
|
|
139
|
+
#
|
|
140
|
+
# @param [String] description
|
|
141
|
+
# A brief description of the _when_ criteria.
|
|
142
|
+
#
|
|
143
|
+
def When(description, &procedure)
|
|
144
|
+
@_feature[:when][description] = procedure
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
alias :wence :When
|
|
148
|
+
|
|
149
|
+
# Then ...
|
|
150
|
+
#
|
|
151
|
+
# @param [String] description
|
|
152
|
+
# A brief description of the _then_ criteria.
|
|
153
|
+
#
|
|
154
|
+
def Then(description, &procedure)
|
|
155
|
+
@_feature[:then][description] = procedure
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
alias :hence :Then
|
|
159
|
+
|
|
160
|
+
# Skip the next scenario when running feature.
|
|
161
|
+
#
|
|
162
|
+
# skip "for some reason"
|
|
163
|
+
# Scenario "blah blah blah" do
|
|
164
|
+
# # ...
|
|
165
|
+
# end
|
|
166
|
+
#
|
|
167
|
+
def skip(reason=true)
|
|
168
|
+
@_skip = reason
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
#
|
|
172
|
+
# Access to underlying feature instance.
|
|
173
|
+
#
|
|
174
|
+
def _feature
|
|
175
|
+
@_feature
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
#
|
|
179
|
+
# Include module and if a Featurette, also update Feature instance.
|
|
180
|
+
#
|
|
181
|
+
def include(*mixins)
|
|
182
|
+
mixins.each do |mixin|
|
|
183
|
+
@_feature.update(mixin) if Featurette === mixin
|
|
184
|
+
end
|
|
185
|
+
super
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
module Spectrum
|
|
2
|
+
|
|
3
|
+
# A featurette is a module of step definitions that features can share.
|
|
4
|
+
#
|
|
5
|
+
# @example
|
|
6
|
+
#
|
|
7
|
+
# module MyStepDefinitions
|
|
8
|
+
# include Spectrum::Featurette
|
|
9
|
+
#
|
|
10
|
+
# Given "customer's name is '(\w+)'" do |name|
|
|
11
|
+
# @name = name
|
|
12
|
+
# end
|
|
13
|
+
# end
|
|
14
|
+
#
|
|
15
|
+
# Feature "..." do
|
|
16
|
+
# include MyStepDefinitions
|
|
17
|
+
# end
|
|
18
|
+
#
|
|
19
|
+
# Ordinary methods of the module are helpers for the step procedures.
|
|
20
|
+
#
|
|
21
|
+
module Featurette
|
|
22
|
+
|
|
23
|
+
def self.append_features(base)
|
|
24
|
+
base.extend(self)
|
|
25
|
+
base.instance_variable_set(:@_advice, Hash.new{ |h,k| h[k] = {} })
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Given ...
|
|
29
|
+
#
|
|
30
|
+
# @param [String] description
|
|
31
|
+
# A brief description of the _given_ criteria.
|
|
32
|
+
#
|
|
33
|
+
def Given(description, &procedure)
|
|
34
|
+
@_advice[:given][description] = procedure
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
alias :given :Given
|
|
38
|
+
|
|
39
|
+
# When ...
|
|
40
|
+
#
|
|
41
|
+
# @param [String] description
|
|
42
|
+
# A brief description of the _when_ criteria.
|
|
43
|
+
#
|
|
44
|
+
def When(description, &procedure)
|
|
45
|
+
@_advice[:when][description] = procedure
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
alias :wence :When
|
|
49
|
+
|
|
50
|
+
# Then ...
|
|
51
|
+
#
|
|
52
|
+
# @param [String] description
|
|
53
|
+
# A brief description of the _then_ criteria.
|
|
54
|
+
#
|
|
55
|
+
def Then(description, &procedure)
|
|
56
|
+
@_advice[:then][description] = procedure
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
alias :hence :Then
|
|
60
|
+
|
|
61
|
+
# Access to advice.
|
|
62
|
+
def [](key)
|
|
63
|
+
@_advice[key]
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|