rspec-when 0.0.1 → 0.0.2
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 +5 -5
- data/README.md +42 -1
- metadata +5 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 44837389b8a8fe11afe1b9e829a1eaac0e4e7536342a4c95a0d505d7312e399f
|
4
|
+
data.tar.gz: 9aae1e273e5052db62103570ac5c87c84f556b3afbd46ef2c029cfb19c61d2d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c05ca0ac8562fd4f8f7b7cf2e42015534866e05cbffda5f13eff6e3bbc94a3caa5b5767118ab379f2d96aff85d26b3b86e4cc601c12183b57b70c0ec676d338
|
7
|
+
data.tar.gz: e785eb34ea4954d9d311102a4df62834f06e9f21068417ecb102e33c57a7c1ac93ae23ae804e06ae9a3fd6da6dfac1d4d9f3026ca35f646d0e79e05896b20e32
|
data/README.md
CHANGED
@@ -42,4 +42,45 @@ end
|
|
42
42
|
```
|
43
43
|
|
44
44
|
Typical usage is when abstracting common expectations into a helper method to
|
45
|
-
DRY up tests where testing the inverse expectation is also required.
|
45
|
+
DRY up tests where testing the inverse expectation is also required.
|
46
|
+
|
47
|
+
## Examples
|
48
|
+
|
49
|
+
The most common place I find these types of wrappers useful is when testing
|
50
|
+
access privileges on users. Instead of testing each user type independently,
|
51
|
+
they can all be tested at once with an easy to read and understand syntax
|
52
|
+
|
53
|
+
so
|
54
|
+
|
55
|
+
```rb
|
56
|
+
context 'admin' do
|
57
|
+
subject(:user) { build(:user, :admin) }
|
58
|
+
|
59
|
+
it { is_expected.to have_property_a }
|
60
|
+
...
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'normie' do
|
64
|
+
subject(:user) { build(:user, :admin) }
|
65
|
+
|
66
|
+
it { is_expected.not_to have_property_a }
|
67
|
+
...
|
68
|
+
end
|
69
|
+
|
70
|
+
...
|
71
|
+
|
72
|
+
```
|
73
|
+
|
74
|
+
can be re-written as
|
75
|
+
```rb
|
76
|
+
%i[admin normie super_admin another_type].each do |user_type|
|
77
|
+
subject(:user) { build(:user, user_type) }
|
78
|
+
let(:is_an_admin) { %i[admin super_admin].include? user_type }
|
79
|
+
|
80
|
+
it { is_expected.when(is_an_admin).with_inverse.to have_property_a }
|
81
|
+
...
|
82
|
+
end
|
83
|
+
```
|
84
|
+
|
85
|
+
Another common place is when testing page content, again usually user type based.
|
86
|
+
Can very easily combine otherwise repetitive expectations into single tests
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-when
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Bromwich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-expectations
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '2.0'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '5.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '2.0'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '5.0'
|
33
33
|
description:
|
34
34
|
email: a.bromwich@gmail.com
|
35
35
|
executables: []
|
@@ -64,10 +64,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
- !ruby/object:Gem::Version
|
65
65
|
version: '0'
|
66
66
|
requirements: []
|
67
|
-
|
68
|
-
rubygems_version: 2.4.8
|
67
|
+
rubygems_version: 3.0.6
|
69
68
|
signing_key:
|
70
69
|
specification_version: 4
|
71
70
|
summary: RSpec extension for when syntax
|
72
71
|
test_files: []
|
73
|
-
has_rdoc:
|