File: functype.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 (71 lines) | stat: -rw-r--r-- 1,574 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
Feature: Fetching contracted function type

  You can use `functype(name)` method for that:

  ```ruby
  functype(:add) # => "add :: Num, Num => Num"
  ```

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

    class Example
      include Contracts::Core

      Contract C::Num, C::Num => C::Num
      def add(a, b)
        a + b
      end

      Contract String => String
      def self.greeting(name)
        "Hello, #{name}"
      end

      class << self
        Contract C::Num => C::Num
        def increment(number)
          number + 1
        end
      end
    end
    """

  Scenario: functype on instance method
    Given a file named "instance_method_functype.rb" with:
    """ruby
    require "./example"
    puts Example.new.functype(:add)
    """
    When I run `ruby instance_method_functype.rb`
    Then the output should contain:
    """
    add :: Num, Num => Num
    """

  Scenario: functype on class method
    Given a file named "class_method_functype.rb" with:
    """ruby
    require "./example"
    puts Example.functype(:greeting)
    """
    When I run `ruby class_method_functype.rb`
    Then the output should contain:
    """
    greeting :: String => String
    """

  Scenario: functype on singleton method
    Given a file named "singleton_method_functype.rb" with:
    """ruby
    require "./example"
    puts Example.functype(:increment)
    """
    When I run `ruby singleton_method_functype.rb`
    Then the output should contain:
    """
    increment :: Num => Num
    """