once-ler 0.1.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 1a4b8b2e50e9181b9287f8e867f79fd42a2bab8b
4
- data.tar.gz: a429cc3bf13a874bad255998e5c96f24e9842275
2
+ SHA256:
3
+ metadata.gz: aea7d75aae3135a7bfa951604502f2a7c4e61658843b61c93b6b97cd4f6b0289
4
+ data.tar.gz: 289277bdf59da70f3068411c8f456f8667b297634cd2e82e42ea1571f7b71f81
5
5
  SHA512:
6
- metadata.gz: 4a34ee33c59b9a26ba33e66083b26b4c05fe9ab27d47283986912a6f91c943076d2a8948296cfe00c18e98f5e8ce94abbb61ee6a5d39e52eca0a94bb05cd9762
7
- data.tar.gz: aed0e70f32d122b7f47b363e6c242d15a72da8814555be1aa137696e8f8534369d5b076cf3aca6f3261df927d6fecfdbaa7cd7d8b27e1041898f0b1217a4e2c9
6
+ metadata.gz: b4ea98d508128b993f078f9896aa65663844da47324f392da226fee9bfb7e8b4ca5556aa529520985b6d2c1e4899bff9d75c377f836c448f2aabe07107d2a2a2
7
+ data.tar.gz: f311f4d33548d2b123de54c49142b15b9c5b7298843e005b5418d8c4f4c2535ae2887f45bc119a342cae7e515cead02f7b082e5e39cd4a5efe96f25809e70472
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)
@@ -13,7 +13,7 @@ module Onceler
13
13
  end
14
14
 
15
15
  def after(scope, &block)
16
- hooks[:before][scope] << block
16
+ hooks[:after][scope] << block
17
17
  end
18
18
 
19
19
  def hooks
@@ -1,7 +1,19 @@
1
1
  require "active_record"
2
2
 
3
- if ActiveRecord::VERSION::STRING >= "4.1."
4
- require "onceler/extensions/active_record_4_1"
5
- else
6
- require "onceler/extensions/active_record_4_0"
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
@@ -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
- @recordings.each do |recording|
67
- recording.record_onto!(@tape)
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
@@ -1,2 +1,2 @@
1
1
  require "active_record"
2
- require "onceler/transactions/active_record_4"
2
+ require "onceler/transactions/active_record"
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: 0.1.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Jensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-17 00:00:00.000000000 Z
11
+ date: 2021-05-12 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: '4.0'
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: '4.0'
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.0'
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.0'
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,14 +86,12 @@ 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/active_record_4.rb
62
- homepage: http://github.com/instructure/onceler
93
+ - lib/onceler/transactions/active_record.rb
94
+ homepage: http://github.com/instructure/once-ler
63
95
  licenses: []
64
96
  metadata: {}
65
97
  post_install_message:
@@ -70,15 +102,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
102
  requirements:
71
103
  - - ">="
72
104
  - !ruby/object:Gem::Version
73
- version: 1.9.3
105
+ version: '2.6'
74
106
  required_rubygems_version: !ruby/object:Gem::Requirement
75
107
  requirements:
76
108
  - - ">="
77
109
  - !ruby/object:Gem::Version
78
- version: 1.3.5
110
+ version: 2.6.0
79
111
  requirements: []
80
- rubyforge_project:
81
- rubygems_version: 2.6.10
112
+ rubygems_version: 3.1.6
82
113
  signing_key:
83
114
  specification_version: 4
84
115
  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