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)
 ```
  • Loading branch information
jnunemaker committed Aug 27, 2024
1 parent 33153db commit 16988d9
Show file tree
Hide file tree
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
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/flipper/engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion spec/flipper/middleware/memoizer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
15 changes: 13 additions & 2 deletions spec/support/spec_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 16988d9

Please sign in to comment.