Class: Tuile::FakeScreen
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
- #prints ⇒ Array<String> readonly
Attributes inherited from Screen
#buffer, #event_queue, #focused, #on_error, #pane, #size, #theme, #theme_def
Instance Method Summary collapse
- #check_locked ⇒ void
- #clear ⇒ void
-
#emit(str) ⇒ void
Captures the assembled repaint frame instead of writing to the test runner’s TTY.
-
#initialize ⇒ FakeScreen
constructor
A new instance of FakeScreen.
- #invalidated?(component) ⇒ Boolean
- #invalidated_clear ⇒ void
-
#print(*args) ⇒ void
Doesn’t print anything: collects all strings in #prints.
Methods inherited from Screen
#active_window, #add_popup, #close, close, #content, #content=, #cursor_position, fake, #focus_next, #focus_previous, #has_popup?, instance, #invalidate, #needs_full_repaint, #popups, #register_global_shortcut, #remove_popup, #repaint, #run_event_loop, #unregister_global_shortcut
Constructor Details
#initialize ⇒ FakeScreen
Returns a new instance of FakeScreen.
24 25 26 27 28 29 30 |
# File 'lib/tuile/fake_screen.rb', line 24 def initialize super @event_queue = FakeEventQueue.new @size = Size.new(160, 50) @buffer.resize(@size) # super sized it to the test runner's TTY @prints = [] end |
Instance Attribute Details
#prints ⇒ Array<String> (readonly)
Returns whatever #print / #emit produced so far. Component painting lands in Screen#buffer, not here — assert on Buffer#row_text / Buffer#row_ansi / Buffer#cell for content, and on ‘prints` for cursor and housekeeping escapes.
36 37 38 |
# File 'lib/tuile/fake_screen.rb', line 36 def prints @prints end |
Instance Method Details
#check_locked ⇒ void
This method returns an undefined value.
39 |
# File 'lib/tuile/fake_screen.rb', line 39 def check_locked; end |
#clear ⇒ void
This method returns an undefined value.
42 43 44 |
# File 'lib/tuile/fake_screen.rb', line 42 def clear @prints.clear end |
#emit(str) ⇒ void
This method returns an undefined value.
Captures the assembled repaint frame instead of writing to the test runner’s TTY. Lands in #prints so cursor/sync escapes can be asserted; painted content is read from Screen#buffer.
58 59 60 |
# File 'lib/tuile/fake_screen.rb', line 58 def emit(str) @prints << str end |
#invalidated?(component) ⇒ Boolean
64 |
# File 'lib/tuile/fake_screen.rb', line 64 def invalidated?(component) = @invalidated.include?(component) |
#invalidated_clear ⇒ void
This method returns an undefined value.
67 68 69 |
# File 'lib/tuile/fake_screen.rb', line 67 def invalidated_clear @invalidated.clear end |
#print(*args) ⇒ void
This method returns an undefined value.
Doesn’t print anything: collects all strings in #prints.
49 50 51 |
# File 'lib/tuile/fake_screen.rb', line 49 def print(*args) @prints += args end |