knapsack_pro 2.1.1 → 2.2.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
2
  SHA256:
3
- metadata.gz: 653a964b0c75547cec30531146adeb0075f251e6bc6511d4d85d710b778cf539
4
- data.tar.gz: 21bb3baafa53c8dcc609d87e8fd8adb2b700df40f3275908968dee74f4186921
3
+ metadata.gz: b399cf5cff114341276acbcc1c9c372ff4bfb51ffc05a5ee5b59cf531dc64feb
4
+ data.tar.gz: aed0dea9791ab8589c63192e53b3f64c2a071f690553bc0d450be61d20b51b1e
5
5
  SHA512:
6
- metadata.gz: a09a6f1318b285910c1db3eb8828a2d79034cfd7a1cf23926995b91b89d68f768bdab003f33ee4fc1480c1431fd22cffe6236bc69413494147bc9d12619ee73e
7
- data.tar.gz: 1aa7010f7a371a8dca1f333a1254261341bfec1143e101dc2e6a717aa0dac43f31f4382050da248bb87a387268bd2ef39eeeb64ed76f348293dd5efafe9607e3
6
+ metadata.gz: d44d7d00c68d618d7ec41b764b28a8bcd7e5f2c62329d7246f2ee760f0d956ce7f1ffbbf6e8fae2adedf3cbd62d83a255f0b89a1dff9c8cc216d42cd11a89603
7
+ data.tar.gz: 403cbc599ff70473aa07ae92abb73016a942c3ed21a2bbcb376ade1e8d0fe62e1ea64677fd6527c5a2b8822bd65fa7c6139ffb6c0850f273b795303974724bab
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ### 2.2.0
4
+
5
+ * Allow defining Queue Mode hooks multiple times (`KnapsackPro::Hooks::Queue.before_queue`, `KnapsackPro::Hooks::Queue.after_subset_queue`, `KnapsackPro::Hooks::Queue.after_queue`)
6
+
7
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/122
8
+
9
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v2.1.1...v2.2.0
10
+
3
11
  ### 2.1.1
4
12
 
5
13
  * Explicitly call root test runner class to avoid a confusing error when test runner gem is not loaded
data/README.md CHANGED
@@ -2737,6 +2737,8 @@ end
2737
2737
 
2738
2738
  #### What hooks are supported in Queue Mode?
2739
2739
 
2740
+ Note: Each hook type can be defined multiple times. For instance, if you define `KnapsackPro::Hooks::Queue.before_queue` twice then both block of code will be called when running your tests.
2741
+
2740
2742
  * RSpec in knapsack_pro Queue Mode supports hooks:
2741
2743
 
2742
2744
  ```ruby
@@ -2,54 +2,63 @@ module KnapsackPro
2
2
  module Hooks
3
3
  class Queue
4
4
  class << self
5
- attr_reader :before_queue,
6
- :after_subset_queue,
7
- :after_queue
5
+ attr_reader :before_queue_store,
6
+ :after_subset_queue_store,
7
+ :after_queue_store
8
8
 
9
9
  def reset_before_queue
10
- @before_queue = nil
10
+ @before_queue_store = nil
11
11
  end
12
12
 
13
13
  def reset_after_subset_queue
14
- @after_subset_queue = nil
14
+ @after_subset_queue_store = nil
15
15
  end
16
16
 
17
17
  def reset_after_queue
18
- @after_queue = nil
18
+ @after_queue_store = nil
19
19
  end
20
20
 
21
21
  def before_queue(&block)
22
- @before_queue ||= block
22
+ @before_queue_store ||= []
23
+ @before_queue_store << block
23
24
  end
24
25
 
25
26
  def after_subset_queue(&block)
26
- @after_subset_queue ||= block
27
+ @after_subset_queue_store ||= []
28
+ @after_subset_queue_store << block
27
29
  end
28
30
 
29
31
  def after_queue(&block)
30
- @after_queue ||= block
32
+ @after_queue_store ||= []
33
+ @after_queue_store << block
31
34
  end
32
35
 
33
36
  def call_before_queue
34
- return unless before_queue
35
- before_queue.call(
36
- KnapsackPro::Config::Env.queue_id
37
- )
37
+ return unless before_queue_store
38
+ before_queue_store.each do |block|
39
+ block.call(
40
+ KnapsackPro::Config::Env.queue_id
41
+ )
42
+ end
38
43
  end
39
44
 
40
45
  def call_after_subset_queue
41
- return unless after_subset_queue
42
- after_subset_queue.call(
43
- KnapsackPro::Config::Env.queue_id,
44
- KnapsackPro::Config::Env.subset_queue_id
45
- )
46
+ return unless after_subset_queue_store
47
+ after_subset_queue_store.each do |block|
48
+ block.call(
49
+ KnapsackPro::Config::Env.queue_id,
50
+ KnapsackPro::Config::Env.subset_queue_id
51
+ )
52
+ end
46
53
  end
47
54
 
48
55
  def call_after_queue
49
- return unless after_queue
50
- after_queue.call(
51
- KnapsackPro::Config::Env.queue_id
52
- )
56
+ return unless after_queue_store
57
+ after_queue_store.each do |block|
58
+ block.call(
59
+ KnapsackPro::Config::Env.queue_id
60
+ )
61
+ end
53
62
  end
54
63
  end
55
64
  end
@@ -1,3 +1,3 @@
1
1
  module KnapsackPro
2
- VERSION = '2.1.1'
2
+ VERSION = '2.2.0'
3
3
  end
@@ -10,18 +10,30 @@ describe KnapsackPro::Hooks::Queue do
10
10
  it { should be_nil }
11
11
  end
12
12
 
13
- context 'when callback is set' do
13
+ context 'when callback is set multiple times' do
14
14
  let(:queue_id) { double }
15
15
 
16
16
  before do
17
- expect(KnapsackPro::Config::Env).to receive(:queue_id).and_return(queue_id)
17
+ expect(KnapsackPro::Config::Env).to receive(:queue_id).twice.and_return(queue_id)
18
18
 
19
+ $expected_called_blocks = []
20
+
21
+ described_class.before_queue do |q_id|
22
+ $expected_called_blocks << [:block_1_called, q_id]
23
+ end
19
24
  described_class.before_queue do |q_id|
20
- [:fake_value, q_id]
25
+ $expected_called_blocks << [:block_2_called, q_id]
21
26
  end
22
27
  end
23
28
 
24
- it { should eq [:fake_value, queue_id] }
29
+ it 'each block is called' do
30
+ subject
31
+
32
+ expect($expected_called_blocks).to eq([
33
+ [:block_1_called, queue_id],
34
+ [:block_2_called, queue_id],
35
+ ])
36
+ end
25
37
  end
26
38
  end
27
39
 
@@ -36,20 +48,32 @@ describe KnapsackPro::Hooks::Queue do
36
48
  it { should be_nil }
37
49
  end
38
50
 
39
- context 'when callback is set' do
51
+ context 'when callback is set multiple times' do
40
52
  let(:queue_id) { double }
41
53
  let(:subset_queue_id) { double }
42
54
 
43
55
  before do
44
- expect(KnapsackPro::Config::Env).to receive(:queue_id).and_return(queue_id)
45
- expect(KnapsackPro::Config::Env).to receive(:subset_queue_id).and_return(subset_queue_id)
56
+ expect(KnapsackPro::Config::Env).to receive(:queue_id).twice.and_return(queue_id)
57
+ expect(KnapsackPro::Config::Env).to receive(:subset_queue_id).twice.and_return(subset_queue_id)
58
+
59
+ $expected_called_blocks = []
46
60
 
47
61
  described_class.after_subset_queue do |q_id, subset_q_id|
48
- [:fake_value, q_id, subset_q_id]
62
+ $expected_called_blocks << [:block_1_called, q_id, subset_q_id]
63
+ end
64
+ described_class.after_subset_queue do |q_id, subset_q_id|
65
+ $expected_called_blocks << [:block_2_called, q_id, subset_q_id]
49
66
  end
50
67
  end
51
68
 
52
- it { should eq [:fake_value, queue_id, subset_queue_id] }
69
+ it 'each block is called' do
70
+ subject
71
+
72
+ expect($expected_called_blocks).to eq([
73
+ [:block_1_called, queue_id, subset_queue_id],
74
+ [:block_2_called, queue_id, subset_queue_id],
75
+ ])
76
+ end
53
77
  end
54
78
  end
55
79
 
@@ -64,18 +88,30 @@ describe KnapsackPro::Hooks::Queue do
64
88
  it { should be_nil }
65
89
  end
66
90
 
67
- context 'when callback is set' do
91
+ context 'when callback is set multiple times' do
68
92
  let(:queue_id) { double }
69
93
 
70
94
  before do
71
- expect(KnapsackPro::Config::Env).to receive(:queue_id).and_return(queue_id)
95
+ expect(KnapsackPro::Config::Env).to receive(:queue_id).twice.and_return(queue_id)
96
+
97
+ $expected_called_blocks = []
72
98
 
73
99
  described_class.after_queue do |q_id|
74
- [:fake_value, q_id]
100
+ $expected_called_blocks << [:block_1_called, q_id]
101
+ end
102
+ described_class.after_queue do |q_id|
103
+ $expected_called_blocks << [:block_2_called, q_id]
75
104
  end
76
105
  end
77
106
 
78
- it { should eq [:fake_value, queue_id] }
107
+ it 'each block is called' do
108
+ subject
109
+
110
+ expect($expected_called_blocks).to eq([
111
+ [:block_1_called, queue_id],
112
+ [:block_2_called, queue_id],
113
+ ])
114
+ end
79
115
  end
80
116
  end
81
117
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knapsack_pro
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ArturT
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-18 00:00:00.000000000 Z
11
+ date: 2020-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake