File: table.rb

package info (click to toggle)
ruby-rspec-parameterized 0.4.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 148 kB
  • sloc: ruby: 529; makefile: 4
file content (49 lines) | stat: -rw-r--r-- 827 bytes parent folder | download
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
module RSpec
  module Parameterized
    class Table
      attr_reader :last_row

      def initialize
        @rows = []
        @last_row = nil
      end

      def add_row(row)
        unless @rows.find {|r| r.object_id == row.object_id}
          @rows << row
          @last_row = row
        end
        self
      end

      def add_param_to_last_row(param)
        last_row.add_param(param)
        self
      end
      alias :| :add_param_to_last_row

      def to_a
        @rows.map(&:to_a)
      end
      alias :to_params :to_a

      class Row
        def initialize(param)
          @params = [param]
        end

        def add_param(param)
          @params << param
        end

        def to_a
          @params
        end

        def to_params
          [@params]
        end
      end
    end
  end
end