space, → | next slide |
← | previous slide |
d | debug mode |
## <ret> | go to slide # |
c | table of contents (vi) |
f | toggle footer |
r | reload slides |
z | toggle help (this) |
class ConfigurationFacade
def initialize
@config = ...
end
def method_missing(name, *args, &block)
@config[name.to_s]
end
def capital_investment
@config["capital_investment"].present?
? @config["capital_investment"]
: 0
end
end
class AgingReportView
def view(parent)
@table_model = ReadOnlyTableModel.new
@aging = JTable.new(@table_model)
@aging.row_selection_allowed = false
@aging.cell_selection_enabled = true
end
end
def invoke_later(&block)
if javax.swing.SwingUtilities.
is_event_dispatch_thread
block.call
else
...
end
end
SwingUtilities.invoke_later(Runnable.impl do
begin
block.call
rescue Exception => ex
puts ex.message
puts ex.backtrace.join("\n")
end
end)
def add_row(row)
invoke_later do
@table_model.add_row row.to_java
end
end
def clear_rows
invoke_later do
@table_model.clear
end
end
class PlayPresenter
constructor :model, :view
def setup
@view.when :pause_clicked do
@model.pause
@view.hide_play
@view.show_pause
end
@view.when :play_clicked do
if @model.paused?
@model.resume
else
@model.play
end
end
end
end
describe Ui::PlayPresenter do
before do
create_mocks(:view, :model)
@play = @view.trap.when :play_clicked
@pause = @view.trap.when :pause_clicked
Ui::PlayPresenter.new(@model, @view)
end
end
it 'pauses the sim when Pause is clicked' do
@model.expects.pause
@view.expects.hide_play
@view.expects.show_pause
@pause.trigger
verify_mocks
end
it 'starts the sim when Play is clicked' do
@model.expects.paused?.returns false
@model.expects.play
@play.trigger
verify_mocks
end
it 'resumes the sim when Play
is clicked after a Pause' do
@model.expects.paused?.returns true
@model.expects.resume
@play.trigger
verify_mocks
end
class PlayPresenter
constructor :model, :view
def setup
@view.when :pause_clicked do
@model.pause
@view.hide_play
@view.show_pause
end
@view.when :play_clicked do
if @model.paused?
@model.resume
else
@model.play
end
end
end
end