Sha256: dce73da47b974a89b47bc9067095bdd2d92bf82b6c46b4b98058556c1f8e2c0a
Contents?: true
Size: 1.74 KB
Versions: 7
Compression:
Stored size: 1.74 KB
Contents
# encoding: utf-8 require 'spec_helper' describe SQL::Generator::Visitor, '.handler_for' do subject { object.handler_for(visitable_class) } let(:object) { Class.new(SQL::Generator::Visitor) } before :all do module ::MySpec class Visitable; end end end after :all do MySpec.class_eval { remove_const(:Visitable) } Object.class_eval { remove_const(:MySpec) } end context 'with an object handled by a public method' do let(:visitable_class) { MySpec::Visitable } before do object.class_eval do remove_instance_variable(:@handlers) if instance_variable_defined?(:@handlers) define_method(:visit_my_spec_visitable) {} end end after do object.class_eval do remove_instance_variable(:@handlers) remove_method(:visit_my_spec_visitable) end end it_should_behave_like 'an idempotent method' it { should == :visit_my_spec_visitable } end context 'with an object handled by a private method' do let(:visitable_class) { MySpec::Visitable } before do object.class_eval do remove_instance_variable(:@handlers) if instance_variable_defined?(:@handlers) define_method(:visit_my_spec_visitable) {} private :visit_my_spec_visitable end end after do object.class_eval do remove_instance_variable(:@handlers) remove_method(:visit_my_spec_visitable) end end it_should_behave_like 'an idempotent method' it { should == :visit_my_spec_visitable } end context 'with an unhandled object' do let(:visitable_class) { Class.new } specify { expect { subject }.to raise_error(object::UnknownObject, "No handler for #{visitable_class} in #{object}") } end end
Version data entries
7 entries across 7 versions & 2 rubygems