File: data_table_spec.rb

package info (click to toggle)
ruby-cucumber-core 16.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 764 kB
  • sloc: ruby: 5,074; makefile: 2
file content (63 lines) | stat: -rw-r--r-- 1,904 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# frozen_string_literal: true

require 'cucumber/core/test/data_table'

module Cucumber
  module Core
    module Test
      describe DataTable do
        before do
          @table = described_class.new([
                                         %w[one four seven],
                                         %w[4444 55555 666666]
                                       ])
        end

        describe '#data_table?' do
          let(:table) { described_class.new([[1, 2], [3, 4]]) }

          it 'returns true' do
            expect(table).to be_data_table
          end
        end

        describe '#doc_string' do
          let(:table) { described_class.new([[1, 2], [3, 4]]) }

          it 'returns false' do
            expect(table).not_to be_doc_string
          end
        end

        describe '#map' do
          let(:table) { described_class.new([%w[foo bar], %w[1 2]]) }

          it 'yields the contents of each cell to the block' do
            expect { |b| table.map(&b) }.to yield_successive_args('foo', 'bar', '1', '2')
          end

          it 'returns a new table with the cells modified by the block' do
            expect(table.map { |cell| "*#{cell}*" }).to eq described_class.new([%w[*foo* *bar*], %w[*1* *2*]])
          end
        end

        describe '#transpose' do
          before do
            @table = described_class.new([
                                           %w[one 1111],
                                           %w[two 22222]
                                         ])
          end

          it 'transposes the table' do
            transposed = described_class.new([
                                               %w[one two],
                                               %w[1111 22222]
                                             ])
            expect(@table.transpose).to eq(transposed)
          end
        end
      end
    end
  end
end