egonSchiele / contracts.ruby

Contracts for Ruby.
http://egonschiele.github.com/contracts.ruby
BSD 2-Clause "Simplified" License
1.44k stars 82 forks source link

Apply contracts to each name for multi-attribute calls #259

Closed kyeah closed 7 years ago

kyeah commented 7 years ago

:wave:

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.

kyeah commented 7 years ago

Opened #260 due to the failing 1.9.2 ci check.

egonSchiele commented 7 years ago

Thank you!