spec/diagnostics/check_spec.rb in diagnostics-0.0.2 vs spec/diagnostics/check_spec.rb in diagnostics-0.0.3
- old
+ new
@@ -1,31 +1,47 @@
require 'spec_helper'
module Diagnostics
describe Check do
+ before { class MyClass; end }
+
describe '.add' do
it 'adds a check' do
- described_class.add :foo
+ described_class.add MyClass
Diagnostics.should have(1).checks
end
end
describe '.find' do
- let!(:check) { described_class.add :foo }
+ let!(:check) { described_class.add MyClass }
it 'finds the check by name' do
- described_class.find(:foo).should eq(check)
+ 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) do
- described_class.new(:foo) do |c|
- c.passed { true }
- c.warning { false }
- c.failed { false }
+ 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 }
@@ -43,35 +59,26 @@
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 = nil)
- described_class.new(:foo) do |c|
- c.passed { status == :passed }
- c.warning { status == :warning }
- c.failed { status == :failed }
+ 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
- context 'given a block' do
- it 'yields a DataGroup instance' do
- described_class.new(:foo).data do |d|
- d.should be_an_instance_of(Diagnostics::DataGroup)
- end
- end
- end
-
- context 'given no block' do
- it 'returns a DataGroup instance' do
- data = described_class.new(:foo).data
- data.should be_an_instance_of(Diagnostics::DataGroup)
- end
+ it 'returns a DataGroup instance' do
+ data = described_class.new(MyClass).data
+ data.should be_an_instance_of(Diagnostics::DataGroup)
end
end
end
end
\ No newline at end of file