From 8817f4ab38dde976065dd6a486486cd628478417 Mon Sep 17 00:00:00 2001 From: Andrew Kvalheim Date: Wed, 25 Feb 2015 17:11:29 -0800 Subject: [PATCH] Move IRB initialization into an overridable method. --- middleman-core/features/console.feature | 10 ++++++++++ middleman-core/lib/middleman-core/cli/console.rb | 11 ++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 middleman-core/features/console.feature diff --git a/middleman-core/features/console.feature b/middleman-core/features/console.feature new file mode 100644 index 00000000..c3400e3b --- /dev/null +++ b/middleman-core/features/console.feature @@ -0,0 +1,10 @@ +Feature: Console + + Scenario: Enter and exit the console + Given I run `middleman console` interactively + When I type "puts 'Hello from the console.'" + And I type "exit" + Then it should pass with: + """ + Hello from the console. + """ diff --git a/middleman-core/lib/middleman-core/cli/console.rb b/middleman-core/lib/middleman-core/cli/console.rb index 56b9abd9..47525b80 100644 --- a/middleman-core/lib/middleman-core/cli/console.rb +++ b/middleman-core/lib/middleman-core/cli/console.rb @@ -34,10 +34,19 @@ module Middleman::Cli # TODO: get file watcher / reload! working in console + interact_with @app + end + + private + + # Start an interactive console in the context of the provided object. + # @param [Object] context + # @return [void] + def interact_with(context) IRB.setup nil IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context require 'irb/ext/multi-irb' - IRB.irb nil, @app + IRB.irb nil, context end end end