From 85b820934bfe46650be34396cf94050e8336cc6c Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Sun, 12 Mar 2023 12:52:51 -0400 Subject: [PATCH 1/2] Spec needs to load rspec helper and the unit under test If spec_helper existed, we could have a smaller rspec configuration that did not depend on rails. However, without it, we would need the spec to load the unit under test as well as rspec and its configuration. It seems the pattern is to load rails_helper in all specs in order to configure rspec while also getting rails' autoloading. --- spec/unit/railtie_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/unit/railtie_spec.rb b/spec/unit/railtie_spec.rb index c76f850..991af08 100644 --- a/spec/unit/railtie_spec.rb +++ b/spec/unit/railtie_spec.rb @@ -1,4 +1,5 @@ # TODO: Write proper specs +require "rails_helper" RSpec.describe Graphiti::Rails::Railtie do describe "when rails is defined with logger" do From 1239c8e03a23c948f1bf261a0dbe384371f0b0f4 Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Sun, 12 Mar 2023 13:26:21 -0400 Subject: [PATCH 2/2] Reset Graphiti config between test runs to avoid leaking Rails doubles --- spec/unit/railtie_spec.rb | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/spec/unit/railtie_spec.rb b/spec/unit/railtie_spec.rb index 991af08..6c754f4 100644 --- a/spec/unit/railtie_spec.rb +++ b/spec/unit/railtie_spec.rb @@ -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) @@ -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) @@ -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)