Class: Tuile::FakeScreen

Inherits:
Screen
  • Object
show all
Defined in:
lib/tuile/fake_screen.rb

Overview

Testing only — a screen which doesn’t paint anything and pretends that the lock is held. This way, the TTY running the tests is not painted over.

Intended for unit-testing individual components: instantiate a component, mutate it, and assert against #prints or #invalidated?. It does not run an event loop, so it is not suitable for system-testing whole apps — for that, drive the real script through a PTY (see ‘spec/examples/`).

Call Screen.fake to initialize the fake screen easily. Typical usage:

before { Screen.fake }
after  { Screen.close }

it "paints its content" do
  label = Component::Label.new.tap { |l| l.text = "hi" }
  Screen.instance.content = Component::Window.new("Greeting").tap { |w| w.content = label }
  Screen.instance.repaint
  assert_includes Screen.instance.prints.join, "hi"
end

Instance Attribute Summary collapse

Attributes inherited from Screen

#event_queue, #focused, #on_error, #pane, #size

Instance Method Summary collapse

Methods inherited from Screen

#active_window, #add_popup, #close, close, #content, #content=, #cursor_position, fake, #has_popup?, instance, #invalidate, #popups, #remove_popup, #repaint, #run_event_loop

Constructor Details

#initializeFakeScreen

Returns a new instance of FakeScreen.



24
25
26
27
28
29
# File 'lib/tuile/fake_screen.rb', line 24

def initialize
  super
  @event_queue = FakeEventQueue.new
  @size = Size.new(160, 50)
  @prints = []
end

Instance Attribute Details

#printsArray<String> (readonly)

Returns whatever #print printed so far.

Returns:

  • (Array<String>)

    whatever #print printed so far.



32
33
34
# File 'lib/tuile/fake_screen.rb', line 32

def prints
  @prints
end

Instance Method Details

#check_lockedvoid

This method returns an undefined value.



35
# File 'lib/tuile/fake_screen.rb', line 35

def check_locked; end

#clearvoid

This method returns an undefined value.



38
39
40
# File 'lib/tuile/fake_screen.rb', line 38

def clear
  @prints.clear
end

#invalidated?(component) ⇒ Boolean

Parameters:

  • component (Component)

    the component to check.

Returns:

  • (Boolean)


51
# File 'lib/tuile/fake_screen.rb', line 51

def invalidated?(component) = @invalidated.include?(component)

#invalidated_clearvoid

This method returns an undefined value.



54
55
56
# File 'lib/tuile/fake_screen.rb', line 54

def invalidated_clear
  @invalidated.clear
end

This method returns an undefined value.

Doesn’t print anything: collects all strings in #prints.

Parameters:

  • args (String)


45
46
47
# File 'lib/tuile/fake_screen.rb', line 45

def print(*args)
  @prints += args
end