require 'spec_helper' module Diagnostics describe Check do before { class MyClass; end } describe '.add' do it 'adds a check' do described_class.add MyClass Diagnostics.should have(1).checks end end describe '.find' do let!(:check) { described_class.add MyClass } it 'finds the check by name' do described_class.find('Diagnostics::MyClass').should eq(check) end end describe '#name' do it 'returns the diagnostic class name' do described_class.new(MyClass).name.should eq('Diagnostics::MyClass') end end describe '#instance' do it 'returns an instance of the diagnostic class' do described_class.new(MyClass).instance.should be_an_instance_of(MyClass) end end describe 'status predicate methods' do let(:check) { described_class.new(MyClass) } before do check.cls.class_eval do def passed; true end def warning; false end def failed; false end end end describe '#passed?' do specify { check.should be_passed } end describe '#warning?' do specify { check.should_not be_warning } end describe '#failed?' do specify { check.should_not be_failed } end end describe '#status' do [:passed, :warning, :failed, :none].each do |status| context "with #{status}" do let(:check) { create_check(status) } specify { check.status.should eq(status) } after { check.cls.send(:remove_method, status) } end end def create_check(status) described_class.new(MyClass).tap do |check| check.cls.class_eval do define_method(status) { true } end end end end describe '#data' do it 'returns a DataGroup instance' do data = described_class.new(MyClass).data data.should be_an_instance_of(Diagnostics::DataGroup) end end end end