From e63f32d801ee47be4f0a9545e23f722b0c970223 Mon Sep 17 00:00:00 2001 From: Grant Hutchins Date: Wed, 30 Oct 2024 10:02:01 -0500 Subject: [PATCH] Replace ostruct dependency with RSpec double There's no need to introduce the ostruct stdlib gem just for this single object while testing. This removes a warning about including a stdlib gem without explicitly depending on it. --- spec/lib/pg_search/features/trigram_spec.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/spec/lib/pg_search/features/trigram_spec.rb b/spec/lib/pg_search/features/trigram_spec.rb index 4dd44eb2..9055901e 100644 --- a/spec/lib/pg_search/features/trigram_spec.rb +++ b/spec/lib/pg_search/features/trigram_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require "spec_helper" -require "ostruct" # standard:disable RSpec/MultipleMemoizedHelpers, RSpec/NestedGroups describe PgSearch::Features::Trigram do @@ -16,7 +15,8 @@ ] } let(:normalizer) { PgSearch::Normalizer.new(config) } - let(:config) { OpenStruct.new(ignore: []) } + let(:config) { instance_double(PgSearch::Configuration, ignore: ignore) } + let(:ignore) { [] } let(:coalesced_columns) do <<~SQL.squish @@ -35,7 +35,6 @@ describe "conditions" do it "escapes the search document and query" do - config.ignore = [] expect(feature.conditions.to_sql).to eq("('#{query}' % (#{coalesced_columns}))") end @@ -45,14 +44,14 @@ end it 'uses the "<%" operator when searching by word_similarity' do - config.ignore = [] expect(feature.conditions.to_sql).to eq("('#{query}' <% (#{coalesced_columns}))") end end context "when ignoring accents" do + let(:ignore) { [:accents] } + it "escapes the search document and query, but not the accent function" do - config.ignore = [:accents] expect(feature.conditions.to_sql).to eq("(unaccent('#{query}') % (unaccent(#{coalesced_columns})))") end end