Skip to content

Commit

Permalink
chore: Update readme & changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscz committed Sep 16, 2021
1 parent 2ed194d commit 6713694
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master

## 0.3.0 (2021-09-16)

- Add minitest assertions: `assert_event_published`, `refute_event_published`, `assert_async_event_subscriber_enqueued` ([@chriscz][])

## 0.2.1 (2020-09-30)

- Fix Active Support load hook name. ([@palkan][])
Expand Down
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,32 @@ We suggest putting subscribers to the `app/subscribers` folder using the followi

You can test subscribers as normal Ruby objects.

**NOTE:** Currently, we provide additional matchers only for RSpec. PRs with Minitest support are welcomed!
**NOTE** To test using minitest include the `ActiveEventStore::TestHelpers` module in your tests.

To test that a given subscriber exists, you can use the `have_enqueued_async_subscriber_for` matcher:

```ruby
# for asynchronous subscriptions
# for asynchronous subscriptions (rspec)
it "is subscribed to some event" do
event = MyEvent.new(some: "data")
expect { ActiveEventStore.publish event }
.to have_enqueued_async_subscriber_for(MySubscriberService)
.with(event)
end

# for asynchronous subscriptions (minitest)
def test_is_subscribed_to_some_event
event = MyEvent.new(some: "data")

assert_async_event_subscriber_enqueued(MySubscriberService, event: event) do
ActiveEventStore.publish event
end
end
```

**NOTE** Async event subscribers are queued only after the current transaction has commited so when using `assert_enqued_async_subcriber` in rails
make sure to have `self.use_transactional_fixtures = false` at the top of your test class.

**NOTE:** You must have `rspec-rails` gem in your bundle to use `have_enqueued_async_subscriber_for` matcher.

For synchronous subscribers using `have_received` is enough:
Expand All @@ -182,10 +194,14 @@ end
To test event publishing, use `have_published_event` matcher:

```ruby
# rspec
expect { subject }.to have_published_event(ProfileCreated).with(user_id: user.id)

# minitest
assert_event_published(ProfileCreated, with: { user_id: user.id }) { subject }
```

**NOTE:** `have_published_event` only supports block expectations.
**NOTE:** `have_published_event` and `assert_event_published` only supports block expectations.

**NOTE 2** `with` modifier works like `have_attributes` matcher (not `contain_exactly`); you can only specify serializable attributes in `with` (i.e. sync attributes are not supported, 'cause they are not persistent).

Expand Down

0 comments on commit 6713694

Please sign in to comment.