spectus 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +14 -0
  4. data/.travis.yml +6 -0
  5. data/.yardopts +1 -0
  6. data/Gemfile +2 -0
  7. data/LICENSE.md +22 -0
  8. data/README.md +239 -0
  9. data/Rakefile +18 -0
  10. data/VERSION.semver +1 -0
  11. data/lib/spectus.rb +6 -0
  12. data/lib/spectus/dsl.rb +14 -0
  13. data/lib/spectus/expectation_target.rb +27 -0
  14. data/lib/spectus/matcher.rb +35 -0
  15. data/lib/spectus/matcher/capture_stderr.rb +31 -0
  16. data/lib/spectus/matcher/capture_stdout.rb +31 -0
  17. data/lib/spectus/matcher/eql.rb +21 -0
  18. data/lib/spectus/matcher/equal.rb +21 -0
  19. data/lib/spectus/matcher/match.rb +21 -0
  20. data/lib/spectus/matcher/raise_exception.rb +27 -0
  21. data/lib/spectus/reporter.rb +45 -0
  22. data/lib/spectus/version.rb +9 -0
  23. data/spectus.gemspec +20 -0
  24. data/test/helper_test.rb +4 -0
  25. data/test/spectus/helper_test.rb +1 -0
  26. data/test/spectus/matcher/built_in/helper_test.rb +1 -0
  27. data/test/spectus/matcher/built_in/test_capture_stderr.rb +21 -0
  28. data/test/spectus/matcher/built_in/test_capture_stdout.rb +21 -0
  29. data/test/spectus/matcher/built_in/test_eql.rb +21 -0
  30. data/test/spectus/matcher/built_in/test_equal.rb +21 -0
  31. data/test/spectus/matcher/built_in/test_match.rb +21 -0
  32. data/test/spectus/matcher/built_in/test_raise_exception.rb +21 -0
  33. data/test/spectus/matcher/custom/be_prime/helper_test.rb +13 -0
  34. data/test/spectus/matcher/custom/be_prime/test_be_prime.rb +21 -0
  35. data/test/spectus/matcher/custom/be_the_answer/helper_test.rb +11 -0
  36. data/test/spectus/matcher/custom/be_the_answer/test_be_the_answer.rb +21 -0
  37. data/test/spectus/matcher/custom/helper_test.rb +1 -0
  38. data/test/spectus/matcher/custom/start_with/helper_test.rb +15 -0
  39. data/test/spectus/matcher/custom/start_with/test_start_with.rb +21 -0
  40. data/test/spectus/matcher/helper_test.rb +1 -0
  41. data/test/spectus/test_dsl.rb +9 -0
  42. data/test/spectus/test_expectation_target.rb +17 -0
  43. data/test/spectus/test_matcher.rb +34 -0
  44. data/test/spectus/test_reporter.rb +97 -0
  45. data/test/spectus/test_version.rb +11 -0
  46. data/test/support.rb +3 -0
  47. data/test/support/coverage.rb +3 -0
  48. data/test/support/env.rb +4 -0
  49. data/test/support/presenter.rb +23 -0
  50. metadata +175 -0
@@ -0,0 +1,21 @@
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 return the expected value' do
8
+ expect { subject.instance_variable_get(:@expected) }.to eql: 'foo'
9
+ end
10
+
11
+ it 'must match the string' do
12
+ expect { subject.matches? { 'foobar' } }.to equal: true
13
+ end
14
+
15
+ it 'must not match the string' 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
@@ -0,0 +1 @@
1
+ require_relative File.join '..', 'helper_test'
@@ -0,0 +1,9 @@
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
@@ -0,0 +1,17 @@
1
+ require_relative 'helper_test'
2
+
3
+ subject "expectation target" do
4
+ Spectus::ExpectationTarget.new { 42 }
5
+ end
6
+
7
+ it 'must confirm that the block is defined' do
8
+ expect { subject.instance_variable_defined?(:@actual) }.to equal: true
9
+ end
10
+
11
+ it 'must responds to :to' do
12
+ expect { subject.respond_to? :to }.to equal: true
13
+ end
14
+
15
+ it 'must responds to :not_to' do
16
+ expect { subject.respond_to? :not_to }.to equal: true
17
+ end
@@ -0,0 +1,34 @@
1
+ require_relative 'helper_test'
2
+
3
+ subject "matcher module" do
4
+ Spectus::Matcher
5
+ end
6
+
7
+ it 'must evaluate the expectation' do
8
+ expect do
9
+ subject.eval(false, eql: 'foobar') { 'foobar' }.class
10
+ end.to equal: Spectus::Reporter
11
+ end
12
+
13
+ it 'must return the class of a matcher from its symbol' do
14
+ expect { subject.get(:eql).equal? subject.const_get(:Eql) }.to equal: true
15
+ end
16
+
17
+ it 'must raise: uninitialized constant Foo' do
18
+ expect { subject.get(:foo).equal? subject.const_get(:Foo) }.
19
+ to raise_exception: NameError
20
+ end
21
+
22
+ it 'must no longer raise' do
23
+ module Spectus
24
+ module Matcher
25
+ class Foo
26
+ def matches?
27
+ true
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ expect { subject.get(:foo).equal? subject.const_get(:Foo) }.to equal: true
34
+ end
@@ -0,0 +1,97 @@
1
+ require_relative 'helper_test'
2
+
3
+ subject "reported success" do
4
+ Spectus::Reporter.new true, :foo, 42, true
5
+ end
6
+
7
+ it 'must return nil as the is no exceptions' do
8
+ expect { subject.exception }.to equal: nil
9
+ end
10
+
11
+ it 'must pass' do
12
+ expect { subject.pass? }.to equal: true
13
+ end
14
+
15
+ it 'must be a negative assertion' do
16
+ expect { subject.negated }.to equal: true
17
+ end
18
+
19
+ it 'must be foo matcher' do
20
+ expect { subject.matcher }.to equal: :foo
21
+ end
22
+
23
+ it 'must expect 42' do
24
+ expect { subject.expected }.to equal: 42
25
+ end
26
+
27
+ it 'must return a state' do
28
+ expect { subject.state }.to equal: :success
29
+ end
30
+
31
+ it 'must return a char' do
32
+ expect { subject.to_s }.to eql: '.'
33
+ end
34
+
35
+ subject "reported error" do
36
+ Spectus::Reporter.new false, :foo, 4, :BOOM
37
+ end
38
+
39
+ it 'must return the cached exception' do
40
+ expect { subject.exception }.to equal: :BOOM
41
+ end
42
+
43
+ it 'wont pass' do
44
+ expect { subject.pass? }.to equal: false
45
+ end
46
+
47
+ it 'must be a positive assertion' do
48
+ expect { subject.negated }.to equal: false
49
+ end
50
+
51
+ it 'must be foo matcher' do
52
+ expect { subject.matcher }.to equal: :foo
53
+ end
54
+
55
+ it 'must expect 4' do
56
+ expect { subject.expected }.to equal: 4
57
+ end
58
+
59
+ it 'must return a state' do
60
+ expect { subject.state }.to equal: :error
61
+ end
62
+
63
+ it 'must return a char' do
64
+ expect { subject.to_s }.to eql: 'E'
65
+ end
66
+
67
+ subject "reported failure" do
68
+ Spectus::Reporter.new false, :foo, 9, false
69
+ end
70
+
71
+ it 'must return nil as the is no exceptions' do
72
+ expect { subject.exception }.to equal: nil
73
+ end
74
+
75
+ it 'wont pass' do
76
+ expect { subject.pass? }.to equal: false
77
+ end
78
+
79
+ it 'must be a positive assertion' do
80
+ expect { subject.negated }.to equal: false
81
+ end
82
+
83
+ it 'must be foo matcher' do
84
+ expect { subject.matcher }.to equal: :foo
85
+ end
86
+
87
+ it 'must expect 9' do
88
+ expect { subject.expected }.to equal: 9
89
+ end
90
+
91
+ it 'must return a state' do
92
+ expect { subject.state }.to equal: :failure
93
+ end
94
+
95
+ it 'must return a char' do
96
+ expect { subject.to_s }.to eql: 'F'
97
+ end
@@ -0,0 +1,11 @@
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
data/test/support.rb ADDED
@@ -0,0 +1,3 @@
1
+ Dir[File.join File.dirname(__FILE__), 'support', '**' '*.rb'].each do |filename|
2
+ require_relative filename
3
+ end
@@ -0,0 +1,3 @@
1
+ require 'coveralls'
2
+
3
+ Coveralls.wear!
@@ -0,0 +1,4 @@
1
+ if RUBY_VERSION < '2.0.0'
2
+ warn "Needs Ruby 2.0.0, you're running: #{RUBY_VERSION}"
3
+ exit 1
4
+ end
@@ -0,0 +1,23 @@
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
+
13
+ result = expectation.call
14
+
15
+ case result.state
16
+ when :success
17
+ puts "\e[32m#{result}\e[0m"
18
+ when :failure
19
+ warn "\e[31m#{result}\e[0m"
20
+ else
21
+ fail result.exception
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spectus
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.pre
5
+ platform: ruby
6
+ authors:
7
+ - Cyril Wack
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: yard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.7'
69
+ description: An expectation library with some matchers for Ruby.
70
+ email:
71
+ - cyril@sashite.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".coveralls.yml"
77
+ - ".gitignore"
78
+ - ".travis.yml"
79
+ - ".yardopts"
80
+ - Gemfile
81
+ - LICENSE.md
82
+ - README.md
83
+ - Rakefile
84
+ - VERSION.semver
85
+ - lib/spectus.rb
86
+ - lib/spectus/dsl.rb
87
+ - lib/spectus/expectation_target.rb
88
+ - lib/spectus/matcher.rb
89
+ - lib/spectus/matcher/capture_stderr.rb
90
+ - lib/spectus/matcher/capture_stdout.rb
91
+ - lib/spectus/matcher/eql.rb
92
+ - lib/spectus/matcher/equal.rb
93
+ - lib/spectus/matcher/match.rb
94
+ - lib/spectus/matcher/raise_exception.rb
95
+ - lib/spectus/reporter.rb
96
+ - lib/spectus/version.rb
97
+ - spectus.gemspec
98
+ - test/helper_test.rb
99
+ - test/spectus/helper_test.rb
100
+ - test/spectus/matcher/built_in/helper_test.rb
101
+ - test/spectus/matcher/built_in/test_capture_stderr.rb
102
+ - test/spectus/matcher/built_in/test_capture_stdout.rb
103
+ - test/spectus/matcher/built_in/test_eql.rb
104
+ - test/spectus/matcher/built_in/test_equal.rb
105
+ - test/spectus/matcher/built_in/test_match.rb
106
+ - test/spectus/matcher/built_in/test_raise_exception.rb
107
+ - test/spectus/matcher/custom/be_prime/helper_test.rb
108
+ - test/spectus/matcher/custom/be_prime/test_be_prime.rb
109
+ - test/spectus/matcher/custom/be_the_answer/helper_test.rb
110
+ - test/spectus/matcher/custom/be_the_answer/test_be_the_answer.rb
111
+ - test/spectus/matcher/custom/helper_test.rb
112
+ - test/spectus/matcher/custom/start_with/helper_test.rb
113
+ - test/spectus/matcher/custom/start_with/test_start_with.rb
114
+ - test/spectus/matcher/helper_test.rb
115
+ - test/spectus/test_dsl.rb
116
+ - test/spectus/test_expectation_target.rb
117
+ - test/spectus/test_matcher.rb
118
+ - test/spectus/test_reporter.rb
119
+ - test/spectus/test_version.rb
120
+ - test/support.rb
121
+ - test/support/coverage.rb
122
+ - test/support/env.rb
123
+ - test/support/presenter.rb
124
+ homepage: https://github.com/cyril/spectus.rb
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: 2.0.0
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">"
140
+ - !ruby/object:Gem::Version
141
+ version: 1.3.1
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.2.2
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Expectation library.
148
+ test_files:
149
+ - test/helper_test.rb
150
+ - test/spectus/helper_test.rb
151
+ - test/spectus/matcher/built_in/helper_test.rb
152
+ - test/spectus/matcher/built_in/test_capture_stderr.rb
153
+ - test/spectus/matcher/built_in/test_capture_stdout.rb
154
+ - test/spectus/matcher/built_in/test_eql.rb
155
+ - test/spectus/matcher/built_in/test_equal.rb
156
+ - test/spectus/matcher/built_in/test_match.rb
157
+ - test/spectus/matcher/built_in/test_raise_exception.rb
158
+ - test/spectus/matcher/custom/be_prime/helper_test.rb
159
+ - test/spectus/matcher/custom/be_prime/test_be_prime.rb
160
+ - test/spectus/matcher/custom/be_the_answer/helper_test.rb
161
+ - test/spectus/matcher/custom/be_the_answer/test_be_the_answer.rb
162
+ - test/spectus/matcher/custom/helper_test.rb
163
+ - test/spectus/matcher/custom/start_with/helper_test.rb
164
+ - test/spectus/matcher/custom/start_with/test_start_with.rb
165
+ - test/spectus/matcher/helper_test.rb
166
+ - test/spectus/test_dsl.rb
167
+ - test/spectus/test_expectation_target.rb
168
+ - test/spectus/test_matcher.rb
169
+ - test/spectus/test_reporter.rb
170
+ - test/spectus/test_version.rb
171
+ - test/support.rb
172
+ - test/support/coverage.rb
173
+ - test/support/env.rb
174
+ - test/support/presenter.rb
175
+ has_rdoc: