once-ler 0.1.2 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +13 -0
- data/lib/onceler.rb +7 -0
- data/lib/onceler/basic_helpers.rb +18 -0
- data/lib/onceler/extensions/active_record.rb +16 -4
- data/lib/onceler/recorder.rb +20 -2
- data/lib/onceler/transactions.rb +1 -1
- data/lib/onceler/transactions/{active_record_4.rb → active_record.rb} +0 -0
- metadata +47 -15
- data/lib/onceler/extensions/active_record_4_0.rb +0 -19
- data/lib/onceler/extensions/active_record_4_1.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 994d38083ec48a1954601ccde89242bc6183272d2533aa3f9ac580356bf96d9f
|
4
|
+
data.tar.gz: 9d7205e0a400aa673dc9fbc4f9c84fc47ea4162bb5df3d45d28e7f06bd220acf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b68997b82367df5f4e22ce7e791528b0b85afb2e8ccbd8a9b78b711210cadbccc2662af387fe86fcd558a4116a73f78fb3d4ae83f120c541439113bc673fc701
|
7
|
+
data.tar.gz: fc434921ddb4f6d238e3ec5cdc03a715e51b88e02bf87e5b4918060ceae5372ef6e1920889e69fa4853378b62b03ebdba18b9c7ad6e5be7d2464a91e6f958680
|
data/README.md
CHANGED
@@ -36,6 +36,19 @@ Change a slow `let` (or `let!`) to `let_once` to speed it up.
|
|
36
36
|
|
37
37
|
Change a slow `subject` (or `subject!`) to `subject_once` to speed it up.
|
38
38
|
|
39
|
+
### around(:once) { ... }
|
40
|
+
|
41
|
+
Need to run something around all of your once blocks (like freezing time)?
|
42
|
+
Use this.
|
43
|
+
|
44
|
+
### around(:once_and_each) { ... }
|
45
|
+
|
46
|
+
Shorthand for around(:once) + around(:each). Be careful, as you cannot
|
47
|
+
share state with instance variables between arounds and examples, so
|
48
|
+
use local variables if you want to say freeze time consistently
|
49
|
+
between all before(*) and examples. Also, the block is called twice (once for
|
50
|
+
:once and once for :each), so be careful using, e.g. Time.now in the block.
|
51
|
+
|
39
52
|
## Ambitious usage
|
40
53
|
|
41
54
|
If you're feeling bold, you can automatically speed up all
|
data/lib/onceler.rb
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
require "rspec"
|
2
|
+
require "rubygems"
|
3
|
+
|
2
4
|
require "onceler/basic_helpers"
|
3
5
|
require "onceler/configuration"
|
4
6
|
require "onceler/extensions/active_record"
|
7
|
+
|
5
8
|
if defined?(DatabaseCleaner)
|
9
|
+
unless !DatabaseCleaner.const_defined?("VERSION") ||
|
10
|
+
Gem::Requirement.new(">= 1.7").satisfied_by?(Gem::Version.new(DatabaseCleaner::VERSION))
|
11
|
+
raise "Onceler in only compatible with DatabaseCleaner >= 1.7."
|
12
|
+
end
|
6
13
|
require "onceler/extensions/database_cleaner"
|
7
14
|
end
|
@@ -28,6 +28,11 @@ module Onceler
|
|
28
28
|
alias_method :subject, name if name != :subject
|
29
29
|
end
|
30
30
|
|
31
|
+
def around_once(&block)
|
32
|
+
onceler(:create).add_around(block)
|
33
|
+
add_onceler_hooks!
|
34
|
+
end
|
35
|
+
|
31
36
|
def before_once(&block)
|
32
37
|
onceler(:create) << block
|
33
38
|
add_onceler_hooks!
|
@@ -82,6 +87,19 @@ module Onceler
|
|
82
87
|
end
|
83
88
|
end
|
84
89
|
|
90
|
+
def around(*args, &block)
|
91
|
+
scope = args.first
|
92
|
+
case scope
|
93
|
+
when *once_scopes
|
94
|
+
around_once(&block)
|
95
|
+
when :once_and_each
|
96
|
+
around_once(&block)
|
97
|
+
around(:each, &block)
|
98
|
+
else
|
99
|
+
super(*args, &block)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
85
103
|
def onceler(create_own = false)
|
86
104
|
if create_own
|
87
105
|
@onceler ||= Recorder.new(self)
|
@@ -1,7 +1,19 @@
|
|
1
1
|
require "active_record"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
# monkey-patch this to not clear connections so that we don't lose our
|
4
|
+
# transactions
|
5
|
+
|
6
|
+
module ActiveRecord::TestFixtures
|
7
|
+
def teardown_fixtures
|
8
|
+
# Rollback changes if a transaction is active.
|
9
|
+
if run_in_transaction?
|
10
|
+
@fixture_connections.each do |connection|
|
11
|
+
connection.rollback_transaction if connection.transaction_open?
|
12
|
+
end
|
13
|
+
@fixture_connections.clear
|
14
|
+
else
|
15
|
+
ActiveRecord::FixtureSet.reset_cache
|
16
|
+
end
|
17
|
+
### ONCELER'd
|
18
|
+
end
|
7
19
|
end
|
data/lib/onceler/recorder.rb
CHANGED
@@ -27,6 +27,7 @@ module Onceler
|
|
27
27
|
@group_class = group_class
|
28
28
|
@recordings = []
|
29
29
|
@named_recordings = []
|
30
|
+
@arounds = []
|
30
31
|
end
|
31
32
|
|
32
33
|
def parent_tape
|
@@ -50,6 +51,14 @@ module Onceler
|
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
54
|
+
def add_around(block)
|
55
|
+
@arounds.unshift(block)
|
56
|
+
end
|
57
|
+
|
58
|
+
def arounds
|
59
|
+
(parent ? parent.arounds : []) + @arounds
|
60
|
+
end
|
61
|
+
|
53
62
|
def record!
|
54
63
|
Onceler.recording = true
|
55
64
|
begin_transactions!
|
@@ -63,9 +72,18 @@ module Onceler
|
|
63
72
|
@recordings.each do |recording|
|
64
73
|
recording.prepare_medium!(@tape)
|
65
74
|
end
|
66
|
-
|
67
|
-
|
75
|
+
|
76
|
+
# wrap the before in a lambda
|
77
|
+
stack = -> do
|
78
|
+
@recordings.each do |recording|
|
79
|
+
recording.record_onto!(@tape)
|
80
|
+
end
|
68
81
|
end
|
82
|
+
# and then stack each around block on top
|
83
|
+
arounds.inject(stack) do |old_stack, hook|
|
84
|
+
-> { @tape.instance_exec(old_stack, &hook) }
|
85
|
+
end.call
|
86
|
+
|
69
87
|
run_after_hooks(:record, @tape)
|
70
88
|
@data = @tape.__data
|
71
89
|
ensure
|
data/lib/onceler/transactions.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
require "active_record"
|
2
|
-
require "onceler/transactions/
|
2
|
+
require "onceler/transactions/active_record"
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: once-ler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Jensen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,28 +16,62 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.2'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '6.1'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
29
|
+
version: '5.2'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '6.1'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: rspec
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - ">="
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version: '3.
|
39
|
+
version: '3.6'
|
34
40
|
type: :runtime
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
44
|
- - ">="
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version: '3.
|
46
|
+
version: '3.6'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: appraisal
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.2'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '2.2'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: byebug
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
41
75
|
description: once-ler supercharges your let's and before's with the performance of
|
42
76
|
before(:all)
|
43
77
|
email: jon@instructure.com
|
@@ -52,15 +86,14 @@ files:
|
|
52
86
|
- lib/onceler/basic_helpers.rb
|
53
87
|
- lib/onceler/configuration.rb
|
54
88
|
- lib/onceler/extensions/active_record.rb
|
55
|
-
- lib/onceler/extensions/active_record_4_0.rb
|
56
|
-
- lib/onceler/extensions/active_record_4_1.rb
|
57
89
|
- lib/onceler/extensions/database_cleaner.rb
|
58
90
|
- lib/onceler/recordable.rb
|
59
91
|
- lib/onceler/recorder.rb
|
60
92
|
- lib/onceler/transactions.rb
|
61
|
-
- lib/onceler/transactions/
|
62
|
-
homepage: http://github.com/instructure/
|
63
|
-
licenses:
|
93
|
+
- lib/onceler/transactions/active_record.rb
|
94
|
+
homepage: http://github.com/instructure/once-ler
|
95
|
+
licenses:
|
96
|
+
- MIT
|
64
97
|
metadata: {}
|
65
98
|
post_install_message:
|
66
99
|
rdoc_options: []
|
@@ -70,15 +103,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
103
|
requirements:
|
71
104
|
- - ">="
|
72
105
|
- !ruby/object:Gem::Version
|
73
|
-
version:
|
106
|
+
version: '2.6'
|
74
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
108
|
requirements:
|
76
109
|
- - ">="
|
77
110
|
- !ruby/object:Gem::Version
|
78
|
-
version:
|
111
|
+
version: 2.6.0
|
79
112
|
requirements: []
|
80
|
-
|
81
|
-
rubygems_version: 2.6.11
|
113
|
+
rubygems_version: 3.1.6
|
82
114
|
signing_key:
|
83
115
|
specification_version: 4
|
84
116
|
summary: rspec supercharger
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# monkey-patch this to not clear connections so that we don't lose our
|
2
|
-
# transactions
|
3
|
-
|
4
|
-
module ActiveRecord::TestFixtures
|
5
|
-
def teardown_fixtures
|
6
|
-
return if ActiveRecord::Base.configurations.blank?
|
7
|
-
|
8
|
-
# Rollback changes if a transaction is active.
|
9
|
-
if run_in_transaction?
|
10
|
-
@fixture_connections.each do |connection|
|
11
|
-
connection.rollback_transaction if connection.transaction_open?
|
12
|
-
end
|
13
|
-
@fixture_connections.clear
|
14
|
-
else
|
15
|
-
ActiveRecord::FixtureSet.reset_cache
|
16
|
-
end
|
17
|
-
### ONCELER'd
|
18
|
-
end
|
19
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# monkey-patch this to not clear connections so that we don't lose our
|
2
|
-
# transactions
|
3
|
-
|
4
|
-
module ActiveRecord::TestFixtures
|
5
|
-
def teardown_fixtures
|
6
|
-
# Rollback changes if a transaction is active.
|
7
|
-
if run_in_transaction?
|
8
|
-
@fixture_connections.each do |connection|
|
9
|
-
connection.rollback_transaction if connection.transaction_open?
|
10
|
-
end
|
11
|
-
@fixture_connections.clear
|
12
|
-
else
|
13
|
-
ActiveRecord::FixtureSet.reset_cache
|
14
|
-
end
|
15
|
-
### ONCELER'd
|
16
|
-
end
|
17
|
-
end
|