{"id":14991262,"url":"https://github.com/krisleech/wisper-rspec","last_synced_at":"2025-04-06T16:14:54.636Z","repository":{"id":22372944,"uuid":"25709377","full_name":"krisleech/wisper-rspec","owner":"krisleech","description":"RSpec matchers and stubbing for Wisper","archived":false,"fork":false,"pushed_at":"2020-08-07T16:27:03.000Z","size":47,"stargazers_count":63,"open_issues_count":0,"forks_count":17,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-30T15:09:33.112Z","etag":null,"topics":["rspec","ruby","wisper"],"latest_commit_sha":null,"homepage":null,"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/krisleech.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2014-10-24T21:35:53.000Z","updated_at":"2025-02-14T17:58:41.000Z","dependencies_parsed_at":"2022-08-07T10:15:34.994Z","dependency_job_id":null,"html_url":"https://github.com/krisleech/wisper-rspec","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisleech%2Fwisper-rspec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisleech%2Fwisper-rspec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisleech%2Fwisper-rspec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisleech%2Fwisper-rspec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krisleech","download_url":"https://codeload.github.com/krisleech/wisper-rspec/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247509237,"owners_count":20950232,"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":["rspec","ruby","wisper"],"created_at":"2024-09-24T14:22:02.976Z","updated_at":"2025-04-06T16:14:54.597Z","avatar_url":"https://github.com/krisleech.png","language":"Ruby","readme":"# Wisper::Rspec\n\nRspec matcher and stubbing for [Wisper](https://github.com/krisleech/wisper).\n\n[![Gem Version](https://badge.fury.io/rb/wisper-rspec.png)](http://badge.fury.io/rb/wisper-rspec)\n[![Build Status](https://travis-ci.org/krisleech/wisper-rspec.png?branch=master)](https://travis-ci.org/krisleech/wisper-rspec)\n\n## Installation\n\n```ruby\ngem 'wisper-rspec', require: false\n```\n\n## Usage\n\n### Broadcast Matcher\n\nIn `spec_helper`\n\n```ruby\nrequire 'wisper/rspec/matchers'\n\nRSpec::configure do |config|\n  config.include(Wisper::RSpec::BroadcastMatcher)\nend\n```\n\nIn your specs:\n```ruby\nexpect { publisher.execute }.to broadcast(:an_event)\n```\nThis will match both `broadcast(:an_event)` and `broadcast(:an_event, :arg_1)`.\n\n\n```ruby\n# with optional arguments\nexpect { publisher.execute }.to broadcast(:another_event, :arg_1, :arg_2)\n```\n\nWith event arguments, it matches only if the event is broadcast with those arguments. This assertion matches `broadcast(:another_event, :arg_1, :arg_2)` but not `broadcast(:another_event)`.\n\n```ruby\n# with arguments matcher\nexpect { publisher.execute }.to broadcast(:event, hash_including(a: 2))\n```\n\nRspec values matcher can be used to match arguments. This assertion matches `broadcast(:another_event, a: 2, b: 1)` but not `broadcast(:another_event, a: 3)`\n\nMatchers can be composed using [compound rspec matchers](http://www.rubydoc.info/gems/rspec-expectations/RSpec/Matchers/Composable):\n\n```ruby\nexpect {\n  publisher.execute(123)\n  publisher.execute(234)\n}.to broadcast(:event, 123).and broadcast(:event, 234)\n\nexpect {\n  publisher.execute(123)\n  publisher.execute(234)\n}.to broadcast(:event, 123).or broadcast(:event, 234)\n```\n\nNote that the `broadcast` method is aliased as `publish`, similar to the *Wisper* library itself.\n\n### Not broadcast matcher\n\nIf you want to assert a broadcast was not made you can use `not_broadcast` which is especially useful when chaining expectations.\n\n```ruby\nexpect {\n  publisher.execute(123)\n}.to not_broadcast(:event, 99).and broadcast(:event, 123)\n```\n\n### Using message expectations\n\nIf you need to assert on the listener receiving broadcast arguments you can subscribe a double\nwith a [message expectation](https://github.com/rspec/rspec-mocks#message-expectations)\nand then use any of the [argument matchers](https://github.com/rspec/rspec-mocks#argument-matchers).\n\n```ruby\nlistener = double('Listener')\n\nexpect(listener).to receive(:an_event).with(some_args)\n\npublisher.subscribe(listener)\n\npublisher.execute\n```\n\n### Stubbing publishers\n\nYou can stub publishers and their events in unit (isolated) tests that only care about reacting to events.\n\nGiven this piece of code:\n\n```ruby\nclass MyController\n  def create\n    publisher = MyPublisher.new\n\n    publisher.on(:some_event) do |variable|\n      return \"Hello with #{variable}!\"\n    end\n\n    publisher.execute\n  end\nend\n```\n\nYou can test it like this:\n\n```ruby\nrequire 'wisper/rspec/stub_wisper_publisher'\n\ndescribe MyController do\n  context \"on some_event\" do\n    before do\n      stub_wisper_publisher(\"MyPublisher\", :execute, :some_event, \"foo\")\n    end\n\n    it \"renders\" do\n      response = MyController.new.create\n      expect(response).to eq \"Hello with foo!\"\n    end\n  end\nend\n```\n\nThis is useful when testing Rails controllers in isolation from the business logic.\n\nYou can use any number of args to pass to the event:\n\n```ruby\nstub_wisper_publisher(\"MyPublisher\", :execute, :some_event, \"foo1\", \"foo2\", ...)\n```\n\nSee `spec/lib/rspec_extensions_spec.rb` for a runnable example.\n\n\n## Contributing\n\nYes, please.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrisleech%2Fwisper-rspec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrisleech%2Fwisper-rspec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrisleech%2Fwisper-rspec/lists"}