File: output_stream_spec.rb

package info (click to toggle)
ruby-rspec 3.13.0c0e0m0s1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,856 kB
  • sloc: ruby: 70,868; sh: 1,423; makefile: 99
file content (72 lines) | stat: -rw-r--r-- 1,881 bytes parent folder | download | duplicates (3)
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
require 'support/aruba_support'

RSpec.describe 'Output stream' do
  include_context 'aruba support'
  before { setup_aruba }

  context 'when a formatter set in a configure block' do
    it 'writes to the right output stream' do
      write_file_formatted 'spec/example_spec.rb', <<-SPEC
        RSpec.configure do |c|
          c.formatter = :documentation
          c.output_stream = File.open('saved_output', 'w')
        end

        RSpec.describe 'something' do
          it 'succeeds' do
            true
          end
        end
      SPEC

      run_command ''
      expect(last_cmd_stdout).to be_empty
      cd '.' do
        expect(File.read('saved_output')).to include('1 example, 0 failures')
      end
    end

    it 'writes to the right output stream even when its a filename' do
      write_file_formatted 'spec/example_spec.rb', <<-SPEC
        RSpec.configure do |c|
          c.formatter = :documentation
          c.output_stream = 'saved_output'
        end

        RSpec.describe 'something' do
          it 'succeeds' do
            true
          end
        end
      SPEC

      run_command ''
      expect(last_cmd_stdout).to be_empty
      cd '.' do
        expect(File.read('saved_output')).to include('1 example, 0 failures')
      end
    end

    it 'writes to the right output stream even when its a filename' do
      write_file_formatted 'spec/example_spec.rb', <<-SPEC
        require 'pathname'
        RSpec.configure do |c|
          c.formatter = :documentation
          c.output_stream = Pathname.new('saved_output')
        end

        RSpec.describe 'something' do
          it 'succeeds' do
            true
          end
        end
      SPEC

      run_command ''
      expect(last_cmd_stdout).to be_empty
      cd '.' do
        expect(File.read('saved_output')).to include('1 example, 0 failures')
      end
    end
  end
end