rspec_let_cache 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -2
- data/lib/rspec_let_cache/version.rb +1 -1
- data/lib/rspec_let_cache.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7732c0d19066e09f21b17a009b1603253c79c0d80f40d1c1ce06e5097f5c6ff9
|
4
|
+
data.tar.gz: 44a80b00339a6475a3fe49719f8ba1c7d35d9e2981e9fa838a3eccdb4bf385b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f7d647f0c2edf089d4f8388d7923070d67f5154706e68203e915c2c3b784d7b5f01731456d18f9dd5d2c37d4bd03065925f3dc6c5d8fef8da87c0bef2c2189c
|
7
|
+
data.tar.gz: a4c1178142ca6771670e24389e1518088f18543f9086d17e274dd86f855486dc784fe6abecd096c7062a58eeb3679ea1582b64ef4b4bcedac2bec64cbcdafdca
|
data/README.md
CHANGED
@@ -24,6 +24,16 @@ Load dependency to be available in your tests
|
|
24
24
|
require 'rspec_let_cache'
|
25
25
|
```
|
26
26
|
|
27
|
+
## Structure
|
28
|
+
```
|
29
|
+
let_cache(<variable_name>){
|
30
|
+
block to calculate value
|
31
|
+
return calculated value
|
32
|
+
}
|
33
|
+
```
|
34
|
+
The first time `variable_name` is called, then the block to calculate value is evaluated and saved as a cache value.
|
35
|
+
The next time the variable is called, then it returns the corresponding cached value.
|
36
|
+
|
27
37
|
## Examples
|
28
38
|
### Reusing controller response
|
29
39
|
```ruby
|
@@ -54,12 +64,13 @@ describe 'index page', type: :feature do
|
|
54
64
|
let_cache(:articles_cached) do
|
55
65
|
[Article.create!(title: 'article 1'), Article.create!(title: 'article 2')]
|
56
66
|
end
|
57
|
-
|
67
|
+
|
68
|
+
# Make capybara page to be reusable by passing feature: true
|
69
|
+
let_cache(:page_cached, feature: true) do
|
58
70
|
articles_cached
|
59
71
|
visit articles_path
|
60
72
|
page
|
61
73
|
end
|
62
|
-
before { allow(page_cached).to receive(:reset!) } # Make capybara page to be reusable
|
63
74
|
|
64
75
|
describe 'when checking page content' do
|
65
76
|
it 'includes first article' do
|
data/lib/rspec_let_cache.rb
CHANGED
@@ -20,13 +20,14 @@ module RspecLetCache
|
|
20
20
|
# it 'includes button to delete article' { expect(page_cached).to have_css('table.articles_table .btn-delete') }
|
21
21
|
# it 'includes button to edit article' { expect(page_cached).to have_css('table.articles_table .btn-edit') }
|
22
22
|
# end
|
23
|
-
def let_cache(attr_name, after_all: nil, &block)
|
23
|
+
def let_cache(attr_name, feature: false, after_all: nil, &block)
|
24
24
|
var_name = "@#{attr_name}"
|
25
25
|
let(attr_name) do
|
26
26
|
already_saved = RspecLetCacheObj.instance_variable_defined?(var_name)
|
27
27
|
RspecLetCacheObj.instance_variable_set(var_name, instance_exec(&block)) unless already_saved
|
28
28
|
RspecLetCacheObj.instance_variable_get(var_name)
|
29
29
|
end
|
30
|
+
before { allow(page).to receive(:reset!) } if feature # Make capybara page to be reusable
|
30
31
|
after(:all) { RspecLetCacheObj.instance_variable_get(var_name)&.send(after_all) if after_all }
|
31
32
|
after(:all) { RspecLetCacheObj.remove_instance_variable(var_name) rescue nil } # rubocop:disable Style/RescueModifier
|
32
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec_let_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Owen Peredo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|