Sha256: 3f5d51b835554a37e661530a26ea916de9e90867994d8d7d4612928bb9e73e96
Contents?: true
Size: 1.61 KB
Versions: 1
Compression:
Stored size: 1.61 KB
Contents
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 RSpec.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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
wannabe_bool-0.6.0 | spec/wannabe_bool/attributes_spec.rb |