Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gems/aws-sdk-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Unreleased Changes
------------------

* Issue - Fix response stubbing conflicts with other testing libraries.

3.271.0 (2026-11-19)
------------------

Expand Down
4 changes: 2 additions & 2 deletions gems/aws-sdk-core/lib/aws-sdk-core/client_stubs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def stub_data(operation_name, data = {})
def next_stub(context)
operation_name = context.operation_name.to_sym
stub = @config.stubs_mutex.synchronize do
stubs = @config.stubs[operation_name] || []
stubs = @config[:stubs][operation_name] || []
case stubs.length
when 0 then stub_data(operation_name)
when 1 then stubs.first
Expand All @@ -235,7 +235,7 @@ def next_stub(context)

def apply_stubs(operation_name, stubs)
@config.stubs_mutex.synchronize do
@config.stubs[operation_name.to_sym] = stubs
@config[:stubs][operation_name.to_sym] = stubs
end
end

Expand Down
15 changes: 15 additions & 0 deletions gems/aws-sdk-core/spec/aws/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ module Aws
expect(resp.string).to eq('value')
end

it 'supports response stubbing when Object defines stubs' do
original_stubs = Object.instance_method(:stubs) if
Object.instance_methods(false).include?(:stubs)
Object.send(:define_method, :stubs) do |_stubbed_methods|
raise 'Object#stubs should not be called'
end

client.stub_responses(:example_operation, string: 'value')
expect(client.example_operation.string).to eq('value')
ensure
Object.send(:remove_method, :stubs) if
Object.instance_methods(false).include?(:stubs)
Object.send(:define_method, :stubs, original_stubs) if original_stubs
end

it 'accepts a list of stubs' do
client.stub_responses(:example_operation, [
{ string: 'value-1' },
Expand Down
Loading