pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/pdabrowski6/cable-ready-testing

ts.com/assets/github-cf976967feea1e66.css" /> GitHub - pdabrowski6/cable-ready-testing: Cable Ready testing utils · GitHub
Skip to content

pdabrowski6/cable-ready-testing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CableReady helps you create great real-time user experiences by making it simple to trigger client-side DOM changes from server-side Ruby.

This gem makes the testing of your broadcast classes easier by providing custom matchers that will verify that the expected message was broadcasted to the expected channel.

📚 Docs

🚀 Install

Open Gemfile and add the following line to the test group:

group :test do
  gem 'cable-ready-testing'
end

now load the library for RSpec by editing the file spec/rails_helper.rb and loading the gem after initializing the environment with the following line:

require 'cable_ready/testing/rspec'

you are now ready to use the matchers inside your RSpec tests.

🎲 Usage

Let's consider the following usage of Cable Ready:

class Broadcaster
  include CableReady::Broadcaster

  def call(channel_name, selector)
    cable_ready[channel_name].outer_html(
      selector: selector,
      html: 'html'
    )

    cable_ready.broadcast
  end
end

without custom matchers you may end-up with the following test:

RSpec.describe Broadcaster do
  subject { described_class.new }

  describe '#call' do
    it 'broadcasts the html' do
      cable_ready = double(outer_html: double)

      expect(CableReady::Channels.instance)
        .to receive(:[])
        .with('custom_channel')
        .and_return(cable_ready)
      expect(cable_ready)
        .to receive(:outer_html)
        .with(selector: '#some-div', html: 'html')
      expect(CableReady::Channels.instance)
        .to receive(:broadcast).once

      subject.call('custom_channel', '#some-div')
    end
  end
end

after using cable-ready-testing gem:

RSpec.describe Broadcaster do
  subject { described_class.new }

  describe '#call' do
    it 'broadcasts the html' do
      expect {
        subject.call('custom_channel', '#some-div')
      }.to mutated_element('#some-div')
       .on_channel('custom_channel')
       .with(:outer_html, { 'html' => 'html' })
    end
  end
end

📝 Documentation

The following matchers are available:

  • mudated_element
  • mutated_attribute
  • mutated_css_class
  • mutated_dataset
  • mutated_style
  • mutated_element

Mentioned above matchers work the same way, you should choose the right one depending on the context. If you are calling cable_ready["MyChannel"].set_dataset_property then use mutated_dataset matcher, etc. Always chain them with .on_channel and .with.

📝 License

CableReady testing lib is released under the MIT License.

About

Cable Ready testing utils

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy