summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGabriel Mazetto <brodock@gmail.com>2017-02-13 12:21:12 +0100
committerGabriel Mazetto <brodock@gmail.com>2017-05-31 14:33:03 +0200
commitbc6d131b74ba4cdf7acadea5a5b7d23f083f47ed (patch)
tree2cff048cee92204e1579957531fa6027e8e8e7db /spec
parenta4460f420bbbac30fbcec3395261c89749b52bbd (diff)
downloadgitlab-ce-bc6d131b74ba4cdf7acadea5a5b7d23f083f47ed.tar.gz
Added specs for SystemCheck and custom matcher
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/system_check_spec.rb39
-rw-r--r--spec/support/matchers/execute_check.rb19
2 files changed, 58 insertions, 0 deletions
diff --git a/spec/lib/system_check_spec.rb b/spec/lib/system_check_spec.rb
new file mode 100644
index 00000000000..399a492ea2e
--- /dev/null
+++ b/spec/lib/system_check_spec.rb
@@ -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
diff --git a/spec/support/matchers/execute_check.rb b/spec/support/matchers/execute_check.rb
new file mode 100644
index 00000000000..9664eb3879d
--- /dev/null
+++ b/spec/support/matchers/execute_check.rb
@@ -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