Sha256: 2cd7b849cfeee2cd260a1749ff1463068408619e91df73b25b98ebfba6c524b4

Contents?: true

Size: 1.34 KB

Versions: 29

Compression:

Stored size: 1.34 KB

Contents

Feature: Bool

  Checks that the argument is a `true` or `false`.

  ```ruby
  Contract String => C::Bool
  ```

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

    class Example
      include Contracts::Core

      Contract String => C::Bool
      def self.strong?(password)
        return if password == ""
        password.length > 22
      end
    end
    """

  Scenario: Accepts `true`
    Given a file named "true.rb" with:
    """ruby
    require "./bool_usage"
    puts Example.strong?("verystrongandLon774gPassword!ForYouHere")
    """
    When I run `ruby true.rb`
    Then output should contain:
    """
    true
    """

  Scenario: Accepts `false`
    Given a file named "false.rb" with:
    """ruby
    require "./bool_usage"
    puts Example.strong?("welcome")
    """
    When I run `ruby false.rb`
    Then output should contain:
    """
    false
    """

  Scenario: Rejects everything else
    Given a file named "nil.rb" with:
    """ruby
    require "./bool_usage"
    puts Example.strong?("")
    """
    When I run `ruby nil.rb`
    Then output should contain:
    """
    : Contract violation for return value: (ReturnContractError)
            Expected: Bool,
            Actual: nil
            Value guarded in: Example::strong?
            With Contract: String => Bool
    """

Version data entries

29 entries across 20 versions & 5 rubygems

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