From 4f71e2ac34060efcb77ea9d7517af5e7ab001755 Mon Sep 17 00:00:00 2001 From: Katsuyoshi Ito Date: Mon, 10 Jun 2013 17:47:48 +0900 Subject: [PATCH] add callback after created controller. Sometimes view controller has a data. The controller was set as a root view controller to the window before called "before" block. But a data is not set at this point. The view controller access to nil, and crash sometime even if I set a data in "before" block. After created controller it will call the specified callback method if you set :after_created option # Example describe MyViewController do tests MyViewController, after_created: :after_created_controller def after_created_controller controller # you can set data to the controller here controller.my_data = "foo" end . . end --- lib/motion/project/template/ios/spec-helpers/ui.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/motion/project/template/ios/spec-helpers/ui.rb b/lib/motion/project/template/ios/spec-helpers/ui.rb index 013690f6..90a99a65 100644 --- a/lib/motion/project/template/ios/spec-helpers/ui.rb +++ b/lib/motion/project/template/ios/spec-helpers/ui.rb @@ -213,10 +213,15 @@ module Bacon attr_accessor :controller def controller - @controller ||= if @options[:id] - storyboard.instantiateViewControllerWithIdentifier(@options[:id]) - else - @controller_class.alloc.init + @controller ||= begin + c = nil + if @options[:id] + c = storyboard.instantiateViewControllerWithIdentifier(@options[:id]) + else + c = @controller_class.alloc.init + end + send(@options[:after_created], c) if @options[:after_created] + c end end