action-cable-testing 0.0.5 → 0.0.6

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
  SHA1:
3
- metadata.gz: 4b6269f11a5590fddc954a824bd3af62f7a64e83
4
- data.tar.gz: '079a0c9dbf1507e5238d40085a459649f962131d'
3
+ metadata.gz: c5796425a4e5ab73343b517a89d64d5aa2be0fd6
4
+ data.tar.gz: 58e1d065fbf5038ab793ed22a7d204d1c3c045ef
5
5
  SHA512:
6
- metadata.gz: 98e4529e68c95d98e3ae33c7a8302c4c492cbb8c96dd70cdbe702e9481aadce1fc58d77331e2cd713c5b8a9dcaf2138ac47c291a947542e8d7b6967bad3e13a2
7
- data.tar.gz: f3238297625a5ef0a9dc38fc536d3d07ba19785de42313f199b3a9d67352f8d0e8910b144885fe4593c221982dcb52d19c89cd09e3e8db13ee0680de0d2162a8
6
+ metadata.gz: e5b188a2a39bc37f77a8456ba9e308098210899fbf33686e847d4ddd1b6e7337004c7a1c8e79c8df94e34e5e19fc2f9b0f83ffe03294529320ce612f027c0290
7
+ data.tar.gz: 0dab5c1a7ac3ac23a9bbe61a3701e0a559bd5347e2a4722933f964b66b5935bdcefdf98058262c782d27d197dcfb8e7c605983983ba80f621448f776e1b9bda7
data/.yardopts CHANGED
@@ -1,2 +1,3 @@
1
1
  --exclude /templates/
2
+ --exclude /rspec/
2
3
  --quiet
data/README.md CHANGED
@@ -21,8 +21,6 @@ And then execute:
21
21
 
22
22
  ## Usage
23
23
 
24
- [Documentation](http://www.rubydoc.info/gems/action-cable-testing)
25
-
26
24
  ### Test Adapter and Broadcasting
27
25
 
28
26
  We add `ActionCable::SubscriptionAdapter::Test` (very similar Active Job and Action Mailer tests adapters) and `ActionCable::TestCase` with a couple of matchers to track broadcasting messages in our tests:
@@ -102,7 +100,7 @@ def test_perform_speak
102
100
  perform :speak, message: "Hello, Rails!"
103
101
 
104
102
  # `transmissions` stores messages sent directly to the channel (i.e. with `transmit` method)
105
- assert_equal "Hello, Rails!", transmissions.last["message"]["text"]
103
+ assert_equal "Hello, Rails!", transmissions.last["text"]
106
104
  end
107
105
  ```
108
106
 
@@ -124,6 +122,10 @@ class ChatChannelTest < ActionCable::Channel::TestCase
124
122
  end
125
123
  ```
126
124
 
125
+ ### RSpec Usage
126
+
127
+ For more RSpec documentation see https://relishapp.com/palkan/action-cable-testing/docs.
128
+
127
129
  ### Generators
128
130
 
129
131
  This gem also provides Rails generators:
@@ -131,6 +133,9 @@ This gem also provides Rails generators:
131
133
  ```sh
132
134
  # Generate a channel test case for ChatChannel
133
135
  rails generate test_unit:channel chat
136
+
137
+ # or for RSpec
138
+ rails generate rspec:channel chat
134
139
  ```
135
140
 
136
141
  ## Development
@@ -138,11 +138,12 @@ module ActionCable
138
138
  include ActiveSupport::Testing::ConstantLookup
139
139
  include ActionCable::TestHelper
140
140
 
141
+ CHANNEL_IDENTIFIER = "test_stub"
142
+
141
143
  included do
142
144
  class_attribute :_channel_class
143
145
 
144
146
  attr_reader :subscription
145
- delegate :transmissions, to: :connection
146
147
  delegate :streams, to: :subscription
147
148
 
148
149
  ActiveSupport.run_load_hooks(:action_cable_channel_test_case, self)
@@ -190,7 +191,7 @@ module ActionCable
190
191
 
191
192
  # Subsribe to the channel under test. Optionally pass subscription parameters as a Hash.
192
193
  def subscribe(params = {})
193
- @subscription = self.class.channel_class.new(connection, "test_stub", params.with_indifferent_access)
194
+ @subscription = self.class.channel_class.new(connection, CHANNEL_IDENTIFIER, params.with_indifferent_access)
194
195
  @subscription.singleton_class.include(ChannelStub)
195
196
  @subscription.subscribe_to_channel
196
197
  @subscription
@@ -208,6 +209,12 @@ module ActionCable
208
209
  @connection ||= stub_connection
209
210
  end
210
211
 
212
+ # Returns messages transmitted into channel
213
+ def transmissions
214
+ # Return only directly sent message (via #transmit)
215
+ connection.transmissions.map { |data| data["message"] }.compact
216
+ end
217
+
211
218
  private
212
219
  def check_subscribed!
213
220
  raise "Must be subscribed!" if subscription.nil? || subscription.rejected?
@@ -18,3 +18,5 @@ module ActionCable
18
18
  autoload :Test
19
19
  end
20
20
  end
21
+
22
+ require "action_cable/testing/rspec" if defined?(::RSpec::Rails)
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rspec/rails/example/channel_example_group"
4
+
5
+ module RSpec
6
+ module Rails
7
+ module FeatureCheck
8
+ module_function
9
+ def has_action_cable?
10
+ defined?(::ActionCable)
11
+ end
12
+ end
13
+
14
+ self::DIRECTORY_MAPPINGS[:channel] = %w[spec channels]
15
+ end
16
+ end
17
+
18
+ RSpec.configure do |config|
19
+ if defined?(ActionCable)
20
+ config.include RSpec::Rails::ChannelExampleGroup, type: :channel
21
+ end
22
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActionCable
4
4
  module Testing
5
- VERSION = "0.0.5"
5
+ VERSION = "0.0.6"
6
6
  end
7
7
  end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ module Rails
5
+ # @api public
6
+ # Container module for channel spec functionality. It is only available if
7
+ # ActionCable has been loaded before it.
8
+ module ChannelExampleGroup
9
+ # This blank module is only necessary for YARD processing. It doesn't
10
+ # handle the conditional `defined?` check below very well.
11
+ end
12
+ end
13
+ end
14
+
15
+ if defined?(ActionCable)
16
+ module RSpec
17
+ module Rails
18
+ # Container module for channel spec functionality.
19
+ module ChannelExampleGroup
20
+ extend ActiveSupport::Concern
21
+ include RSpec::Rails::RailsExampleGroup
22
+ include ActionCable::Channel::TestCase::Behavior
23
+
24
+ # Class-level DSL for channel specs.
25
+ module ClassMethods
26
+ # @private
27
+ def channel_class
28
+ described_class
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ 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.0.5
4
+ version: 0.0.6
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-10-22 00:00:00.000000000 Z
11
+ date: 2017-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actioncable
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: cucumber
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.3.5
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.3.5
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -53,7 +67,7 @@ dependencies:
53
67
  - !ruby/object:Gem::Version
54
68
  version: '10.0'
55
69
  - !ruby/object:Gem::Dependency
56
- name: rspec
70
+ name: rspec-rails
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
@@ -66,6 +80,20 @@ dependencies:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
82
  version: '3.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: aruba
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.5.4
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.5.4
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: minitest
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -125,9 +153,11 @@ files:
125
153
  - lib/action_cable/test_case.rb
126
154
  - lib/action_cable/test_helper.rb
127
155
  - lib/action_cable/testing.rb
156
+ - lib/action_cable/testing/rspec.rb
128
157
  - lib/action_cable/testing/version.rb
129
158
  - lib/generators/test_unit/channel/channel_generator.rb
130
159
  - lib/generators/test_unit/channel/templates/unit_test.rb.erb
160
+ - lib/rspec/rails/example/channel_example_group.rb
131
161
  homepage: http://github.com/palkan/action-cable-testing
132
162
  licenses:
133
163
  - MIT