Skip to content

Commit

Permalink
Add channel spec generator
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan authored and benoittgt committed May 15, 2019
1 parent ba28284 commit ac64a6b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/generators/rspec/channel/channel_generator.rb
@@ -0,0 +1,12 @@
require 'generators/rspec'

module Rspec
module Generators
# @private
class ChannelGenerator < Base
def create_channel_spec
template 'channel_spec.rb.erb', File.join('spec/channels', class_path, "#{file_name}_channel_spec.rb")
end
end
end
end
7 changes: 7 additions & 0 deletions lib/generators/rspec/channel/templates/channel_spec.rb.erb
@@ -0,0 +1,7 @@
require 'rails_helper'

<% module_namespacing do -%>
RSpec.describe <%= class_name %>Channel, <%= type_metatag(:channel) %> do
pending "add some examples to (or delete) #{__FILE__}"
end
<% end -%>
17 changes: 17 additions & 0 deletions spec/generators/rspec/channel/channel_generator_spec.rb
@@ -0,0 +1,17 @@
# Generators are not automatically loaded by Rails
require "generators/rspec/channel/channel_generator"
require 'support/generators'

RSpec.describe Rspec::Generators::ChannelGenerator, :type => :generator, :skip => !RSpec::Rails::FeatureCheck.has_action_cable_testing? do
setup_default_destination

describe 'the generated files' do
before { run_generator %w(chat) }

subject { file("spec/channels/chat_channel_spec.rb") }

it { is_expected.to exist }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/describe ChatChannel, #{type_metatag(:channel)}/) }
end
end

0 comments on commit ac64a6b

Please sign in to comment.