-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for ActionCable::Channel::TestCase
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |