Skip to content

Commit

Permalink
🤖 Fix stub methods to pass tests
Browse files Browse the repository at this point in the history
These tests weren't verifying that we could reach Redis; they were
testing the interface of the `RedisEndpoint#ping` by mocking the
instance.

This commit changes the mocking by avoiding a call to
`Hyrax::RedisEventStore.instance` which was raising a Redis connection
error.

Again, this test is not is redis connecting but "assume we are trying to
connect to redis now demonstrate ping."
  • Loading branch information
jeremyf committed Dec 20, 2023
1 parent f50b3f5 commit 73359b6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions spec/models/redis_endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@
let(:namespace) { 'foobar' }

describe '.options' do
subject { described_class.new namespace: }
subject { described_class.new(namespace:) }

it 'uses the configured application settings' do
expect(subject.options[:namespace]).to eq namespace
end
end

describe '#ping' do
let(:faux_redis_instance) { double(Hyrax::RedisEventStore, ping: 'PONG') }
it 'checks if the service is up' do
allow(Hyrax::RedisEventStore.instance).to receive(:ping).and_return('PONG')
allow(subject).to receive(:redis_instance).and_return(faux_redis_instance)
expect(subject.ping).to be_truthy
end

it 'is false if the service is down' do
allow(Hyrax::RedisEventStore.instance).to receive(:ping).and_raise(RuntimeError)
allow(faux_redis_instance).to receive(:ping).and_raise(RuntimeError)
allow(subject).to receive(:redis_instance).and_return(faux_redis_instance)
expect(subject.ping).to eq false
end
end
Expand Down

0 comments on commit 73359b6

Please sign in to comment.