Added specs for SystemCheck and custom matcher
This commit is contained in:
parent
a4460f420b
commit
bc6d131b74
|
@ -15,9 +15,16 @@ module SystemCheck
|
|||
raise ArgumentError, 'Invalid executor'
|
||||
end
|
||||
|
||||
prepare(component, checks, executor_klass).execute
|
||||
end
|
||||
|
||||
def self.prepare(component, checks = [], executor_klass = SimpleExecutor)
|
||||
executor = executor_klass.new(component)
|
||||
checks.each do |check|
|
||||
executor << check
|
||||
end
|
||||
|
||||
executor
|
||||
end
|
||||
private_class_method :prepare
|
||||
end
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe SystemCheck, lib: true do
|
||||
subject { SystemCheck }
|
||||
|
||||
describe '.run' do
|
||||
it 'requires custom executor to be a BasicExecutor' do
|
||||
expect { subject.run('Component', [], SystemCheck::SimpleExecutor) }.not_to raise_error
|
||||
end
|
||||
|
||||
context 'custom matcher' do
|
||||
class SimpleCheck < SystemCheck::BaseCheck
|
||||
def check?
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
class OtherCheck < SystemCheck::BaseCheck
|
||||
def check?
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
subject { SystemCheck }
|
||||
|
||||
it 'detects execution of SimpleCheck' do
|
||||
is_expected.to execute_check(SimpleCheck)
|
||||
|
||||
SystemCheck.run('Test', [SimpleCheck])
|
||||
end
|
||||
|
||||
it 'detects exclusion of OtherCheck in execution' do
|
||||
is_expected.not_to execute_check(OtherCheck)
|
||||
|
||||
SystemCheck.run('Test', [SimpleCheck])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
RSpec::Matchers.define :execute_check do |expected|
|
||||
match do |actual|
|
||||
expect(actual).to eq(SystemCheck)
|
||||
expect(actual).to receive(:run) do |*args|
|
||||
expect(args[1]).to include(expected)
|
||||
end
|
||||
end
|
||||
|
||||
match_when_negated do |actual|
|
||||
expect(actual).to eq(SystemCheck)
|
||||
expect(actual).to receive(:run) do |*args|
|
||||
expect(args[1]).not_to include(expected)
|
||||
end
|
||||
end
|
||||
|
||||
failure_message do |actual|
|
||||
return 'This matcher must be used with SystemCheck' unless actual == SystemCheck
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue