File: attributes_reader_spec.rb

package info (click to toggle)
ruby-virtus 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 660 kB
  • sloc: ruby: 4,378; makefile: 2
file content (41 lines) | stat: -rw-r--r-- 867 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'spec_helper'

describe Virtus, '#attributes' do

  shared_examples_for 'attribute hash' do
    it 'includes all attributes' do
      subject.attributes = { :test => 'Hello World', :test_priv => 'Yo' }

      expect(subject.attributes).to eql(:test => 'Hello World')
    end
  end

  context 'with a class' do
    let(:model) {
      Class.new {
        include Virtus

        attribute :test,      String
        attribute :test_priv, String, :reader => :private
      }
    }

    it_behaves_like 'attribute hash' do
      subject { model.new }
    end
  end

  context 'with an instance' do
    subject { model.new }

    let(:model) { Class.new }

    before do
      subject.extend(Virtus)
      subject.attribute :test,      String
      subject.attribute :test_priv, String, :reader => :private
    end

    it_behaves_like 'attribute hash'
  end
end