Skip to content

Instantly share code, notes, and snippets.

@satococoa
Last active March 12, 2017 23:46
Show Gist options
  • Save satococoa/6051504 to your computer and use it in GitHub Desktop.
Save satococoa/6051504 to your computer and use it in GitHub Desktop.
spec が強制終了してる?
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