Skip to content

Commit 12e755a

Browse files
authored
Merge pull request #247 from Earlopain/benchmark-specs
Don't skip specs when benchmark is not available
2 parents 791417c + 7b8bffc commit 12e755a

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ gem "stackprof"
1111
gem "standard"
1212
gem "ruby-prof"
1313

14+
gem "benchmark"
1415
gem "benchmark-ips"
1516

1617
case ENV["PRISM_VERSION"]&.strip&.downcase

spec/integration/syntax_suggest_spec.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44

55
module SyntaxSuggest
66
RSpec.describe "Integration tests that don't spawn a process (like using the cli)" do
7-
before(:each) do
8-
skip "Benchmark is not available" unless defined?(::Benchmark)
9-
end
10-
117
it "does not timeout on massive files" do
128
next unless ENV["SYNTAX_SUGGEST_TIMEOUT"]
139

@@ -17,7 +13,7 @@ module SyntaxSuggest
1713

1814
io = StringIO.new
1915

20-
benchmark = Benchmark.measure do
16+
benchmark_measure do
2117
debug_perf do
2218
SyntaxSuggest.call(
2319
io: io,
@@ -28,7 +24,6 @@ module SyntaxSuggest
2824
end
2925

3026
debug_display(io.string)
31-
debug_display(benchmark)
3227

3328
expect(io.string).to include(<<~EOM)
3429
6 class SyntaxTree < Ripper
@@ -46,15 +41,14 @@ module SyntaxSuggest
4641
io = StringIO.new
4742

4843
debug_perf do
49-
benchmark = Benchmark.measure do
44+
benchmark_measure do
5045
SyntaxSuggest.call(
5146
io: io,
5247
source: file.read,
5348
filename: file
5449
)
5550
end
5651
debug_display(io.string)
57-
debug_display(benchmark)
5852
end
5953

6054
expect(io.string).to_not include("def ruby_install_binstub_path")

spec/spec_helper.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ def debug_perf
8585
end
8686
end
8787

88+
def benchmark_measure
89+
raise "No block given" unless block_given?
90+
91+
if defined?(::Benchmark)
92+
debug_display(Benchmark.measure { yield })
93+
else
94+
yield
95+
end
96+
end
97+
8898
def run!(cmd, raise_on_nonzero_exit: true)
8999
out = `#{cmd} 2>&1`
90100
raise "Command: #{cmd} failed: #{out}" if !$?.success? && raise_on_nonzero_exit

0 commit comments

Comments
 (0)