Sha256: 3c330c87aaa732ecbaeb4b2e5f001dc6d6dc26e76312c6604fffe444cfb335f4
Contents?: true
Size: 1.32 KB
Versions: 2
Compression:
Stored size: 1.32 KB
Contents
require "active_support" require "active_support/test_case" class StimulusReflex::TestCase < ActiveSupport::TestCase class TestChannel < ActionCable::Channel::TestCase delegate :env, to: :connection def initialize(connection_opts = {}) super("StimulusReflex::Channel") @connection = stub_connection(connection_opts.merge(env: {})) end def stream_name ids = connection.identifiers.map { |identifier| connection.send(identifier).try(:id) || connection.send(identifier) } [ "StimulusReflex::Channel", ids.select(&:present?).join(";") ].select(&:present?).join(":") end end module Behavior extend ActiveSupport::Concern module ClassMethods def reflex_class end end def build_reflex(opts = {}) channel = opts.fetch(:channel, TestChannel.new(opts.fetch(:connection, {}))) element = opts.fetch(:element, StimulusReflex::Element.new) self.class.reflex_class.new( channel, element: element, url: opts.dig(:url), method_name: opts.dig(:method_name), params: opts.fetch(:params, {}) ) end end include Behavior rescue NameError => e if e.missing_name == "ActionCable::Channel::TestCase" raise "Please install action-cable-testing https://github.com/palkan/action-cable-testing" else raise end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
stimulus_reflex_testing-0.2.1 | lib/stimulus_reflex/test_case.rb |
stimulus_reflex_testing-0.2.0 | lib/stimulus_reflex/test_case.rb |