Sha256: c98e32ff7bda3499fef86a9965ce0cca59b58a5d213692aaed777840fca1005e

Contents?: true

Size: 1.18 KB

Versions: 4

Compression:

Stored size: 1.18 KB

Contents

class GenericExample
  Contract C::Args[String], { repeat: C::Maybe[C::Num] } => C::ArrayOf[String]
  def splat_then_optional_named(*vals, repeat: 2)
    vals.map { |v| v * repeat }
  end

  Contract ({foo: C::Nat}) => nil
  def nat_test_with_kwarg(foo: 10)
  end
end

RSpec.describe "Contracts:" do
  before :all do
    @o = GenericExample.new
  end

  describe "Optional named arguments" do
    it "should work with optional named argument unfilled after splat" do
      expect { @o.splat_then_optional_named("hello", "world") }.to_not raise_error
    end

    it "should work with optional named argument filled after splat" do
      expect { @o.splat_then_optional_named("hello", "world", repeat: 3) }.to_not raise_error
    end
  end

  describe "Nat:" do
    it "should pass for keyword args with correct arg given" do
      expect { @o.nat_test_with_kwarg(foo: 10) }.to_not raise_error
    end

    it "should fail with a ContractError for wrong keyword args input" do
      expect { @o.nat_test_with_kwarg(foo: -10) }.to raise_error(ContractError)
    end

    it "should fail with a ContractError for no input" do
      expect { @o.nat_test_with_kwarg }.to raise_error(ContractError)
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/contracts-0.13.0/spec/ruby_version_specific/contracts_spec_2.0.rb
contracts-0.13.0 spec/ruby_version_specific/contracts_spec_2.0.rb
contracts-0.12.0 spec/ruby_version_specific/contracts_spec_2.0.rb
contracts-0.11.0 spec/ruby_version_specific/contracts_spec_2.0.rb