Skip to content

Specs fail because an rspec double is leaking across tests #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 18, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reset Graphiti config between test runs to avoid leaking Rails doubles
  • Loading branch information
jasonkarns committed Mar 12, 2023
commit 1239c8e03a23c948f1bf261a0dbe384371f0b0f4
24 changes: 10 additions & 14 deletions spec/unit/railtie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
require "rails_helper"

RSpec.describe Graphiti::Rails::Railtie do
before do
stub_const("::Rails", rails)
Graphiti.instance_variable_set(:@config, nil)
end

after do
Graphiti.instance_variable_set(:@config, nil)
end

describe "when rails is defined with logger" do
let(:rails) do
logger = OpenStruct.new(level: 1)
Expand All @@ -12,15 +21,6 @@ def logger.debug?
double(root: Pathname.new("/foo/bar"), logger: logger)
end

before do
stub_const("::Rails", rails)
Graphiti.instance_variable_set(:@config, nil)
end

after do
Graphiti.instance_variable_set(:@config, nil)
end

describe "#schema_path" do
it "defaults" do
expect(Graphiti.config.schema_path.to_s)
Expand Down Expand Up @@ -51,11 +51,7 @@ def logger.debug?
end

context "when Rails is defined without logger" do
before do
rails = double(root: Pathname.new("/foo/bar"), logger: double.as_null_object)
stub_const("::Rails", rails)
Graphiti.instance_variable_set(:@config, nil)
end
let(:rails) { stub_const("::Rails", double(root: Pathname.new("/foo/bar"), logger: nil)) }

it "defaults" do
expect(Graphiti.config.schema_path.to_s)
Expand Down