rspec_let_cache 0.1.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/MIT-LICENSE +20 -0
- data/README.md +85 -0
- data/Rakefile +13 -0
- data/lib/rspec_let_cache/version.rb +5 -0
- data/lib/rspec_let_cache.rb +37 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6b4ce26af49150f5bcdae369e2111051f1e53e8b43d38b765dd79e2dbc1724c3
|
4
|
+
data.tar.gz: 8e71e98b2d9bacafe489ff6251821c071455184e49a6fe6c21e1518bfefe90b7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3ae418e2b70a335b7eaa71035ee74de0814807d2208526f62535a47e9936068c4d3029773775393fc49f15b8eb6d0757a57899904b37de2c58f09922b156f3ab
|
7
|
+
data.tar.gz: 5eb0fce3abd82c3cbf1a4b1c31f86f3549ba9caf276a5c0f9e4bd0a4342c6e6163c87e1a492e9656bc4ed96465d5d1a577e887e81315bef77ad2ab0a04f59132
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2021
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# RspecLetCache
|
2
|
+
This gem permits to cache rspec test values used/shared across tests and thus, it reduces dramatically the time to run involved tests.
|
3
|
+
|
4
|
+
Results for "features" example:
|
5
|
+

|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
group :test do
|
12
|
+
gem 'rspec_let_cache'
|
13
|
+
end
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
```bash
|
18
|
+
$ bundle install
|
19
|
+
```
|
20
|
+
|
21
|
+
Load dependency to be available in your tests
|
22
|
+
```ruby
|
23
|
+
# spec/spec_helper.rb
|
24
|
+
require 'rspec_let_cache'
|
25
|
+
```
|
26
|
+
|
27
|
+
## Examples
|
28
|
+
### Reusing controller response
|
29
|
+
```ruby
|
30
|
+
describe 'when checking response content', type: :controller do
|
31
|
+
render_views
|
32
|
+
let_cache(:articles_cached) do
|
33
|
+
[Article.create!(title: 'article 1'), Article.create!(title: 'article 2')]
|
34
|
+
end
|
35
|
+
let_cache(:response_cached) do
|
36
|
+
articles_cached
|
37
|
+
get :index
|
38
|
+
response
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'includes first article\'s title' do
|
42
|
+
expect(response_cached.body).to include(articles_cached.first.title)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'includes second article\'s title' do
|
46
|
+
expect(response_cached.body).to include(articles_cached.second.title)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
### Reusing features page content
|
52
|
+
```ruby
|
53
|
+
describe 'index page', type: :feature do
|
54
|
+
let_cache(:articles_cached) do
|
55
|
+
[Article.create!(title: 'article 1'), Article.create!(title: 'article 2')]
|
56
|
+
end
|
57
|
+
let_cache(:page_cached) do
|
58
|
+
articles_cached
|
59
|
+
visit articles_path
|
60
|
+
page
|
61
|
+
end
|
62
|
+
before { allow(page_cached).to receive(:reset!) } # Make capybara page to be reusable
|
63
|
+
|
64
|
+
describe 'when checking page content' do
|
65
|
+
it 'includes first article' do
|
66
|
+
expect(page_cached).to have_content(articles_cached.first.title)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'includes second article' do
|
70
|
+
expect(page_cached).to have_content(articles_cached.second.title)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'includes button to delete' do
|
74
|
+
expect(page_cached).to have_css('#articles_table .edit_button')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
```
|
79
|
+
Note: Articles page is visited just one time.
|
80
|
+
|
81
|
+
## Contributing
|
82
|
+
Contribution directions go here.
|
83
|
+
|
84
|
+
## License
|
85
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rspec_let_cache/version'
|
4
|
+
require 'rspec'
|
5
|
+
module RspecLetCache
|
6
|
+
class RspecLetCacheObj
|
7
|
+
end
|
8
|
+
|
9
|
+
# Permits to cache block results across tests and improve related tests performance
|
10
|
+
# @example
|
11
|
+
# describe "articles index page" do
|
12
|
+
# let_cached(:article_cached) { Article.create!(title: 'sample title') }
|
13
|
+
# let_cached(:page_cached) do
|
14
|
+
# visit articles_path
|
15
|
+
# page
|
16
|
+
# end
|
17
|
+
# before { allow(page_cached).to receive(:reset!) }
|
18
|
+
# it 'includes page title' { expect(page_cached).to have_css('header h1', text: "Articles") }
|
19
|
+
# it 'includes articles' { expect(page_cached).to have_content(article_cached.title) }
|
20
|
+
# it 'includes button to delete article' { expect(page_cached).to have_css('table.articles_table .btn-delete') }
|
21
|
+
# it 'includes button to edit article' { expect(page_cached).to have_css('table.articles_table .btn-edit') }
|
22
|
+
# end
|
23
|
+
def let_cache(attr_name, after_all: nil, &block)
|
24
|
+
var_name = "@#{attr_name}"
|
25
|
+
let(attr_name) do
|
26
|
+
already_saved = RspecLetCacheObj.instance_variable_defined?(var_name)
|
27
|
+
RspecLetCacheObj.instance_variable_set(var_name, instance_exec(&block)) unless already_saved
|
28
|
+
RspecLetCacheObj.instance_variable_get(var_name)
|
29
|
+
end
|
30
|
+
after(:all) { RspecLetCacheObj.instance_variable_get(var_name)&.send(after_all) if after_all }
|
31
|
+
after(:all) { RspecLetCacheObj.remove_instance_variable(var_name) rescue nil } # rubocop:disable Style/RescueModifier
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec.configure do |config|
|
36
|
+
config.extend RspecLetCache
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec_let_cache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Owen Peredo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-09-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Permit to cache let variables across tests
|
28
|
+
email:
|
29
|
+
- owenperedo@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- MIT-LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- lib/rspec_let_cache.rb
|
38
|
+
- lib/rspec_let_cache/version.rb
|
39
|
+
homepage: http://github.com/owen2345/rspec_let_cache
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata:
|
43
|
+
homepage_uri: http://github.com/owen2345/rspec_let_cache
|
44
|
+
source_code_uri: http://github.com/owen2345/rspec_let_cache
|
45
|
+
changelog_uri: http://github.com/owen2345/rspec_let_cache
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubygems_version: 3.1.2
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: Permit to cache let variables across tests
|
65
|
+
test_files: []
|