2

I have a project which used wisper https://github.com/krisleech/wisper to provide publisher and subscribers functionalities.

The gem works perfectly under development and production modes. However, when I try to add some tests for them (rake test:integration), the newly added tests refused to work. The publisher (maybe also the listener) in the tests mode stopped working anymore.

Core::Request.subscribe(Listener::Studentlistener, async: true) Core::Request.subscribe(Listener::Tutorlistener, async: true)

I used the sidekiq as a async backend, i used wisper-sidekiq gem to handle the async requests, not sure if this would be the problem? ,puma as the server, MRI ruby 2.0.0

Do I have to a set up something in order for the test to run?

it "Student can get latest status after looking for xxx tutor" do
  post api_v1_students_request_look_for_xxx_tutor_path, 
     { subject: 'nothing' },
     { "AUTHORIZATION" => "xxx"}
  
  expect(response).to be_success

  get api_v1_students_status_path, nil,
    { "AUTHORIZATION" => "xxx"}
  
  expect(response).to be_success
  
  json_response = JSON.parse(response.body)
  
  expect(json_response['state']).to eq('matching')
end

The listener should receive the publishing between these two posts and update the state to be "matching". However, now when I run rspec the test failed because the publisher never publish anything and hence the state is not updated correctly.

Rimian
  • 36,864
  • 16
  • 117
  • 117
FatSheep
  • 21
  • 4
  • can you share your tests, which you have tried? – adamliesko Jul 22 '15 at 21:18
  • Wisper does not operate differently during tests. Could you try without `async` and see if the listeners are called by putting a breakpoint or `raise` in one of the listener methods. – Kris Jul 24 '15 at 08:54
  • I tested with async disabled, but no luck. :(, put break points in the listen also did not pause the program from running – FatSheep Jul 25 '15 at 03:25
  • Try insecting `Wisper::GlobalListeners.listeners` to see if your listeners are subscribed. – Kris Aug 19 '15 at 16:28

1 Answers1

1

Even the authors are relying on some mocking/stubbing in the integrations tests, so that might be the correct way.

class MyCommand
  include Wisper::Publisher

  def execute(be_successful)
    if be_successful
      broadcast('success', 'hello')
    else
      broadcast('failure', 'world')
    end
  end
end

describe Wisper do

  it 'subscribes object to all published events' do
    listener = double('listener')
    expect(listener).to receive(:success).with('hello')

    command = MyCommand.new

    command.subscribe(listener)

    command.execute(true)
  end

https://github.com/krisleech/wisper/blob/master/spec/lib/integration_spec.rb

adamliesko
  • 1,887
  • 1
  • 14
  • 21
  • In my project, the listeners are necessary to receive message from publishers and update the models accordingly, since the listener is not working now, i cannot test the rest of the functions after the listener – FatSheep Jul 23 '15 at 18:06