Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Verify buggy dispatch tests #312

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/volt/tasks/dispatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,23 @@ def dispatch_in_thread(channel, message)
promise.then do |result|
reply = EJSON.stringify(['response', callback_id, result, nil, cookies])
channel.send_string_message(reply)
# NOTE: On success the method #send_string_message is called above.
# In some specs the method #send_message is stubbed instead.
# Because this is within a promise the RSpec error is trapped and the
# fail block below is called. This results in green tests that should be red.

finish.call
end.fail do |error|
# NOTE: This next chunk of code should dump to the CI output when the above
# situation triggers. It's what would normally cause the tests to fail.
if error.is_a? RSpec::Mocks::MockExpectationError
puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!"
p error.class
p error
pp error.backtrace
puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!"
end

finish.call(error)
# Convert the error into a string so it can be serialized.
error_str = "#{error.class.to_s}: #{error.to_s}"
Expand Down
10 changes: 10 additions & 0 deletions spec/tasks/dispatcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ def post(*args)
it 'should log an info message before and after the dispatch' do
channel = double('channel')

# NOTE: This method stub is incorrect. We should be stubbing #send_string_message
# See line 150 in lib/volt/tasks/dispatcher.rb
allow(channel).to receive(:send_message).with('response', 0, 'yes it works', nil)

# NOTE: This is what I think the stub needs to be.
#allow(channel).to receive(:send_string_message).with(any_args)
expect(Volt.logger).to receive(:log_dispatch)

dispatcher.dispatch(channel, [0, 'TestTask', :allowed_method, {}, ' it', ' works'])
Expand All @@ -76,7 +81,12 @@ def post(*args)
it 'should let you set a cookie' do
channel = double('channel')

# NOTE: This method stub is incorrect. We should be stubbing #send_string_message
# See line 150 in lib/volt/tasks/dispatcher.rb
allow(channel).to receive(:send_message).with('response', 0, 'yes it works', {something:"awesome"})

# NOTE: This is what I think the stub needs to be.
#allow(channel).to receive(:send_string_message).with(any_args)
expect(Volt.logger).to receive(:log_dispatch)

dispatcher.dispatch(channel, [0, 'TestTask', :set_cookie, {}])
Expand Down