Skip to content

Commit

Permalink
[rb] more precise implementation of checking for deprecations in specs
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Dec 2, 2019
1 parent 1ed6eb5 commit 136c2e9
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions rb/spec/rspec_matchers.rb
Expand Up @@ -19,13 +19,16 @@

RSpec::Matchers.define :have_deprecated do |deprecation|
match do |actual|
# Not sure how else to capture stdout here
expect {
actual.call
std_out = File.read $stdout if $stdout.is_a?(File)
@deprecations_found = std_out&.scan(/DEPRECATION\] \[:([^\]]*)\]/)&.flatten&.map(&:to_sym)
}.to output.to_stdout_from_any_process
expect(Array(deprecation).sort).to eq(@deprecations_found&.sort)
# Suppresses logging output to stdout while ensuring that it is still happening
default_output = Selenium::WebDriver.logger.io
tempfile = Tempfile.new
Selenium::WebDriver.logger.output = tempfile

actual.call

Selenium::WebDriver.logger.output = default_output
@deprecations_found = (tempfile.rewind && tempfile.read).scan(/DEPRECATION\] \[:([^\]]*)\]/).flatten.map(&:to_sym)
expect(Array(deprecation).sort).to eq(@deprecations_found.sort)
end

failure_message do
Expand Down

0 comments on commit 136c2e9

Please sign in to comment.