File: num.feature

package info (click to toggle)
ruby-contracts 0.17-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 624 kB
  • sloc: ruby: 3,805; makefile: 4; sh: 2
file content (64 lines) | stat: -rw-r--r-- 1,383 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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"