Skip to content

Commit

Permalink
Fix failing spec due to deprecation warning
Browse files Browse the repository at this point in the history
silence should return yield. Added new method capture_output to better describe capturing the output.

```
 DEPRECATION WARNING: config.active_support.remove_deprecated_time_with_zone_name is deprecated and will be removed in Rails 7.2. (called from block (2 levels) in <top (required)> at /home/runner/work/flipper/flipper/spec/flipper/engine_spec.rb:32)
 ```
jnunemaker committed Aug 27, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 33153db commit 16988d9
Showing 4 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions spec/flipper/adapters/strict_spec.rb
Original file line number Diff line number Diff line change
@@ -29,13 +29,13 @@

context "#get" do
it "raises an error for unknown feature" do
expect(silence { subject.get(feature) }).to match(/Could not find feature "unknown"/)
expect(capture_output { subject.get(feature) }).to match(/Could not find feature "unknown"/)
end
end

context "#get_multi" do
it "raises an error for unknown feature" do
expect(silence { subject.get_multi([feature]) }).to match(/Could not find feature "unknown"/)
expect(capture_output { subject.get_multi([feature]) }).to match(/Could not find feature "unknown"/)
end
end
end
2 changes: 1 addition & 1 deletion spec/flipper/engine_spec.rb
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@

let(:config) { application.config.flipper }

subject { application.initialize! }
subject { SpecHelpers.silence { application.initialize! } }

shared_examples 'config.strict' do
let(:adapter) { Flipper.adapter.adapter }
2 changes: 1 addition & 1 deletion spec/flipper/middleware/memoizer_spec.rb
Original file line number Diff line number Diff line change
@@ -285,7 +285,7 @@
end

def get(uri, params = {}, env = {}, &block)
silence { super(uri, params, env, &block) }
capture_output { super(uri, params, env, &block) }
end

include_examples 'flipper middleware'
15 changes: 13 additions & 2 deletions spec/support/spec_helpers.rb
Original file line number Diff line number Diff line change
@@ -79,11 +79,22 @@ def silence
original_stdout = $stdout

# Redirect stderr and stdout
output = $stderr = $stdout = StringIO.new
$stderr = $stdout = StringIO.new

yield
ensure
$stderr = original_stderr
$stdout = original_stdout
end

def capture_output
original_stderr = $stderr
original_stdout = $stdout

output = $stdout = $stderr = StringIO.new

yield

# Return output
output.string
ensure
$stderr = original_stderr

0 comments on commit 16988d9

Please sign in to comment.