Skip to content

Commit

Permalink
Add support for ActionCable::Channel::TestCase
Browse files Browse the repository at this point in the history
  • Loading branch information
tijn committed May 17, 2023
1 parent 1fea1a2 commit d3a1893
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/minitest-spec-rails/init/action_cable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module MiniTestSpecRails
module Init
module ActionCableBehavior
extend ActiveSupport::Concern

included do
class_attribute :_helper_class
register_spec_type(/(Channel)( ?Test)?\z/, self)
register_spec_type(self) { |desc| desc.is_a?(Class) && desc < self }
extend Descriptions
end

module Descriptions
def described_class
determine_default_helper_class(name)
end
end
end
end
end

ActionCable::Channel::TestCase.include MiniTestSpecRails::Init::ActionCableBehavior
3 changes: 3 additions & 0 deletions lib/minitest-spec-rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class Railtie < ::Rails::Railtie
require 'active_support'
require 'minitest-spec-rails/init/active_support'
require 'minitest-spec-rails/parallelize'
ActiveSupport.on_load(:action_cable) do
require 'minitest-spec-rails/init/action_cable'
end
ActiveSupport.on_load(:action_controller) do
require 'minitest-spec-rails/init/action_controller'
require 'minitest-spec-rails/init/action_dispatch'
Expand Down
38 changes: 38 additions & 0 deletions test/cases/action_cable_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'test_helper'

class ModelsChannel < ApplicationCable::Channel; end

class ActionCableChannelTest < MiniTestSpecRails::TestCase
it 'matches spec type for class constants' do
assert_channel_test MiniTest::Spec.spec_type(ApplicationCable::Channel)
assert_channel_test MiniTest::Spec.spec_type(ModelsChannel)
end

it 'matches spec type for strings' do
assert_channel_test MiniTest::Spec.spec_type('WidgetChannel')
assert_channel_test MiniTest::Spec.spec_type('WidgetChannelTest')
assert_channel_test MiniTest::Spec.spec_type('Widget Channel Test')
# And is case sensitive
refute_channel_test MiniTest::Spec.spec_type('widgetcontroller')
refute_channel_test MiniTest::Spec.spec_type('widgetcontrollertest')
refute_channel_test MiniTest::Spec.spec_type('widget controller test')
end

it 'wont match spec type for non space characters' do
refute_channel_test MiniTest::Spec.spec_type("Widget Channel\tTest")
refute_channel_test MiniTest::Spec.spec_type("Widget Channel\rTest")
refute_channel_test MiniTest::Spec.spec_type("Widget Channel\nTest")
refute_channel_test MiniTest::Spec.spec_type("Widget Channel\fTest")
refute_channel_test MiniTest::Spec.spec_type('Widget ChannelXTest')
end

private

def assert_channel_test(actual)
assert_equal ActionCable::Channel::TestCase, actual
end

def refute_channel_test(actual)
refute_equal ActionCable::Channel::TestCase, actual
end
end

0 comments on commit d3a1893

Please sign in to comment.