{"id":15284338,"url":"https://github.com/pdabrowski6/cable-ready-testing","last_synced_at":"2025-04-12T23:21:44.431Z","repository":{"id":59151769,"uuid":"281998844","full_name":"pdabrowski6/cable-ready-testing","owner":"pdabrowski6","description":"Cable Ready testing utils","archived":false,"fork":false,"pushed_at":"2020-07-31T13:26:13.000Z","size":11,"stargazers_count":8,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T01:15:49.983Z","etag":null,"topics":["cableready","rails","rspec","testing"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pdabrowski6.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-23T16:11:40.000Z","updated_at":"2023-04-01T20:27:49.000Z","dependencies_parsed_at":"2022-09-15T13:51:32.932Z","dependency_job_id":null,"html_url":"https://github.com/pdabrowski6/cable-ready-testing","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdabrowski6%2Fcable-ready-testing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdabrowski6%2Fcable-ready-testing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdabrowski6%2Fcable-ready-testing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdabrowski6%2Fcable-ready-testing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pdabrowski6","download_url":"https://codeload.github.com/pdabrowski6/cable-ready-testing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248644181,"owners_count":21138564,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cableready","rails","rspec","testing"],"created_at":"2024-09-30T14:53:37.786Z","updated_at":"2025-04-12T23:21:44.398Z","avatar_url":"https://github.com/pdabrowski6.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e CableReady helps you create great real-time user experiences by making it simple to trigger client-side DOM changes from server-side Ruby.\n\nThis 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.\n\n## 📚 Docs\n\n- [Cable Ready official Documentation](https://cableready.stimulusreflex.com)\n- [Instruction how to install Cable Ready on a Rails application](https://pdabrowski.com/articles/cable-ready-with-action-cable)\n\n## 🚀 Install\n\nOpen `Gemfile` and add the following line to the `test` group:\n\n```sh\ngroup :test do\n  gem 'cable-ready-testing'\nend\n```\n\nnow 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:\n\n```ruby\nrequire 'cable_ready/testing/rspec'\n```\n\nyou are now ready to use the matchers inside your RSpec tests.\n\n## 🎲 Usage\n\nLet's consider the following usage of Cable Ready:\n\n```ruby\nclass Broadcaster\n  include CableReady::Broadcaster\n\n  def call(channel_name, selector)\n    cable_ready[channel_name].outer_html(\n      selector: selector,\n      html: 'html'\n    )\n\n    cable_ready.broadcast\n  end\nend\n```\n\nwithout custom matchers you may end-up with the following test:\n\n```ruby\nRSpec.describe Broadcaster do\n  subject { described_class.new }\n\n  describe '#call' do\n    it 'broadcasts the html' do\n      cable_ready = double(outer_html: double)\n\n      expect(CableReady::Channels.instance)\n        .to receive(:[])\n        .with('custom_channel')\n        .and_return(cable_ready)\n      expect(cable_ready)\n        .to receive(:outer_html)\n        .with(selector: '#some-div', html: 'html')\n      expect(CableReady::Channels.instance)\n        .to receive(:broadcast).once\n\n      subject.call('custom_channel', '#some-div')\n    end\n  end\nend\n```\n\nafter using `cable-ready-testing` gem:\n\n```ruby\nRSpec.describe Broadcaster do\n  subject { described_class.new }\n\n  describe '#call' do\n    it 'broadcasts the html' do\n      expect {\n        subject.call('custom_channel', '#some-div')\n      }.to mutated_element('#some-div')\n       .on_channel('custom_channel')\n       .with(:outer_html, { 'html' =\u003e 'html' })\n    end\n  end\nend\n```\n\n## 📝 Documentation\n\nThe following matchers are available:\n\n* `mudated_element`\n* `mutated_attribute`\n* `mutated_css_class`\n* `mutated_dataset`\n* `mutated_style`\n* `mutated_element`\n\nMentioned 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`.\n\n## 📝 License\n\nCableReady testing lib is released under the [MIT License](LICENSE.txt).\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpdabrowski6%2Fcable-ready-testing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpdabrowski6%2Fcable-ready-testing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpdabrowski6%2Fcable-ready-testing/lists"}