twitter-status-bot/.gems/gems/naught-1.0.0/spec/predicate_spec.rb

85 lines
1.8 KiB
Ruby
Raw Normal View History

2014-09-03 08:49:59 +00:00
require 'spec_helper'
describe 'a null object with predicates_return(false)' do
subject(:null) { null_class.new }
let(:null_class) do
Naught.build do |config|
config.predicates_return false
end
end
it 'responds to predicate-style methods with false' do
expect(null.too_much_coffee?).to eq(false)
end
it 'responds to other methods with nil' do
expect(null.foobar).to eq(nil)
end
describe '(black hole)' do
let(:null_class) do
Naught.build do |config|
config.black_hole
config.predicates_return false
end
end
it 'responds to predicate-style methods with false' do
expect(null.too_much_coffee?).to eq(false)
end
it 'responds to other methods with self' do
expect(null.foobar).to be(null)
end
end
describe '(black hole, reverse order config)' do
let(:null_class) do
Naught.build do |config|
config.predicates_return false
config.black_hole
end
end
it 'responds to predicate-style methods with false' do
expect(null.too_much_coffee?).to eq(false)
end
it 'responds to other methods with self' do
expect(null.foobar).to be(null)
end
end
class Coffee
def black?
true
end
def origin
'Ethiopia'
end
end
describe '(mimic)' do
let(:null_class) do
Naught.build do |config|
config.mimic Coffee
config.predicates_return false
end
end
it 'responds to predicate-style methods with false' do
expect(null.black?).to eq(false)
end
it 'responds to other methods with nil' do
expect(null.origin).to be(nil)
end
it 'does not respond to undefined methods' do
expect(null).not_to respond_to(:leaf_variety)
expect { null.leaf_variety }.to raise_error(NoMethodError)
end
end
end