File: neg.feature

package info (click to toggle)
ruby-contracts 0.17-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 624 kB
  • sloc: ruby: 3,805; makefile: 4; sh: 2
file content (115 lines) | stat: -rw-r--r-- 3,065 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
Feature: Neg

  Checks that an argument is negative `Numeric`.

  ```ruby
  Contract C::Neg => C::Neg
  ```

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

    class Example
      include Contracts::Core

      Contract C::Neg => C::Neg
      def double_expense(amount)
        amount * 2
      end
    end
    """

  Scenario: Accepts negative integers
    Given a file named "accepts_negative_integers.rb" with:
    """ruby
    require "./pos_usage"
    puts Example.new.double_expense(-50)
    """
    When I run `ruby accepts_negative_integers.rb`
    Then output should contain:
    """
    -100
    """

  Scenario: Accepts negative floats
    Given a file named "accepts_negative_floats.rb" with:
    """ruby
    require "./pos_usage"
    puts Example.new.double_expense(-37.99)
    """
    When I run `ruby accepts_negative_floats.rb`
    Then output should contain:
    """
    -75.98
    """

  Scenario: Rejects positive integers
    Given a file named "rejects_positive_integers.rb" with:
    """ruby
    require "./pos_usage"
    puts Example.new.double_expense(50)
    """
    When I run `ruby rejects_positive_integers.rb`
    Then output should contain:
    """
    : Contract violation for argument 1 of 1: (ParamContractError)
            Expected: Neg,
            Actual: 50
            Value guarded in: Example::double_expense
            With Contract: Neg => Neg
    """
    And output should contain "pos_usage.rb:8"

  Scenario: Rejects positive floats
    Given a file named "rejects_positive_floats.rb" with:
    """ruby
    require "./pos_usage"
    puts Example.new.double_expense(42.50)
    """
    When I run `ruby rejects_positive_floats.rb`
    Then output should contain:
    """
    : Contract violation for argument 1 of 1: (ParamContractError)
            Expected: Neg,
            Actual: 42.5
            Value guarded in: Example::double_expense
            With Contract: Neg => Neg
    """
    And output should contain "pos_usage.rb:8"

  Scenario: Rejects zero
    Given a file named "rejects_zero.rb" with:
    """ruby
    require "./pos_usage"
    puts Example.new.double_expense(0)
    """
    When I run `ruby rejects_zero.rb`
    Then output should contain:
    """
    : Contract violation for argument 1 of 1: (ParamContractError)
            Expected: Neg,
            Actual: 0
            Value guarded in: Example::double_expense
            With Contract: Neg => Neg
    """
    And output should contain "pos_usage.rb:8"

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