action-cable-testing 0.1.1 → 0.1.2
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
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1937dec963674b1c524cc2e89fa7e3019861ddc8
|
4
|
+
data.tar.gz: 35c43aacde8ee6c44ce0a0921f4aa8a795e519e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65a6dbcf9d077659e1da92cc5237b01fa7194f5c929a31790f0ae14aad2d66a02a859c4ec16fbaf099ffbb85362f5b4bef62fdff319ddb1ce06845a3d6b0d4e9
|
7
|
+
data.tar.gz: f74589aff6ea7a682c26107687601c0b4efa3555a783e2e01f20edcfefc6cd9d6cadad8506a1481110e4d53e4557461c41a5fa16b32be67678aafd9507a053ca
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -180,6 +180,47 @@ RSpec.describe ChatChannel, type: :channel do
|
|
180
180
|
end
|
181
181
|
```
|
182
182
|
|
183
|
+
#### Shared contexts to switch between adapters
|
184
|
+
|
185
|
+
Sometimes you may want to use _real_ Action Cable adapter instead of the test one (for example, in Capybara-like tests).
|
186
|
+
|
187
|
+
We provide shared contexts to do that:
|
188
|
+
|
189
|
+
```ruby
|
190
|
+
# Use async adapter for this example group only
|
191
|
+
RSpec.describe "cable case", action_cable: :async do
|
192
|
+
# ...
|
193
|
+
|
194
|
+
context "inline cable", action_cable: :inline do
|
195
|
+
# ...
|
196
|
+
end
|
197
|
+
|
198
|
+
# or test adapter
|
199
|
+
context "test cable", action_cable: :test do
|
200
|
+
# ...
|
201
|
+
end
|
202
|
+
|
203
|
+
# you can also include contexts by names
|
204
|
+
context "by name" do
|
205
|
+
include "action_cable:async"
|
206
|
+
# ...
|
207
|
+
end
|
208
|
+
end
|
209
|
+
```
|
210
|
+
|
211
|
+
We also provide an integration for _feature_ specs (having `type: :feature`). Just add `require "action_cable/testing/rspec/features"`:
|
212
|
+
|
213
|
+
```ruby
|
214
|
+
# rails_helper.rb
|
215
|
+
require "action_cable/testing/rspec"
|
216
|
+
require "action_cable/testing/rspec/features"
|
217
|
+
|
218
|
+
# spec/features/my_feature_spec.rb
|
219
|
+
feature "Cables!" do
|
220
|
+
# here we have "action_cable:async" context included automatically!
|
221
|
+
end
|
222
|
+
```
|
223
|
+
|
183
224
|
For more RSpec documentation see https://relishapp.com/palkan/action-cable-testing/docs.
|
184
225
|
|
185
226
|
### Generators
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Generate contexts to use specific Action Cable adapter:
|
4
|
+
# - "action_cable:async" (action_cable: :async)
|
5
|
+
# - "action_cable:inline" (action_cable: :inline)
|
6
|
+
# - "action_cable:test" (action_cabke: :test)
|
7
|
+
%w[async inline test].each do |adapter|
|
8
|
+
RSpec.shared_context "action_cable:#{adapter}" do
|
9
|
+
require "action_cable/subscription_adapter/#{adapter}"
|
10
|
+
|
11
|
+
adapter_class = ActionCable::SubscriptionAdapter.const_get(adapter.capitalize)
|
12
|
+
|
13
|
+
before do
|
14
|
+
next if ActionCable.server.pubsub.is_a?(adapter_class)
|
15
|
+
|
16
|
+
@__was_pubsub_adapter__ = ActionCable.server.pubsub
|
17
|
+
|
18
|
+
adapter = adapter_class.new(ActionCable.server)
|
19
|
+
ActionCable.server.instance_variable_set(:@pubsub, adapter)
|
20
|
+
end
|
21
|
+
|
22
|
+
after do
|
23
|
+
next unless instance_variable_defined?(:@__was_pubsub_adapter__)
|
24
|
+
ActionCable.server.instance_variable_set(:@pubsub, @__was_pubsub_adapter__)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
RSpec.configure do |config|
|
29
|
+
config.include_context "action_cable:#{adapter}", action_cable: adapter.to_sym
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action-cable-testing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actioncable
|
@@ -153,6 +153,7 @@ files:
|
|
153
153
|
- lib/action_cable/test_helper.rb
|
154
154
|
- lib/action_cable/testing.rb
|
155
155
|
- lib/action_cable/testing/rspec.rb
|
156
|
+
- lib/action_cable/testing/rspec/features.rb
|
156
157
|
- lib/action_cable/testing/version.rb
|
157
158
|
- lib/generators/rspec/channel/channel_generator.rb
|
158
159
|
- lib/generators/rspec/channel/templates/channel_spec.rb.erb
|
@@ -160,6 +161,7 @@ files:
|
|
160
161
|
- lib/generators/test_unit/channel/templates/unit_test.rb.erb
|
161
162
|
- lib/rspec/rails/example/channel_example_group.rb
|
162
163
|
- lib/rspec/rails/matchers/action_cable.rb
|
164
|
+
- lib/rspec/rails/shared_contexts/action_cable.rb
|
163
165
|
homepage: http://github.com/palkan/action-cable-testing
|
164
166
|
licenses:
|
165
167
|
- MIT
|