spectus 1.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.gitignore +0 -5
- data/.travis.yml +12 -3
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +3 -0
- data/LICENSE.md +17 -18
- data/README.md +18 -199
- data/VERSION.semver +1 -1
- data/bin/console +7 -0
- data/bin/setup +5 -0
- data/lib/spectus.rb +12 -2
- data/lib/spectus/expectation_target.rb +86 -12
- data/lib/spectus/requirement_level/high.rb +36 -0
- data/lib/spectus/requirement_level/low.rb +22 -0
- data/lib/spectus/requirement_level/medium.rb +22 -0
- data/lib/spectus/sandbox.rb +31 -0
- data/{spectus.pem → spectus-gem-public_cert.pem} +0 -0
- data/spectus.gemspec +14 -10
- metadata +50 -72
- metadata.gz.sig +0 -0
- data/.coveralls.yml +0 -1
- data/example/duck/README.md +0 -6
- data/example/duck/app.rb +0 -3
- data/example/duck/lib.rb +0 -13
- data/example/duck/test.rb +0 -43
- data/lib/spectus/dsl.rb +0 -20
- data/lib/spectus/matcher.rb +0 -34
- data/lib/spectus/matcher/eql.rb +0 -16
- data/lib/spectus/matcher/equal.rb +0 -16
- data/lib/spectus/matcher/match.rb +0 -16
- data/lib/spectus/matcher/raise_exception.rb +0 -22
- data/lib/spectus/version.rb +0 -9
- data/test/helper_test.rb +0 -4
- data/test/spectus/helper_test.rb +0 -1
- data/test/spectus/matcher/built_in/helper_test.rb +0 -1
- data/test/spectus/matcher/built_in/test_eql.rb +0 -21
- data/test/spectus/matcher/built_in/test_equal.rb +0 -21
- data/test/spectus/matcher/built_in/test_match.rb +0 -21
- data/test/spectus/matcher/built_in/test_raise_exception.rb +0 -21
- data/test/spectus/matcher/custom/be_prime/helper_test.rb +0 -13
- data/test/spectus/matcher/custom/be_prime/test_be_prime.rb +0 -21
- data/test/spectus/matcher/custom/be_the_answer/helper_test.rb +0 -11
- data/test/spectus/matcher/custom/be_the_answer/test_be_the_answer.rb +0 -21
- data/test/spectus/matcher/custom/helper_test.rb +0 -1
- data/test/spectus/matcher/custom/start_with/helper_test.rb +0 -15
- data/test/spectus/matcher/custom/start_with/test_start_with.rb +0 -21
- data/test/spectus/matcher/helper_test.rb +0 -1
- data/test/spectus/test_dsl.rb +0 -9
- data/test/spectus/test_matcher.rb +0 -38
- data/test/spectus/test_version.rb +0 -11
- data/test/support.rb +0 -3
- data/test/support/coverage.rb +0 -11
- data/test/support/env.rb +0 -1
- data/test/support/immutable.rb +0 -12
- data/test/support/presenter.rb +0 -13
data/lib/spectus/matcher.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
module Spectus
|
2
|
-
|
3
|
-
# This module provides matchers to define expectations.
|
4
|
-
module Matcher
|
5
|
-
|
6
|
-
# Evaluate the expectation with the passed block.
|
7
|
-
#
|
8
|
-
# @param [Boolean] negated
|
9
|
-
# @param [Hash] definition
|
10
|
-
#
|
11
|
-
# @return [Boolean] Report if the expectation is true or false.
|
12
|
-
def self.pass? negated, definition, &actual
|
13
|
-
params = Array(definition).flatten 1
|
14
|
-
name = params.first
|
15
|
-
expected_args = params[1..-1]
|
16
|
-
matcher = Matcher.get(name).new(*expected_args)
|
17
|
-
|
18
|
-
negated ^ matcher.matches?(&actual)
|
19
|
-
end
|
20
|
-
|
21
|
-
# Get the class of a matcher from its symbol.
|
22
|
-
#
|
23
|
-
# @example
|
24
|
-
#
|
25
|
-
# Matcher.get(:eql) # => Eql
|
26
|
-
def self.get name
|
27
|
-
const_get name.to_s.split('_').map {|w| w.capitalize }.join.to_sym
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
Dir[File.join File.dirname(__FILE__), 'matcher', '*.rb'].each do |filename|
|
33
|
-
require_relative filename
|
34
|
-
end
|
data/lib/spectus/matcher/eql.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module Spectus
|
2
|
-
module Matcher
|
3
|
-
|
4
|
-
# Provides the implementation for `eql`.
|
5
|
-
class Eql < BasicObject
|
6
|
-
def initialize expected
|
7
|
-
@expected = expected
|
8
|
-
end
|
9
|
-
|
10
|
-
# @return [Boolean] Comparison between actual and expected values.
|
11
|
-
def matches?
|
12
|
-
@expected.eql? yield
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Spectus
|
2
|
-
module Matcher
|
3
|
-
|
4
|
-
# Provides the implementation for `equal`.
|
5
|
-
class Equal < BasicObject
|
6
|
-
def initialize expected
|
7
|
-
@expected = expected
|
8
|
-
end
|
9
|
-
|
10
|
-
# @return [Boolean] Comparison between actual and expected values.
|
11
|
-
def matches?
|
12
|
-
@expected.equal? yield
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Spectus
|
2
|
-
module Matcher
|
3
|
-
|
4
|
-
# Provides the implementation for `match`.
|
5
|
-
class Match < BasicObject
|
6
|
-
def initialize expected
|
7
|
-
@expected = expected
|
8
|
-
end
|
9
|
-
|
10
|
-
# @return [Boolean] Comparison between actual and expected values.
|
11
|
-
def matches?
|
12
|
-
!@expected.match(yield).nil?
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Spectus
|
2
|
-
module Matcher
|
3
|
-
|
4
|
-
# Provides the implementation for `raise_exception`.
|
5
|
-
class RaiseException < BasicObject
|
6
|
-
def initialize expected
|
7
|
-
@expected = expected
|
8
|
-
end
|
9
|
-
|
10
|
-
# @return [Boolean] Comparison between actual and expected values.
|
11
|
-
def matches?
|
12
|
-
begin
|
13
|
-
yield
|
14
|
-
rescue @expected
|
15
|
-
true
|
16
|
-
else
|
17
|
-
false
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/lib/spectus/version.rb
DELETED
data/test/helper_test.rb
DELETED
data/test/spectus/helper_test.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require_relative File.join '..', 'helper_test'
|
@@ -1 +0,0 @@
|
|
1
|
-
require_relative File.join '..', 'helper_test'
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require_relative 'helper_test'
|
2
|
-
|
3
|
-
subject 'eql built-in matcher' do
|
4
|
-
Spectus::Matcher::Eql.new 'foo'
|
5
|
-
end
|
6
|
-
|
7
|
-
it 'must be eql' do
|
8
|
-
expect { subject.matches? { 'foo' } }.to equal: true
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'must not be eql' do
|
12
|
-
expect { subject.matches? { 'bar' } }.not_to equal: true
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'must return false' do
|
16
|
-
expect { subject.matches? { 'bar' } }.to equal: false
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'must return the raised exception' do
|
20
|
-
expect { raise subject.matches? { BOOM } }.to raise_exception: NameError
|
21
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require_relative 'helper_test'
|
2
|
-
|
3
|
-
subject 'equal built-in matcher' do
|
4
|
-
Spectus::Matcher::Equal.new :foo
|
5
|
-
end
|
6
|
-
|
7
|
-
it 'must be equal' do
|
8
|
-
expect { subject.matches? { :foo } }.to equal: true
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'must not be equal' do
|
12
|
-
expect { subject.matches? { :bar } }.not_to equal: true
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'must return false' do
|
16
|
-
expect { subject.matches? { :bar } }.to equal: false
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'must return the raised exception' do
|
20
|
-
expect { raise subject.matches? { BOOM } }.to raise_exception: NameError
|
21
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require_relative 'helper_test'
|
2
|
-
|
3
|
-
subject 'match built-in matcher' do
|
4
|
-
Spectus::Matcher::Match.new(/^foo/)
|
5
|
-
end
|
6
|
-
|
7
|
-
it 'must match the string' do
|
8
|
-
expect { subject.matches? { 'foobar' } }.to equal: true
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'must not match the string' do
|
12
|
-
expect { subject.matches? { 'bar' } }.not_to equal: true
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'must return false' do
|
16
|
-
expect { subject.matches? { 'bar' } }.to equal: false
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'must return the raised exception' do
|
20
|
-
expect { raise subject.matches? { BOOM } }.to raise_exception: NameError
|
21
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require_relative 'helper_test'
|
2
|
-
|
3
|
-
subject 'raise exception built-in matcher' do
|
4
|
-
Spectus::Matcher::RaiseException.new ZeroDivisionError
|
5
|
-
end
|
6
|
-
|
7
|
-
it 'must raise the expected exception' do
|
8
|
-
expect { subject.matches? { 0 / 0 } }.to equal: true
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'must not raise any exceptions' do
|
12
|
-
expect { subject.matches? { :foo } }.not_to equal: true
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'must return false' do
|
16
|
-
expect { subject.matches? { :foo } }.to equal: false
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'must return the raised exception' do
|
20
|
-
expect { raise subject.matches? { BOOM } }.to raise_exception: NameError
|
21
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require_relative 'helper_test'
|
2
|
-
|
3
|
-
subject 'be prime custom matcher' do
|
4
|
-
Spectus::Matcher::BePrime.new
|
5
|
-
end
|
6
|
-
|
7
|
-
it 'must be prime' do
|
8
|
-
expect { subject.matches? { 3 } }.to equal: true
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'must not match the string' do
|
12
|
-
expect { subject.matches? { 4 } }.not_to equal: true
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'must return false' do
|
16
|
-
expect { subject.matches? { 4 } }.to equal: false
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'must return the raised exception' do
|
20
|
-
expect { raise subject.matches? { BOOM } }.to raise_exception: NameError
|
21
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require_relative 'helper_test'
|
2
|
-
|
3
|
-
subject 'be the answer custom matcher' do
|
4
|
-
Spectus::Matcher::BeTheAnswer.new
|
5
|
-
end
|
6
|
-
|
7
|
-
it 'must be the answer' do
|
8
|
-
expect { subject.matches? { 42 } }.to equal: true
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'must not match the string' do
|
12
|
-
expect { subject.matches? { 'foo' } }.not_to equal: true
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'must return false' do
|
16
|
-
expect { subject.matches? { 'foo' } }.to equal: false
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'must return the raised exception' do
|
20
|
-
expect { raise subject.matches? { BOOM } }.to raise_exception: NameError
|
21
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require_relative File.join '..', 'helper_test'
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require_relative File.join '..', 'helper_test'
|
2
|
-
|
3
|
-
module Spectus
|
4
|
-
module Matcher
|
5
|
-
class StartWith
|
6
|
-
def initialize expected
|
7
|
-
@expected = expected
|
8
|
-
end
|
9
|
-
|
10
|
-
def matches?
|
11
|
-
Regexp.new("^#{@expected}").match(yield) != nil
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require_relative 'helper_test'
|
2
|
-
|
3
|
-
subject 'start with custom matcher' do
|
4
|
-
Spectus::Matcher::StartWith.new('foo')
|
5
|
-
end
|
6
|
-
|
7
|
-
it 'must match the string' do
|
8
|
-
expect { subject.matches? { 'foobar' } }.to equal: true
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'must not match the string' do
|
12
|
-
expect { subject.matches? { 'bar' } }.not_to equal: true
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'must return false' do
|
16
|
-
expect { subject.matches? { 'bar' } }.to equal: false
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'must return the raised exception' do
|
20
|
-
expect { raise subject.matches? { BOOM } }.to raise_exception: NameError
|
21
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require_relative File.join '..', 'helper_test'
|
data/test/spectus/test_dsl.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require_relative 'helper_test'
|
2
|
-
|
3
|
-
subject "matcher module" do
|
4
|
-
Spectus::Matcher
|
5
|
-
end
|
6
|
-
|
7
|
-
it 'must return true after the evaluation' do
|
8
|
-
expect { subject.pass?(false, eql: 'foo') { 'foo' } }.to equal: true
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'must return false after the evaluation' do
|
12
|
-
expect { subject.pass?(false, eql: 'foo') { 'bar' } }.to equal: false
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'must raise a name error exception' do
|
16
|
-
expect { subject.pass?(false, eql: 'foo') { BOOM } }.
|
17
|
-
to raise_exception: NameError
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'must return the class of a matcher from its symbol' do
|
21
|
-
expect { subject.get(:eql).equal? subject.const_get(:Eql) }.to equal: true
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'must raise a name error exception' do
|
25
|
-
expect { subject.get(:foo).equal? subject.const_get(:Foo) }.
|
26
|
-
to raise_exception: NameError
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'must no longer raise' do
|
30
|
-
module Spectus
|
31
|
-
module Matcher
|
32
|
-
class Foo
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
expect { subject.get(:foo).equal? subject.const_get(:Foo) }.to equal: true
|
38
|
-
end
|
data/test/support.rb
DELETED
data/test/support/coverage.rb
DELETED
data/test/support/env.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
abort "Needs Ruby 2, you're running: #{RUBY_VERSION}" if RUBY_VERSION < '2'
|
data/test/support/immutable.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
class Object
|
2
|
-
alias_method :overridden_initialize, :initialize
|
3
|
-
|
4
|
-
def initialize
|
5
|
-
overridden_initialize
|
6
|
-
|
7
|
-
if !self.class.ancestors.include?(SimpleCov::Formatter::MultiFormatter) &&
|
8
|
-
!self.class.ancestors.include?(SimpleCov::Formatter::HTMLFormatter)
|
9
|
-
freeze
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
data/test/support/presenter.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
def subject title = nil, &block
|
2
|
-
if block
|
3
|
-
@subject = block.call
|
4
|
-
puts "Testing: #{title}"
|
5
|
-
else
|
6
|
-
@subject
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def it describe, &expectation
|
11
|
-
print " * #{describe}: ".ljust 79
|
12
|
-
expectation.call.equal?(true) ? puts('.') : abort('F')
|
13
|
-
end
|