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
Whatever #print printed so far.
Attributes inherited from Screen
#event_queue, #focused, #on_error, #pane, #size
Instance Method Summary collapse
- #check_locked ⇒ void
- #clear ⇒ void
-
#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, #has_popup?, instance, #invalidate, #popups, #remove_popup, #repaint, #run_event_loop
Constructor Details
#initialize ⇒ FakeScreen
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
#prints ⇒ Array<String> (readonly)
Returns whatever #print printed so far.
32 33 34 |
# File 'lib/tuile/fake_screen.rb', line 32 def prints @prints end |
Instance Method Details
#check_locked ⇒ void
This method returns an undefined value.
35 |
# File 'lib/tuile/fake_screen.rb', line 35 def check_locked; end |
#clear ⇒ void
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
51 |
# File 'lib/tuile/fake_screen.rb', line 51 def invalidated?(component) = @invalidated.include?(component) |
#invalidated_clear ⇒ void
This method returns an undefined value.
54 55 56 |
# File 'lib/tuile/fake_screen.rb', line 54 def invalidated_clear @invalidated.clear end |
#print(*args) ⇒ void
This method returns an undefined value.
Doesn’t print anything: collects all strings in #prints.
45 46 47 |
# File 'lib/tuile/fake_screen.rb', line 45 def print(*args) @prints += args end |