Skip to content

Commit 1c0eb63

Browse files
Extract matcher for slow perf spec
1 parent b173cb8 commit 1c0eb63

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

bundler/spec/realworld/slow_perf_spec.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
gem "mongoid", ">= 0.10.2"
1212
G
1313

14-
start_time = Time.now
15-
16-
bundle "lock"
17-
18-
duration = Time.now - start_time
19-
20-
expect(duration.to_f).to be < 18 # seconds
14+
expect { bundle "lock" }.to take_less_than(18) # seconds
2115
end
2216
end

bundler/spec/support/matchers.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ def self.define_compound_matcher(matcher, preconditions, &declarations)
9797
end
9898
end
9999

100+
RSpec::Matchers.define :take_less_than do |seconds|
101+
match do |actual|
102+
start_time = Time.now
103+
104+
actual.call
105+
106+
(Time.now - start_time).to_f < seconds
107+
end
108+
109+
supports_block_expectations
110+
end
111+
100112
define_compound_matcher :read_as, [exist] do |file_contents|
101113
diffable
102114

0 commit comments

Comments
 (0)