spectus 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.gitignore +0 -5
  5. data/.travis.yml +12 -3
  6. data/CODE_OF_CONDUCT.md +13 -0
  7. data/Gemfile +3 -0
  8. data/LICENSE.md +17 -18
  9. data/README.md +18 -199
  10. data/VERSION.semver +1 -1
  11. data/bin/console +7 -0
  12. data/bin/setup +5 -0
  13. data/lib/spectus.rb +12 -2
  14. data/lib/spectus/expectation_target.rb +86 -12
  15. data/lib/spectus/requirement_level/high.rb +36 -0
  16. data/lib/spectus/requirement_level/low.rb +22 -0
  17. data/lib/spectus/requirement_level/medium.rb +22 -0
  18. data/lib/spectus/sandbox.rb +31 -0
  19. data/{spectus.pem → spectus-gem-public_cert.pem} +0 -0
  20. data/spectus.gemspec +14 -10
  21. metadata +50 -72
  22. metadata.gz.sig +0 -0
  23. data/.coveralls.yml +0 -1
  24. data/example/duck/README.md +0 -6
  25. data/example/duck/app.rb +0 -3
  26. data/example/duck/lib.rb +0 -13
  27. data/example/duck/test.rb +0 -43
  28. data/lib/spectus/dsl.rb +0 -20
  29. data/lib/spectus/matcher.rb +0 -34
  30. data/lib/spectus/matcher/eql.rb +0 -16
  31. data/lib/spectus/matcher/equal.rb +0 -16
  32. data/lib/spectus/matcher/match.rb +0 -16
  33. data/lib/spectus/matcher/raise_exception.rb +0 -22
  34. data/lib/spectus/version.rb +0 -9
  35. data/test/helper_test.rb +0 -4
  36. data/test/spectus/helper_test.rb +0 -1
  37. data/test/spectus/matcher/built_in/helper_test.rb +0 -1
  38. data/test/spectus/matcher/built_in/test_eql.rb +0 -21
  39. data/test/spectus/matcher/built_in/test_equal.rb +0 -21
  40. data/test/spectus/matcher/built_in/test_match.rb +0 -21
  41. data/test/spectus/matcher/built_in/test_raise_exception.rb +0 -21
  42. data/test/spectus/matcher/custom/be_prime/helper_test.rb +0 -13
  43. data/test/spectus/matcher/custom/be_prime/test_be_prime.rb +0 -21
  44. data/test/spectus/matcher/custom/be_the_answer/helper_test.rb +0 -11
  45. data/test/spectus/matcher/custom/be_the_answer/test_be_the_answer.rb +0 -21
  46. data/test/spectus/matcher/custom/helper_test.rb +0 -1
  47. data/test/spectus/matcher/custom/start_with/helper_test.rb +0 -15
  48. data/test/spectus/matcher/custom/start_with/test_start_with.rb +0 -21
  49. data/test/spectus/matcher/helper_test.rb +0 -1
  50. data/test/spectus/test_dsl.rb +0 -9
  51. data/test/spectus/test_matcher.rb +0 -38
  52. data/test/spectus/test_version.rb +0 -11
  53. data/test/support.rb +0 -3
  54. data/test/support/coverage.rb +0 -11
  55. data/test/support/env.rb +0 -1
  56. data/test/support/immutable.rb +0 -12
  57. data/test/support/presenter.rb +0 -13
@@ -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
@@ -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
@@ -1,9 +0,0 @@
1
- require 'pathname'
2
-
3
- module Spectus
4
-
5
- # Gem version
6
- VERSION = File.open(
7
- Pathname.new(__FILE__).join '..', '..', '..', 'VERSION.semver'
8
- ).read.chomp.to_sym
9
- end
@@ -1,4 +0,0 @@
1
- require_relative 'support'
2
-
3
- require_relative File.join '..', 'lib', 'spectus'
4
- extend Spectus::DSL
@@ -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,13 +0,0 @@
1
- require_relative File.join '..', 'helper_test'
2
-
3
- require 'prime'
4
-
5
- module Spectus
6
- module Matcher
7
- class BePrime
8
- def matches?
9
- Prime.prime? yield
10
- end
11
- end
12
- end
13
- 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,11 +0,0 @@
1
- require_relative File.join '..', 'helper_test'
2
-
3
- module Spectus
4
- module Matcher
5
- class BeTheAnswer
6
- def matches?
7
- 42.equal? yield
8
- end
9
- end
10
- end
11
- 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'
@@ -1,9 +0,0 @@
1
- require_relative 'helper_test'
2
-
3
- subject "domain-specific language" do
4
- Spectus::DSL
5
- end
6
-
7
- it 'must return DSL methods' do
8
- expect { [:expect] == subject.instance_methods(false) }.to equal: true
9
- end
@@ -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
@@ -1,11 +0,0 @@
1
- require_relative 'helper_test'
2
-
3
- subject "version" do
4
- Spectus::VERSION
5
- end
6
-
7
- it 'must return the version' do
8
- expect { subject }.to equal: File.open(
9
- Pathname.new(__FILE__).join '..', '..', '..', 'VERSION.semver'
10
- ).read.chomp.to_sym
11
- end
@@ -1,3 +0,0 @@
1
- Dir[File.join File.dirname(__FILE__), 'support', '**' '*.rb'].each do |filename|
2
- require_relative filename
3
- end
@@ -1,11 +0,0 @@
1
- require 'simplecov'
2
- require 'coveralls'
3
-
4
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
- SimpleCov::Formatter::HTMLFormatter,
6
- Coveralls::SimpleCov::Formatter
7
- ]
8
-
9
- SimpleCov.start do
10
- minimum_coverage 100
11
- end
@@ -1 +0,0 @@
1
- abort "Needs Ruby 2, you're running: #{RUBY_VERSION}" if RUBY_VERSION < '2'
@@ -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
@@ -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