我正在使用故事板和RubyMotion。在我的规范中,我有以下内容:
describe "SignUp scene" do
tests SignUpFacebook, :storyboard => 'LoginStoryboard', :id => 'SignUp'
it "some test" do
tap 'FirstName'
# some test here
end
end
在视图控制器中我有
class SignUpFacebook < UIViewController
def viewWillAppear animated
super
self.navigationController.setNavigationBarHidden (true, animated:false)
end
def viewWillDisappear animated
super
self.navigationController.setNavigationBarHidden (false, animated:false)
end
#some code to be tested
end
当我“rake spec”时,我收到错误:
[ERROR: NoMethodError - undefined method `setNavigationBarHidden' for nil:NilClass]
所以,navigationController是零。我错过了什么吗?或者,任何人都可以建议一种方法来测试引用控制器的视图控制器吗?此外,用于测试控制器是否想要在某些条件下执行segue。我可以使用一些模拟或存根吗?
答案 0 :(得分:1)
好的,我找到了一个覆盖(macbacon?)方法的方法示例,该方法返回控制器。我在这里加载了控制器并设置了一个导航控制器,以便现在运行测试。在每个测试运行之前,事件序列为:
def controller unless @controller storyboard = UIStoryboard.storyboardWithName("LoginStoryboard", bundle:nil) @controller = storyboard.instantiateViewControllerWithIdentifier('SignUpFacebook') appDelegate = UIApplication.sharedApplication.delegate appDelegate.setWindow UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds) appDelegate.window.rootViewController = UINavigationController.alloc.initWithRootViewController @controller end @controller end