Skip to content

Commit 882f013

Browse files
committed
refactor(image_helper_spec): simplify response stubbing for profile image methods
1 parent fedc926 commit 882f013

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

spec/helpers/better_together/image_helper_spec.rb

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,23 @@
1818

1919
context 'when person has profile_image_url method' do
2020
before do
21-
allow(person).to receive(:respond_to?).with(:profile_image).and_return(true)
22-
allow(person).to receive(:respond_to?).with(:profile_image, anything).and_return(true)
23-
allow(person).to receive(:respond_to?).with(:profile_image_url).and_return(true)
24-
allow(person).to receive(:respond_to?).with(:profile_image_url, anything).and_return(true)
25-
2621
# Mock profile_image.attached? to return true
2722
profile_image_double = double('profile_image', attached?: true) # rubocop:todo RSpec/VerifiedDoubles
28-
allow(person).to receive_messages(respond_to?: false, profile_image_url: 'http://example.com/optimized.jpg',
29-
profile_image: profile_image_double)
23+
allow(person).to receive(:profile_image).and_return(profile_image_double)
24+
25+
# Stub the profile_image_url method to return our test URL
26+
allow(person).to receive(:profile_image_url).and_return('http://example.com/optimized.jpg')
3027
end
3128

3229
it 'uses the optimized profile_image_url method' do
33-
expect(person).to receive(:profile_image_url).with(size: 300)
30+
expect(person).to receive(:profile_image_url).with(size: 300).and_return('http://example.com/optimized.jpg')
3431
result = profile_image_tag(person)
3532
expect(result).to include('src="http://example.com/optimized.jpg"')
3633
expect(result).to include('class="profile-image rounded-circle')
3734
end
3835

3936
it 'respects custom size parameter' do
40-
expect(person).to receive(:profile_image_url).with(size: 150)
37+
expect(person).to receive(:profile_image_url).with(size: 150).and_return('http://example.com/optimized.jpg')
4138
profile_image_tag(person, size: 150)
4239
end
4340
end

0 commit comments

Comments
 (0)