Giter Site home page Giter Site logo

Comments (5)

remoteweb avatar remoteweb commented on May 25, 2024 1

Thanks for you quick reply and assignment.

Did you expect a subscription to exist without explicitly defining it?

The subscriber get initialised within the RailsEventStore initializer like this

 Rails.configuration.event_store.tap do |store|
        store.subscribe(OnHubCompanyUpdated::SyncCompany.new, to: [HubCompanyUpdated])

        store.subscribe_to_all_events(RailsEventStore::LinkByEventType.new)
        store.subscribe_to_all_events(RailsEventStore::LinkByCorrelationId.new)
        store.subscribe_to_all_events(RailsEventStore::LinkByCausationId.new)
end

I expect the subscriber to exist in my spec and I think it does exist as I have binding.pry inside the matcher and I get this

tes [3] pry(#<RubyEventStore::RSpec::HaveSubscribedToEvents>)>  event_store.subscribers_for(expected.first)

[#<OnHubCompanyUpdated::SyncCompany:0x00000001201f6e88>, ...]

The test is

expect(OnHubCompanyUpdated::SyncCompany).to have_subscribed_to_events(HubCompanyUpdated).in(event_store)

What do you mean by "definition is different than in docs"

If i initialize the subscriber without .new

Rails.configuration.event_store.tap do |store|
        store.subscribe(OnHubCompanyUpdated::SyncCompany, to: [HubCompanyUpdated])
end

the matcher works, and the expectation pass, but in RailsEventStore documentation, the instructions to add a subscriber is like this

event_store.subscribe(OrderNotifier.new, to: [OrderCancelled])

from rails_event_store.

pjurewicz avatar pjurewicz commented on May 25, 2024

Hey @remoteweb, thanks for posting!
I'm not sure if I get it. Did you expect a subscription to exist without explicitly defining it?
What do you mean by "definition is different than in docs"?

from rails_event_store.

pjurewicz avatar pjurewicz commented on May 25, 2024

Thanks, now I get it. Will review this assertion definition soon.

from rails_event_store.

pjurewicz avatar pjurewicz commented on May 25, 2024

Minimal code to reproduce your case:

  it 'got subscribed' do
    event_store.within do
      expect(SyncCompany).to have_subscribed_to_events(HubCompanyUpdated).in(event_store)
    end.subscribe(SyncCompany, to: [HubCompanyUpdated]).call
  end

⬆️ this test passes 🟢

  it 'got subscribed' do
   event_store.within do
     expect(SyncCompany).to have_subscribed_to_events(HubCompanyUpdated).in(event_store)
   end.subscribe(SyncCompany.new, to: [HubCompanyUpdated]).call
 end

⬆️ this one fails 🔴

It is tricky, but I do not consider this as an issue. In the second case, you pass a certain instance of SyncCompany class to subscribe method. To test this subscription properly, you should pass the same instance to the assertion.

  it 'got subscribed' do
    handler = SyncCompany.new
    event_store.within do
      expect(handler).to have_subscribed_to_events(HubCompanyUpdated).in(event_store)
    end.subscribe(handler, to: [HubCompanyUpdated]).call
  end

⬆️ this test passes 🟢

If you don't care about a stateful handler, you should rather pass a class to the subscribe method.
The difference between those two is described in this section of the documentation.

Perhaps the documentation should focus more on stateless subscription handlers, as they are the norm. Thank you for pointing it out.

from rails_event_store.

remoteweb avatar remoteweb commented on May 25, 2024

🙏 Thanks for the time put in to add this great explanation. I was falsely expecting the spec helpers to handle all cases by default and I missed to understand properly all different handler configurations.

from rails_event_store.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.