This repository has been archived by the owner on May 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from st0012/require-stop-condition
Support `TappingDevice::Device#stop_when`
- Loading branch information
Showing
4 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module TappingDevice | ||
class Exception < StandardError | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require "spec_helper" | ||
require 'benchmark' | ||
|
||
RSpec.describe TappingDevice::Device do | ||
let(:devices) do | ||
devices = [] | ||
100.times { devices << TappingDevice::Device.new } | ||
devices | ||
end | ||
|
||
after do | ||
devices.each(&:stop!) | ||
end | ||
|
||
context "without stop_when" do | ||
it "takes long time when tapping multiple devices" do | ||
time = Benchmark.realtime do | ||
devices.each do |device| | ||
s = Student.new("foo", 10) | ||
device.tap_on!(s) | ||
10.times { s.name } | ||
|
||
expect(device.calls.count).to eq(10) | ||
end | ||
end | ||
devices.each { |d| d.stop! } | ||
expect(time).to be_between(4, 10) | ||
end | ||
end | ||
|
||
context "with stop_when" do | ||
it "takes very short time when tapping multiple devices" do | ||
time = Benchmark.realtime do | ||
devices.each do |device| | ||
device.stop_when do | ||
device.calls.count == 10 | ||
end | ||
|
||
s = Student.new("foo", 10) | ||
device.tap_on!(s) | ||
10.times { s.name } | ||
|
||
expect(device.calls.count).to eq(10) | ||
end | ||
end | ||
|
||
devices.each { |d| d.stop! } | ||
expect(time).to be_between(0, 1) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters