Sha256: 600be7ca57e72286c0298741d0c03eda9b651e02bbf51fd81f1f72eb3390265e
Contents?: true
Size: 1.09 KB
Versions: 1
Compression:
Stored size: 1.09 KB
Contents
require 'spec_helper' class Post def initialize(title) @title, @content, @created_at = title, '', 'Today' end named_accessor :title, as: :fancy_title named_writer :content, as: :post_content named_reader :created_at, as: :when_was_it_created? end describe Object do let(:post) { Post.new('foobar') } context "#named_reader" do it "should respond to getter method with specified name" do post.should respond_to(:when_was_it_created?) end it 'should return value of instance variable' do post.when_was_it_created?.should == 'Today' end end context '#named_writer' do it 'should respond to setter method with specified name' do post.should respond_to(:post_content=) end it "should set value to instance method" do content = 'barbaz' post.post_content = content post.instance_variable_get(:"@content").should == content end end context '#named_accessor' do it "should respond to both getter and setter" do post.should respond_to(:fancy_title) post.should respond_to(:fancy_title=) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
named_accessors-1.0 | spec/named_accessors/named_accessors_spec.rb |