once-ler 0.1.2 → 0.1.3

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
- SHA1:
3
- metadata.gz: 65613dd5474beb96d101223913f52f5ebf2d5009
4
- data.tar.gz: 75e10a5c47a3e5dbfa0bb926e4ce88a9a39c1be8
2
+ SHA256:
3
+ metadata.gz: bbf5b269f941f3229b8458562f4e680a6fb7a252d5af905bd115d2057bc81989
4
+ data.tar.gz: 125edea3d2ae36a6719bd91ad3e88bd026d158afa96dc2c52aef0aa0bba38797
5
5
  SHA512:
6
- metadata.gz: 0e8df6f934edb66a1c47ccb8c7b521d87d893673b89328d586f3bd126b7e1fc6c84bd7a64ee73f4e74c1111f196e7b37ef9460cde0629064cbc7b11fa319d03c
7
- data.tar.gz: e2303a7c869da96c0a3eb58e16abd920a500e6f3eec7320ad808d0c096e7b13232646f745c2530bf003c7601922ea04728ec09caf0b63678d9f62cd6f1616b17
6
+ metadata.gz: 5e874374de2828630f69386fda4ff877e68f944825e703a50cea1fda0d709d25a10b3f5506e356cc0f9ecdbf95176b86d57574ae7025fa426125d1f08aab41c4
7
+ data.tar.gz: fe5d063d27a141f6e43a7ca2992d282ee4480e8f9822d1713166a217f413272ab8b2ba98426508e8eaa6a1b07659acaf3976591a517622beba9eaca9108540ea
data/README.md CHANGED
@@ -36,6 +36,18 @@ 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.
50
+
39
51
  ## Ambitious usage
40
52
 
41
53
  If you're feeling bold, you can automatically speed up all
@@ -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)
@@ -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,10 @@ module Onceler
50
51
  end
51
52
  end
52
53
 
54
+ def add_around(block)
55
+ @arounds.unshift(block)
56
+ end
57
+
53
58
  def record!
54
59
  Onceler.recording = true
55
60
  begin_transactions!
@@ -63,9 +68,18 @@ module Onceler
63
68
  @recordings.each do |recording|
64
69
  recording.prepare_medium!(@tape)
65
70
  end
66
- @recordings.each do |recording|
67
- recording.record_onto!(@tape)
71
+
72
+ # wrap the before in a lambda
73
+ stack = -> do
74
+ @recordings.each do |recording|
75
+ recording.record_onto!(@tape)
76
+ end
68
77
  end
78
+ # and then stack each around block on top
79
+ @arounds.inject(stack) do |old_stack, hook|
80
+ -> { @tape.instance_exec(old_stack, &hook) }
81
+ end.call
82
+
69
83
  run_after_hooks(:record, @tape)
70
84
  @data = @tape.__data
71
85
  ensure
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.2
4
+ version: 0.1.3
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-07-26 00:00:00.000000000 Z
11
+ date: 2018-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: once-ler supercharges your let's and before's with the performance of
42
56
  before(:all)
43
57
  email: jon@instructure.com
@@ -59,7 +73,7 @@ files:
59
73
  - lib/onceler/recorder.rb
60
74
  - lib/onceler/transactions.rb
61
75
  - lib/onceler/transactions/active_record_4.rb
62
- homepage: http://github.com/instructure/onceler
76
+ homepage: http://github.com/instructure/once-ler
63
77
  licenses: []
64
78
  metadata: {}
65
79
  post_install_message:
@@ -78,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
92
  version: 1.3.5
79
93
  requirements: []
80
94
  rubyforge_project:
81
- rubygems_version: 2.6.11
95
+ rubygems_version: 2.7.6
82
96
  signing_key:
83
97
  specification_version: 4
84
98
  summary: rspec supercharger