Skip to content

Commit ac64a6b

Browse files
palkanbenoittgt
authored andcommitted
Add channel spec generator
1 parent ba28284 commit ac64a6b

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require 'generators/rspec'
2+
3+
module Rspec
4+
module Generators
5+
# @private
6+
class ChannelGenerator < Base
7+
def create_channel_spec
8+
template 'channel_spec.rb.erb', File.join('spec/channels', class_path, "#{file_name}_channel_spec.rb")
9+
end
10+
end
11+
end
12+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'rails_helper'
2+
3+
<% module_namespacing do -%>
4+
RSpec.describe <%= class_name %>Channel, <%= type_metatag(:channel) %> do
5+
pending "add some examples to (or delete) #{__FILE__}"
6+
end
7+
<% end -%>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generators are not automatically loaded by Rails
2+
require "generators/rspec/channel/channel_generator"
3+
require 'support/generators'
4+
5+
RSpec.describe Rspec::Generators::ChannelGenerator, :type => :generator, :skip => !RSpec::Rails::FeatureCheck.has_action_cable_testing? do
6+
setup_default_destination
7+
8+
describe 'the generated files' do
9+
before { run_generator %w(chat) }
10+
11+
subject { file("spec/channels/chat_channel_spec.rb") }
12+
13+
it { is_expected.to exist }
14+
it { is_expected.to contain(/require 'rails_helper'/) }
15+
it { is_expected.to contain(/describe ChatChannel, #{type_metatag(:channel)}/) }
16+
end
17+
end

0 commit comments

Comments
 (0)