Skip to content

Commit

Permalink
Replace ostruct dependency with RSpec double
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nertzy committed Oct 30, 2024
1 parent 1f88614 commit e63f32d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions spec/lib/pg_search/features/trigram_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require "spec_helper"
require "ostruct"

# standard:disable RSpec/MultipleMemoizedHelpers, RSpec/NestedGroups
describe PgSearch::Features::Trigram do
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down

0 comments on commit e63f32d

Please sign in to comment.