Last active
March 12, 2017 23:46
-
-
Save satococoa/6051504 to your computer and use it in GitHub Desktop.
spec が強制終了してる?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User | |
attr_accessor :name | |
def initialize(name = '') | |
@name = name | |
end | |
def initWithCoder(decoder) | |
self.init | |
self.name = decoder.decodeObjectForKey('name') | |
self | |
end | |
def encodeWithCoder(encoder) | |
encoder.encodeObject(self.name, forKey: 'name') | |
end | |
end | |
describe "Application 'nscoding'" do | |
before do | |
@user = User.new('foo') | |
end | |
it 'nameの値が正しい' do | |
@user.name.should == 'foo' | |
end | |
it 'NSCoding準拠' do | |
@user.respond_to?(:'initWithCoder:').should == true | |
@user.respond_to?(:'encodeWithCoder:').should == true | |
end | |
# ここから | |
it 'save -> load できる' do | |
user_as_data = NSKeyedArchiver.archivedDataWithRootObject(@user) | |
loaded_user = NSKeyedUnarchiver.unarchiveObjectWithData(user_as_data) | |
loaded_user.name.should == 'foo' | |
end | |
# ここまで | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment