Skip to content

Conversation

@kyeah
Copy link
Contributor

@kyeah kyeah commented May 22, 2017

👋

When passing in multiple fields to a single attr_x_with_contract call, the current implementation only applies the contract for the first field.

class Thinger
  include Contracts
  include Contracts::Attrs

  attr_accessor_with_contract :a, :b, :c, String
end
[development] » t = Thinger.new
» #<Test:0x007f934f552dc0>
[development] » t.c
» nil
[development] » t.b
» nil
[development] » t.a
ReturnContractError: Contract violation for return value:
Expected: String,
        Actual: nil
        Value guarded in: Test::a

This applies the contract and attr_reader individually to each field.

Copy link
Owner

@egonSchiele egonSchiele left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! Could you fix the rubocop issue? I will merge after that.


it "getting invalid type for second val" do
expect { Person.new(1.3).name_r_2 }
.to(raise_error(ReturnContractError))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rubocop expects this to be indented two spaces: https://travis-ci.org/egonSchiele/contracts.ruby/jobs/234892156

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 7721271 👍

@kyeah
Copy link
Contributor Author

kyeah commented May 23, 2017

Opened #260 due to the failing 1.9.2 ci check.

@kyeah kyeah force-pushed the multi-attr-fix branch from 7721271 to 5610e4f Compare May 23, 2017 18:22
@egonSchiele egonSchiele merged commit 2bd5c3b into egonSchiele:master May 23, 2017
@egonSchiele
Copy link
Owner

Thank you!

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

Successfully merging this pull request may close these issues.

2 participants