Sha256: a0ad87b9e860027815ed3754bd74ad276946722ae9f189ca473396caca1cd748

Contents?: true

Size: 1.35 KB

Versions: 29

Compression:

Stored size: 1.35 KB

Contents

Feature: Num

  Checks that an argument is `Numeric`.

  ```ruby
  Contract C::Num => C::Num
  ```

  Background:
    Given a file named "num_usage.rb" with:
    """ruby
    require "contracts"
    C = Contracts

    class Example
      include Contracts::Core

      Contract C::Num => C::Num
      def increase(number)
        number + 1
      end
    end
    """

  Scenario: Accepts integers
    Given a file named "accepts_integers.rb" with:
    """ruby
    require "./num_usage"
    puts Example.new.increase(7)
    """
    When I run `ruby accepts_integers.rb`
    Then output should contain:
    """
    8
    """

  Scenario: Accepts floats
    Given a file named "accepts_floats.rb" with:
    """ruby
    require "./num_usage"
    puts Example.new.increase(7.5)
    """
    When I run `ruby accepts_floats.rb`
    Then output should contain:
    """
    8.5
    """

  Scenario: Rejects other values
    Given a file named "rejects_others.rb" with:
    """ruby
    require "./num_usage"
    puts Example.new.increase("foo")
    """
    When I run `ruby rejects_others.rb`
    Then output should contain:
    """
    : Contract violation for argument 1 of 1: (ParamContractError)
            Expected: Num,
            Actual: "foo"
            Value guarded in: Example::increase
            With Contract: Num => Num
    """
    And output should contain "num_usage.rb:8"

Version data entries

29 entries across 20 versions & 5 rubygems

Version Path
contracts-0.17.2 features/builtin_contracts/num.feature
contracts-0.17.1 features/builtin_contracts/num.feature
entitlements-app-1.1.0 lib/contracts-ruby2/features/builtin_contracts/num.feature
entitlements-app-1.1.0 lib/contracts-ruby3/features/builtin_contracts/num.feature
entitlements-app-1.0.0 lib/contracts-ruby3/features/builtin_contracts/num.feature
entitlements-app-1.0.0 lib/contracts-ruby2/features/builtin_contracts/num.feature
entitlements-app-0.3.4 lib/contracts-ruby3/features/builtin_contracts/num.feature
entitlements-app-0.3.4 lib/contracts-ruby2/features/builtin_contracts/num.feature
entitlements-app-0.3.1 lib/contracts-ruby3/features/builtin_contracts/num.feature
entitlements-app-0.3.1 lib/contracts-ruby2/features/builtin_contracts/num.feature
entitlements-app-0.3.0 lib/contracts-ruby3/features/builtin_contracts/num.feature
entitlements-app-0.3.0 lib/contracts-ruby2/features/builtin_contracts/num.feature
entitlements-0.2.1 lib/contracts-ruby3/features/builtin_contracts/num.feature
entitlements-0.2.1 lib/contracts-ruby2/features/builtin_contracts/num.feature
entitlements-app-0.2.1 lib/contracts-ruby2/features/builtin_contracts/num.feature
entitlements-app-0.2.1 lib/contracts-ruby3/features/builtin_contracts/num.feature
entitlements-0.2.0 lib/contracts-ruby3/features/builtin_contracts/num.feature
entitlements-0.2.0 lib/contracts-ruby2/features/builtin_contracts/num.feature
entitlements-app-0.2.0 lib/contracts-ruby3/features/builtin_contracts/num.feature
entitlements-app-0.2.0 lib/contracts-ruby2/features/builtin_contracts/num.feature