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: ee444fe922657c8eb469653a92b1e6283d11e5c6
4
- data.tar.gz: 0bb6858c4b1d695ec8d7be341a25eb79c14b71e9
3
+ metadata.gz: 1937dec963674b1c524cc2e89fa7e3019861ddc8
4
+ data.tar.gz: 35c43aacde8ee6c44ce0a0921f4aa8a795e519e9
5
5
  SHA512:
6
- metadata.gz: c1b6af262b55dc1104808a7d81e1d18ce3d3823824c48559f0ec1294099d8d20c92651b2f6ed5a0391638d04529a143b774d910630433304fcafb35584f8f4cd
7
- data.tar.gz: 0a18ff1b692011d9f5880b9934f1c228f2c9aabd4fc6d58d3cd2137eb4de215d953212f3afe1492d10ba785ebf8989ae8a56c8270d5209ef882937829d9514be
6
+ metadata.gz: 65a6dbcf9d077659e1da92cc5237b01fa7194f5c929a31790f0ae14aad2d66a02a859c4ec16fbaf099ffbb85362f5b4bef62fdff319ddb1ce06845a3d6b0d4e9
7
+ data.tar.gz: f74589aff6ea7a682c26107687601c0b4efa3555a783e2e01f20edcfefc6cd9d6cadad8506a1481110e4d53e4557461c41a5fa16b32be67678aafd9507a053ca
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change log
2
2
 
3
+ ## 0.1.2 (2017-11-14) ([@palkan][])
4
+
5
+ - Add RSpec shared contexts to switch between adapters.
6
+
7
+ See https://github.com/palkan/action-cable-testing/issues/4.
8
+
3
9
  ## 0.1.1
4
10
 
5
11
  - Support Rails 5.0.0.1. ([@palkan][])
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
@@ -4,6 +4,7 @@ require "action-cable-testing"
4
4
  require "rspec/rails"
5
5
  require "rspec/rails/example/channel_example_group"
6
6
  require "rspec/rails/matchers/action_cable"
7
+ require "rspec/rails/shared_contexts/action_cable"
7
8
 
8
9
  module RSpec # :nodoc:
9
10
  module Rails
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Use async adapter for features specs by deafault
4
+ RSpec.configure do |config|
5
+ config.include_context "action_cable:async", type: :feature
6
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActionCable
4
4
  module Testing
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
@@ -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.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-06 00:00:00.000000000 Z
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