Skip to content

Commit

Permalink
Change tests to inline output class in the size_from_ioctl context
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Nov 26, 2023
1 parent 7c1caf8 commit 5f25cfa
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions spec/unit/screen_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,6 @@
require "stringio"

RSpec.describe TTY::Screen do
class Output < SimpleDelegator
def winsize
[100, 200]
end

def big_endian?
[1].pack("S") == [1].pack("n")
end

def ioctl(control, buf)
little_endian = "3\x00\xD3\x00\xF2\x04\xCA\x02\x00"
big_endian = "\x003\x00\xD3\x04\xF2\x02\xCA"
buf.replace(big_endian? ? big_endian : little_endian)
0
end
end

let(:output) { Output.new(StringIO.new) }

subject(:screen) { described_class }

describe "#size" do
Expand Down Expand Up @@ -111,6 +92,27 @@ def java_import(*args); end
end

describe "#size_from_ioctl" do
before do
stub_const("Output", Class.new(SimpleDelegator) do
def winsize
[100, 200]
end

def big_endian?
[1].pack("S") == [1].pack("n")
end

def ioctl(_control, buf)
little_endian = "3\x00\xD3\x00\xF2\x04\xCA\x02\x00"
big_endian = "\x003\x00\xD3\x04\xF2\x02\xCA"
buf.replace(big_endian? ? big_endian : little_endian)
0
end
end)
end

let(:output) { Output.new(StringIO.new) }

def replace_streams(*streams)
originals = [$stdout, $stdin, $stderr]
$stdout, $stdin, $stderr = output, output, output
Expand Down

0 comments on commit 5f25cfa

Please sign in to comment.