Sha256: 386528bc98da80af84a7f83202e1e7b58747679613415ee93de5859962046b84
Contents?: true
Size: 1.62 KB
Versions: 2
Compression:
Stored size: 1.62 KB
Contents
# encoding: utf-8 class Fake include WannabeBool::Attributes attr_reader :main, :published, :migrated attr_wannabe_bool :main, :published, :migrated def initialize(main, published) @main = main @published = published end def migrated? # Don't worry about the symbol in return, it is just to help in test expectation. :original_method_return end end describe WannabeBool::Attributes do context 'when reader attribute exists' do let(:subject_methods) do fake = Fake.new(true, true) fake.public_methods - Object.methods end it 'creates the predicate method' do expect(subject_methods).to include(:main?) expect(subject_methods).to include(:published?) end [ { type: 'string', value: 'true' }, { type: 'integer', value: 1 }, { type: 'symbol', value: :true }, { type: 'boolean', value: true } ].each do |info| context "with a #{info[:type]} value" do subject { Fake.new(info[:value], info[:value]) } it 'returns original value converted to boolean' do expect(subject.main?).to be true expect(subject.published?).to be true end end end end context 'when reader attribute does not exist' do it 'raise an ArgumentError' do expect { Fake.send(:attr_wannabe_bool, :not_exist) }.to raise_error(ArgumentError, 'not_exist method is not defined.') end end context 'when predicate method exists' do subject { Fake.new(true, true) } it 'does not overrides the original predicate method' do expect(subject.migrated?).to eql :original_method_return end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
wannabe_bool-0.1.1 | spec/wannabe_bool/attributes_spec.rb |
wannabe_bool-0.1.0 | spec/wannabe_bool/attributes_spec.rb |