rspec_let_cache 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b4ce26af49150f5bcdae369e2111051f1e53e8b43d38b765dd79e2dbc1724c3
4
- data.tar.gz: 8e71e98b2d9bacafe489ff6251821c071455184e49a6fe6c21e1518bfefe90b7
3
+ metadata.gz: 7732c0d19066e09f21b17a009b1603253c79c0d80f40d1c1ce06e5097f5c6ff9
4
+ data.tar.gz: 44a80b00339a6475a3fe49719f8ba1c7d35d9e2981e9fa838a3eccdb4bf385b8
5
5
  SHA512:
6
- metadata.gz: 3ae418e2b70a335b7eaa71035ee74de0814807d2208526f62535a47e9936068c4d3029773775393fc49f15b8eb6d0757a57899904b37de2c58f09922b156f3ab
7
- data.tar.gz: 5eb0fce3abd82c3cbf1a4b1c31f86f3549ba9caf276a5c0f9e4bd0a4342c6e6163c87e1a492e9656bc4ed96465d5d1a577e887e81315bef77ad2ab0a04f59132
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
- let_cache(:page_cached) do
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RspecLetCache
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
@@ -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.0
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: 2021-09-13 00:00:00.000000000 Z
11
+ date: 2022-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec