Skip to content

Instantly share code, notes, and snippets.

@s2kw
Last active December 22, 2015 04:59
Show Gist options
  • Save s2kw/6420859 to your computer and use it in GitHub Desktop.
Save s2kw/6420859 to your computer and use it in GitHub Desktop.
RubyMotion Test Tutorial.
class ButtonController < UIViewController
def viewDidLoad
super
@button = UIButton.buttonWithType(UIButtonTypeRoundedRect)
@button.setTitle( "Test me title!", forState:UIControlStateNormal )
# ここの文字列で検索がされる
@button.accessibilityLabel = 'Test me!'
@button.sizeToFit
self.view.addSubview(@button)
@button.addTarget(self, action:'tapped',forControlEvents:UIControlEventTouchUpInside)
end
def tapped
p "tapped!"
@was_tapped = true
end
end
describe "Application 'Tests'" do
before do
@app = UIApplication.sharedApplication
end
it "has one window" do
@app.windows.size.should == 1
end
end
describe "button controller" do
tests ButtonController
it "changes instance variable when button is tapped" do
# @button.accessibilityLabel で指定した文字列で検索しにいく。
tap 'Test me!'
# controller はButtonControllerのエイリアス
# @was_tappedが存在するか確認。
controller.instance_variable_get('@was_tapped').should == true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment