Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I stub response including nil value? #763

Closed
dtan4 opened this issue Apr 3, 2015 · 3 comments
Closed

How can I stub response including nil value? #763

dtan4 opened this issue Apr 3, 2015 · 3 comments

Comments

@dtan4
Copy link
Contributor

dtan4 commented Apr 3, 2015

Hello,

I'm developing a tool using aws-sdk gem v2, and implmenting tests with stubbed API requests.

I'd like to stub response including nil value, like this:

client = Aws::RDS::Client.new

client.describe_db_parameters(db_parameter_group_name: "hoge").parameters[2]
=> #<struct
 parameter_name="archive_timeout",
 parameter_value="300",
 description= "Timeout seconds for archiving",
 source="system",
 apply_type="dynamic",
 data_type="integer",
 allowed_values="0-2147483647",
 is_modifiable=false,
 minimum_engine_version=nil,
 apply_method=nil>

However, the actual stubbed response is this:

client = Aws::RDS::Client.new(stub_responses: true)
db_parameters = [
  {
    parameter_name: "archive_timeout",
    parameter_value: "300",
    description: "Timeout seconds for archiving",
    source: "system",
    apply_type: "dynamic",
    data_type: "integer",
    allowed_values: "0-214748364",
    is_modifiable: false,
    minimum_engine_version: nil,
    apply_method: nil
  }
]
client.stub_responses(:describe_db_parameters, db_parameters)

client.describe_db_parameters(db_parameter_group_name: "hoge").parameters[0]
=> #<struct
 parameter_name="archive_timeout",
 parameter_value="300",
 description="Timeout seconds for archiving",
 source="system",
 apply_type="dynamic",
 data_type="integer",
 allowed_values="0-214748364",
 is_modifiable=false,
 minimum_engine_version="String",
 apply_method="ApplyMethod">

nil value is converted to another default value by #stub_scalar method.

Is there any way to stub nil-included response?
Thanks.

@trevorrowe
Copy link
Member

It looks like this is a deficiency of the current implementation. I look into a patch so that explicitly given nil values are preserved.

@trevorrowe
Copy link
Member

The fix above should got out with the next release. Thanks for reporting the issue!

@dtan4
Copy link
Contributor Author

dtan4 commented Apr 4, 2015

Thanks for quick resolving 👍 ❗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants