• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Nu-hin / remote_ruby / 13421563399

19 Feb 2025 08:16PM UTC coverage: 94.253% (+0.8%) from 93.425%
13421563399

push

github

Nu-hin
Refactor StreamSplitter

25 of 25 new or added lines in 1 file covered. (100.0%)

21 existing lines in 3 files now uncovered.

1148 of 1218 relevant lines covered (94.25%)

21.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.06
/spec/remote_ruby/execution_context_spec.rb
1
# frozen_string_literal: true
2

3
require 'tmpdir'
4✔
4

5
describe RemoteRuby::ExecutionContext do
4✔
6
  subject(:execution_context) do
4✔
7
    described_class.new(**params)
32✔
8
  end
9

10
  let(:working_dir) do
4✔
11
    Dir.mktmpdir
32✔
12
  end
13
  let(:base_params) { {} }
16✔
14
  let(:params) do
4✔
15
    {
16
      adapter: RemoteRuby::TmpFileAdapter,
32✔
17
      working_dir: working_dir
18
    }.merge(base_params)
19
  end
20

21
  let(:cache_dir) do
4✔
22
    Dir.mktmpdir
32✔
23
  end
24

25
  after do
4✔
26
    FileUtils.rm_rf(working_dir)
32✔
27
    FileUtils.rm_rf(cache_dir)
32✔
28
  end
29

30
  it 'prints to stdout' do
4✔
31
    s = 'Something'
4✔
32

33
    expect do
4✔
34
      execution_context.execute(s: s) do
4✔
35
        # :nocov:
36
        puts s
37
        # :nocov:
38
      end
39
    end.to output("#{s}\n").to_stdout
40
  end
41

42
  it 'serializes binary data correctly' do
4✔
43
    fname = File.join(__dir__, '../support/test_files/noise.png')
4✔
44
    var = nil
4✔
45

46
    res = execution_context.execute(fname: fname, var: var) do
4✔
UNCOV
47
      var = File.read(fname)
×
UNCOV
48
      var
×
49
    end
50

51
    expect(res).to eq(File.read(fname))
4✔
52
    expect(res).to eq(var)
4✔
53
  end
54

55
  context 'with save_cache' do
4✔
56
    let(:base_params) { { save_cache: true, cache_dir: cache_dir } }
8✔
57

58
    it 'creates cache files' do
4✔
59
      execution_context.execute do
4✔
60
        # :nocov:
61
        0
62
        # :nocov:
63
      end
64

65
      expect(Dir.glob(File.join(cache_dir, '*'))).not_to be_empty
4✔
66
    end
67
  end
68

69
  context 'with use_cache' do
4✔
70
    let(:base_params) do
4✔
71
      { save_cache: true, use_cache: true, cache_dir: cache_dir }
4✔
72
    end
73

74
    let(:caching_context) { described_class.new(**params) }
8✔
75

76
    it 'uses cache' do
4✔
77
      caching_context.execute do
4✔
78
        # :nocov:
79
        10
80
        # :nocov:
81
      end
82

83
      expect(execution_context).to receive(:cache_adapter).and_call_original
4✔
84
      expect(RemoteRuby::CacheAdapter).to receive(:new).and_call_original
4✔
85

86
      res = execution_context.execute do
4✔
87
        # :nocov:
88
        10
89
        # :nocov:
90
      end
91

92
      expect(res).to eq(10)
4✔
93
    end
94
  end
95

96
  context 'when execution context is a local variable' do
4✔
97
    it 'does not serialize it' do
4✔
98
      ec = execution_context
4✔
99

100
      res = ec.execute do
4✔
101
        # :nocov:
102
        defined?(ec)
103
        # :nocov:
104
      end
105

106
      expect(res).to be_falsey
4✔
107
    end
108
  end
109

110
  context 'with Rails flavour' do
4✔
111
    let(:base_params) do
4✔
112
      {
113
        rails: { environment: :production }
4✔
114
      }
115
    end
116

117
    before do
4✔
118
      path = File.join(working_dir, 'config/environment.rb')
4✔
119
      dirname = File.dirname(path)
4✔
120
      Dir.mkdir(dirname)
4✔
121
      File.write(path, "ENV['RAILS_ENV']")
4✔
122
    end
123

124
    it 'includes Rails loading code' do
4✔
125
      res = execution_context.execute do
4✔
126
        # :nocov:
127
        ENV.fetch('RAILS_ENV', nil)
128
        # :nocov:
129
      end
130

131
      expect(res).to eq('production')
4✔
132
    end
133
  end
134

135
  context 'with stream redirection' do
4✔
136
    let(:err_str) { StringIO.new }
12✔
137
    let(:out_str) { StringIO.new }
12✔
138

139
    let(:base_params) do
4✔
140
      {
141
        out_stream: out_str,
8✔
142
        err_stream: err_str
143
      }
144
    end
145

146
    it 'redirects stdout to the specified stream' do
4✔
147
      execution_context.execute do
4✔
148
        # :nocov:
149
        puts 'Hello'
150
        # :nocov:
151
      end
152

153
      expect(out_str.string).to eq("Hello\n")
4✔
154
    end
155

156
    it 'redirects stderr to the specified stream' do
4✔
157
      execution_context.execute do
4✔
158
        # :nocov:
159
        warn 'Error'
160
        # :nocov:
161
      end
162

163
      expect(err_str.string).to eq("Error\n")
4✔
164
    end
165
  end
166
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc