Skip to content

Commit

Permalink
Avoid warnings for calls to ordered on RSpec stubs
Browse files Browse the repository at this point in the history
It's only possible to constrain the order in which calls are made when
using `expect`; not when using `allow`. Indeed you need at least two
calls to `expect` with the `ordered` qualifier to make this work.

The following warning was appearing in the spec output multiple times:

    WARNING: `allow(...).to receive(..).ordered` is not supported and will have no effect, use `and_return(*ordered_values)` instead..

Thus the calls to `ordered` were not having any effect and so I have
removed them.

See the documentation [1] for more info.

[1]: https://relishapp.com/rspec/rspec-mocks/v/3-8/docs/setting-constraints/message-order
  • Loading branch information
floehopper committed Aug 7, 2019
1 parent dc1e798 commit 6e1b143
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions spec/lib/listen/event/loop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
it 'sets up the thread in a resumable state' do
subject.setup

expect(subject).to receive(:sleep).with(no_args).ordered
allow(processor).to receive(:loop_for).with(1.234).ordered
expect(subject).to receive(:sleep).with(no_args)
allow(processor).to receive(:loop_for).with(1.234)

blocks[:thread_block].call
end
Expand All @@ -91,8 +91,8 @@
subject.setup

allow(thread).to receive(:wakeup) do
allow(subject).to receive(:sleep).with(no_args).ordered
allow(processor).to receive(:loop_for).with(1.234).ordered
allow(subject).to receive(:sleep).with(no_args)
allow(processor).to receive(:loop_for).with(1.234)
allow(ready).to receive(:<<).with(:ready)
blocks[:thread_block].call
end
Expand Down Expand Up @@ -153,7 +153,7 @@

subject.setup

allow(subject).to receive(:sleep).with(no_args).ordered do
allow(subject).to receive(:sleep).with(no_args) do
allow(processor).to receive(:loop_for).with(1.234)
blocks[:timer_block].call
end
Expand Down
8 changes: 4 additions & 4 deletions spec/lib/listen/event/processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ def status_for_time(time)
it 'sleeps for latency to possibly later optimize some events' do
# pretend we were woken up at 0.6 seconds since start
allow(config).to receive(:sleep).
with(no_args) { |*_args| state[:time] += 0.6 }.ordered
with(no_args) { |*_args| state[:time] += 0.6 }

# pretend we slept for latency (now: 1.6 seconds since start)
allow(config).to receive(:sleep).
with(1.0) { |*_args| state[:time] += 1.0 }.ordered
with(1.0) { |*_args| state[:time] += 1.0 }

subject.loop_for(1)
end
Expand All @@ -123,14 +123,14 @@ def status_for_time(time)
it 'still does not process events because it is paused' do
# pretend we were woken up at 0.6 seconds since start
allow(config).to receive(:sleep).
with(no_args) { |*_args| state[:time] += 2.0 }.ordered
with(no_args) { |*_args| state[:time] += 2.0 }

# second loop starts here (no sleep, coz recent events, but no
# processing coz paused

# pretend we were woken up at 3.6 seconds since start
allow(config).to receive(:sleep).
with(no_args) { |*_args| state[:time] += 3.0 }.ordered
with(no_args) { |*_args| state[:time] += 3.0 }

subject.loop_for(1)
end
Expand Down

0 comments on commit 6e1b143

Please sign in to comment.