neospec 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.buildkite/bin/check-formatting +7 -0
  3. data/.buildkite/bin/install-asdf +16 -0
  4. data/.buildkite/bin/install-ruby +11 -0
  5. data/.buildkite/bin/install-taylor +15 -0
  6. data/.buildkite/bin/setup-ruby +5 -0
  7. data/.buildkite/bin/test-ruby +8 -0
  8. data/.buildkite/bin/test-taylor +8 -0
  9. data/.buildkite/pipeline.yml +52 -0
  10. data/.tool-versions +1 -0
  11. data/Gemfile +4 -0
  12. data/Gemfile.lock +66 -0
  13. data/README.md +43 -0
  14. data/Rakefile +16 -0
  15. data/docs/example_spec.rb +28 -0
  16. data/lib/neospec/color.rb +8 -0
  17. data/lib/neospec/expector.rb +55 -0
  18. data/lib/neospec/logger/basic.rb +32 -0
  19. data/lib/neospec/logger/symbols.rb +18 -0
  20. data/lib/neospec/report/basic.rb +57 -0
  21. data/lib/neospec/results.rb +29 -0
  22. data/lib/neospec/runner/basic.rb +11 -0
  23. data/lib/neospec/spec/result/failure.rb +14 -0
  24. data/lib/neospec/spec/result.rb +31 -0
  25. data/lib/neospec/spec.rb +66 -0
  26. data/lib/neospec/suite.rb +28 -0
  27. data/lib/neospec/version.rb +3 -0
  28. data/lib/neospec.rb +38 -0
  29. data/neospec.gemspec +30 -0
  30. data/spec/neospec/expector_spec.rb +201 -0
  31. data/spec/neospec/logger/basic_spec.rb +101 -0
  32. data/spec/neospec/logger/symbols_spec.rb +54 -0
  33. data/spec/neospec/report/basic_spec.rb +115 -0
  34. data/spec/neospec/results_spec.rb +151 -0
  35. data/spec/neospec/runner/basic_spec.rb +27 -0
  36. data/spec/neospec/spec/result_spec.rb +64 -0
  37. data/spec/neospec/spec_spec.rb +103 -0
  38. data/spec/neospec/suite_spec.rb +56 -0
  39. data/spec/neospec/version_spec.rb +3 -0
  40. data/spec/neospec_spec.rb +11 -0
  41. data/spec/run.rb +30 -0
  42. data/spec/support/test_logger.rb +15 -0
  43. data/spec/support/test_outputter.rb +15 -0
  44. metadata +97 -0
data/lib/neospec.rb ADDED
@@ -0,0 +1,38 @@
1
+ require "neospec/color"
2
+ require "neospec/expector"
3
+ require "neospec/logger/basic"
4
+ require "neospec/logger/symbols"
5
+ require "neospec/report/basic"
6
+ require "neospec/results"
7
+ require "neospec/runner/basic"
8
+ require "neospec/spec"
9
+ require "neospec/spec/result"
10
+ require "neospec/spec/result/failure"
11
+ require "neospec/suite"
12
+ require "neospec/version"
13
+
14
+ class Neospec
15
+ attr_accessor :logger, :suites, :reporters
16
+
17
+ def initialize(
18
+ suites: [],
19
+ logger: Neospec::Logger::Basic.new,
20
+ reporters: [Neospec::Report::Basic]
21
+ )
22
+ @suites = suites
23
+ @logger = logger
24
+ @reporters = reporters
25
+ end
26
+
27
+ def run!
28
+ @suites.each { |suite|
29
+ suite.run(logger: logger)
30
+ }
31
+
32
+ results = Neospec::Results.new(suites: @suites)
33
+
34
+ reporters.each { |reporter| reporter.call(results) }
35
+
36
+ exit 1 unless results.successful?
37
+ end
38
+ end
data/neospec.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ require_relative "./lib/neospec/version"
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = "neospec"
5
+ gem.version = Neospec::VERSION
6
+ gem.summary = "A simple testing library that works on ruby and mruby"
7
+ gem.description = <<-DESC
8
+ A simple testing library that works on ruby and mruby.
9
+
10
+ This has been designed to be very modular, you can run different types of
11
+ suites with different setup/teardown and before/after blocks. You can have
12
+ as many reporters as you want, these can range from "output to the terminal
13
+ in a nice way" all the way to "shape the results into an XML or JSON for my
14
+ CI".
15
+
16
+ The secondary purpose of this testing library is to work with mruby for my
17
+ game engine Taylor and any project built upon that.
18
+
19
+ I also plan to support quite a few ruby versions as I want the code for
20
+ this to be very portable. The main feature I don't want to drop is
21
+ positional AND keyword arguments in definitions, this means anything that
22
+ matches the Ruby 2.6+ spec should be compatible.
23
+ DESC
24
+ gem.authors = ["Sean Earle"]
25
+ gem.email = ["sean.r.earle@gmail.com"]
26
+ gem.files = `git ls-files`.split($\)
27
+ gem.homepage = "https://github.com/HellRok/neospec"
28
+ gem.license = "MIT"
29
+ gem.required_ruby_version = ">= 2.6.0"
30
+ end
@@ -0,0 +1,201 @@
1
+ @unit.describe "Neospec::Expector#initialize" do
2
+ Given "We create a new Neospec::Expector instance" do
3
+ @result = Neospec::Spec::Result.new
4
+ @logger = TestLogger.new
5
+
6
+ @expect = Neospec::Expector.new(
7
+ result: @result,
8
+ actual: "actual",
9
+ logger: @logger,
10
+ stack: ["the stack"]
11
+ )
12
+ end
13
+
14
+ Then "instance variables are set" do
15
+ expect(@expect.instance_variable_get(:@result)).to_equal(@result)
16
+ expect(@expect.instance_variable_get(:@actual)).to_equal("actual")
17
+ expect(@expect.instance_variable_get(:@logger)).to_equal(@logger)
18
+ expect(@expect.instance_variable_get(:@stack)).to_equal(["the stack"])
19
+ end
20
+ end
21
+
22
+ @unit.describe "Neospec::Expector#log" do
23
+ Given "We create a new Neospec::Expector instance" do
24
+ @result = Neospec::Spec::Result.new
25
+ @logger = TestLogger.new
26
+
27
+ @expect = Neospec::Expector.new(
28
+ result: @result,
29
+ actual: "actual",
30
+ logger: @logger,
31
+ stack: ["the stack"]
32
+ )
33
+ end
34
+
35
+ When "#log is called" do
36
+ @expect.log("the message", context: :the_context)
37
+ end
38
+
39
+ Then "the message is logged" do
40
+ expect(@logger.calls.size).to_equal(1)
41
+ expect(@logger.calls.first).to_equal(
42
+ {
43
+ message: "the message",
44
+ context: :the_context,
45
+ result: @result
46
+ }
47
+ )
48
+ end
49
+ end
50
+
51
+ @unit.describe "Neospec::Expector#succeeded" do
52
+ Given "We create a new Neospec::Expector instance" do
53
+ @result = Neospec::Spec::Result.new
54
+ @logger = TestLogger.new
55
+
56
+ @expect = Neospec::Expector.new(
57
+ result: @result,
58
+ actual: "actual",
59
+ logger: @logger,
60
+ stack: ["the stack"]
61
+ )
62
+ end
63
+
64
+ When "#succeeded is called" do
65
+ @expect.succeeded("the success message")
66
+ end
67
+
68
+ Then "the expectation is recorded" do
69
+ expect(@result.expectations).to_equal(1)
70
+ end
71
+
72
+ And "the message is logged" do
73
+ expect(@logger.calls.size).to_equal(1)
74
+ expect(@logger.calls.first).to_equal(
75
+ {
76
+ message: "the success message",
77
+ context: :expect,
78
+ result: @result
79
+ }
80
+ )
81
+ end
82
+ end
83
+
84
+ @unit.describe "Neospec::Expector#failed" do
85
+ Given "We create a new Neospec::Expector instance" do
86
+ @result = Neospec::Spec::Result.new
87
+ @logger = TestLogger.new
88
+
89
+ @expect = Neospec::Expector.new(
90
+ result: @result,
91
+ actual: "actual",
92
+ logger: @logger,
93
+ stack: ["the stack"]
94
+ )
95
+ end
96
+
97
+ When "#failed is called" do
98
+ @expect.failed("the failure message")
99
+ end
100
+
101
+ Then "the failure is recorded" do
102
+ expect(@result.failures.size).to_equal(1)
103
+ expect(@result.failures.first.message).to_equal("Expected the failure message")
104
+ expect(@result.failures.first.stack).to_equal(["the stack"])
105
+ end
106
+
107
+ And "the expectation is recorded" do
108
+ expect(@result.expectations).to_equal(1)
109
+ end
110
+
111
+ And "the message is logged" do
112
+ expect(@logger.calls.size).to_equal(1)
113
+ expect(@logger.calls.first).to_equal(
114
+ {
115
+ message: "the failure message",
116
+ context: :expect,
117
+ result: @result
118
+ }
119
+ )
120
+ end
121
+ end
122
+
123
+ @unit.describe "Neospec::Expector expectations" do
124
+ Given "We create a new Neospec::Expector instance" do
125
+ @result = Neospec::Spec::Result.new
126
+ @logger = TestLogger.new
127
+
128
+ @expect = Neospec::Expector.new(
129
+ result: @result,
130
+ actual: "actual",
131
+ logger: @logger,
132
+ stack: ["the stack"]
133
+ )
134
+ end
135
+
136
+ When "#to_equal is called with success" do
137
+ @expect.to_equal("actual")
138
+ end
139
+
140
+ Then "it's recorded" do
141
+ expect(@result.expectations).to_equal(1)
142
+ expect(@result.failures.size).to_equal(0)
143
+ expect(@logger.calls.size).to_equal(1)
144
+ expect(@logger.calls.last[:message]).to_equal("to be equal")
145
+ end
146
+
147
+ When "#to_equal is called with failure" do
148
+ @expect.to_equal("wrong")
149
+ end
150
+
151
+ Then "it's recorded" do
152
+ expect(@result.expectations).to_equal(2)
153
+ expect(@result.failures.size).to_equal(1)
154
+ expect(@logger.calls.size).to_equal(2)
155
+ expect(@logger.calls.last[:message]).to_equal("'wrong' to equal 'actual'")
156
+ end
157
+
158
+ When "#not_to_equal is called with success" do
159
+ @expect.not_to_equal("wrong")
160
+ end
161
+
162
+ Then "it's recorded" do
163
+ expect(@result.expectations).to_equal(3)
164
+ expect(@result.failures.size).to_equal(1)
165
+ expect(@logger.calls.size).to_equal(3)
166
+ expect(@logger.calls.last[:message]).to_equal("not to be equal")
167
+ end
168
+
169
+ When "#to_equal is called with failure" do
170
+ @expect.not_to_equal("actual")
171
+ end
172
+
173
+ Then "it's recorded" do
174
+ expect(@result.expectations).to_equal(4)
175
+ expect(@result.failures.size).to_equal(2)
176
+ expect(@logger.calls.size).to_equal(4)
177
+ expect(@logger.calls.last[:message]).to_equal("'actual' not to equal 'actual'")
178
+ end
179
+
180
+ When "#to_be_a is called with success" do
181
+ @expect.to_be_a(String)
182
+ end
183
+
184
+ Then "it's recorded" do
185
+ expect(@result.expectations).to_equal(5)
186
+ expect(@result.failures.size).to_equal(2)
187
+ expect(@logger.calls.size).to_equal(5)
188
+ expect(@logger.calls.last[:message]).to_equal("to be a String")
189
+ end
190
+
191
+ When "#to_be_a is called with failure" do
192
+ @expect.to_be_a(Array)
193
+ end
194
+
195
+ Then "it's recorded" do
196
+ expect(@result.expectations).to_equal(6)
197
+ expect(@result.failures.size).to_equal(3)
198
+ expect(@logger.calls.size).to_equal(6)
199
+ expect(@logger.calls.last[:message]).to_equal("'Array' to equal 'String'")
200
+ end
201
+ end
@@ -0,0 +1,101 @@
1
+ @unit.describe "Neospec::Logger::Basic#initialize" do
2
+ Given "we create a new Neospec::Suite instance" do
3
+ @output = TestOutputter.new
4
+ @logger = Neospec::Logger::Basic.new(output: @output, color: "color")
5
+ end
6
+
7
+ Then "instance variables are set" do
8
+ expect(@logger.instance_variable_get(:@output)).to_equal(@output)
9
+ expect(@logger.instance_variable_get(:@color)).to_equal("color")
10
+ end
11
+ end
12
+
13
+ @unit.describe "Neospec::Logger::Basic#log" do
14
+ Given "we create a new Neospec::Suite instance" do
15
+ @output = TestOutputter.new
16
+ @logger = Neospec::Logger::Basic.new(output: @output)
17
+ end
18
+
19
+ When "called with a describe context" do
20
+ @logger.log("describe message", context: :describe)
21
+ end
22
+
23
+ Then "it outputs with no indent" do
24
+ expect(@output.calls.size).to_equal(1)
25
+ expect(@output.calls.last).to_equal("#{Neospec::Color::BLUE}describe message#{Neospec::Color::RESET}\n")
26
+ end
27
+
28
+ When "called with a successful expect context" do
29
+ @logger.log("success message", context: :expect, result: Neospec::Spec::Result.new)
30
+ end
31
+
32
+ Then "it outputs with indent and ✓" do
33
+ expect(@output.calls.size).to_equal(2)
34
+ expect(@output.calls.last).to_equal(" #{Neospec::Color::GREEN}✓ expect success message#{Neospec::Color::RESET}\n")
35
+ end
36
+
37
+ When "called with a failed expect context" do
38
+ failure = Neospec::Spec::Result.new
39
+ failure.failures << "oops"
40
+ @logger.log("success message", context: :expect, result: failure)
41
+ end
42
+
43
+ Then "it outputs with indent and ✗" do
44
+ expect(@output.calls.size).to_equal(3)
45
+ expect(@output.calls.last).to_equal(" #{Neospec::Color::RED}✗ expect success message#{Neospec::Color::RESET}\n")
46
+ end
47
+
48
+ When "called with any other context" do
49
+ @logger.log("given message", context: :Given)
50
+ end
51
+
52
+ Then "it outputs with some indent" do
53
+ expect(@output.calls.size).to_equal(4)
54
+ expect(@output.calls.last).to_equal(" Given given message\n")
55
+ end
56
+ end
57
+
58
+ @unit.describe "Neospec::Logger::Basic#log without color" do
59
+ Given "we create a new Neospec::Suite instance" do
60
+ @output = TestOutputter.new
61
+ @logger = Neospec::Logger::Basic.new(color: false, output: @output)
62
+ end
63
+
64
+ When "called with a describe context" do
65
+ @logger.log("describe message", context: :describe)
66
+ end
67
+
68
+ Then "it outputs with no indent" do
69
+ expect(@output.calls.size).to_equal(1)
70
+ expect(@output.calls.last).to_equal("describe message\n")
71
+ end
72
+
73
+ When "called with a successful expect context" do
74
+ @logger.log("success message", context: :expect, result: Neospec::Spec::Result.new)
75
+ end
76
+
77
+ Then "it outputs with indent and ✓" do
78
+ expect(@output.calls.size).to_equal(2)
79
+ expect(@output.calls.last).to_equal(" ✓ expect success message\n")
80
+ end
81
+
82
+ When "called with a failed expect context" do
83
+ failure = Neospec::Spec::Result.new
84
+ failure.failures << "oops"
85
+ @logger.log("success message", context: :expect, result: failure)
86
+ end
87
+
88
+ Then "it outputs with indent and ✗" do
89
+ expect(@output.calls.size).to_equal(3)
90
+ expect(@output.calls.last).to_equal(" ✗ expect success message\n")
91
+ end
92
+
93
+ When "called with any other context" do
94
+ @logger.log("given message", context: :Given)
95
+ end
96
+
97
+ Then "it outputs with some indent" do
98
+ expect(@output.calls.size).to_equal(4)
99
+ expect(@output.calls.last).to_equal(" Given given message\n")
100
+ end
101
+ end
@@ -0,0 +1,54 @@
1
+ @unit.describe "Neospec::Logger::Symbols#initialize" do
2
+ Given "we create a new Neospec::Suite instance" do
3
+ @output = TestOutputter.new
4
+ @logger = Neospec::Logger::Symbols.new(output: @output, color: "color")
5
+ end
6
+
7
+ Then "instance variables are set" do
8
+ expect(@logger.instance_variable_get(:@output)).to_equal(@output)
9
+ expect(@logger.instance_variable_get(:@color)).to_equal("color")
10
+ end
11
+ end
12
+
13
+ @unit.describe "Neospec::Logger::Symbols#log" do
14
+ Given "we create a new Neospec::Suite instance" do
15
+ @output = TestOutputter.new
16
+ @logger = Neospec::Logger::Symbols.new(output: @output)
17
+ end
18
+
19
+ When "called with a describe context" do
20
+ @logger.log("describe message", context: :describe)
21
+ end
22
+
23
+ Then "it has no output" do
24
+ expect(@output.calls.size).to_equal(0)
25
+ end
26
+
27
+ When "called with a successful expect context" do
28
+ @logger.log("success message", context: :expect, result: Neospec::Spec::Result.new)
29
+ end
30
+
31
+ Then "it outputs ✓" do
32
+ expect(@output.calls.size).to_equal(1)
33
+ expect(@output.calls.last).to_equal("#{Neospec::Color::GREEN}✓#{Neospec::Color::RESET}")
34
+ end
35
+
36
+ When "called with a failed expect context" do
37
+ failure = Neospec::Spec::Result.new
38
+ failure.failures << "oops"
39
+ @logger.log("success message", context: :expect, result: failure)
40
+ end
41
+
42
+ Then "it outputs ✗" do
43
+ expect(@output.calls.size).to_equal(2)
44
+ expect(@output.calls.last).to_equal("#{Neospec::Color::RED}✗#{Neospec::Color::RESET}")
45
+ end
46
+
47
+ When "called with any other context" do
48
+ @logger.log("given message", context: :Given)
49
+ end
50
+
51
+ Then "it has no output" do
52
+ expect(@output.calls.size).to_equal(2)
53
+ end
54
+ end
@@ -0,0 +1,115 @@
1
+ @unit.describe "Neospec::Report::Basic.call" do
2
+ When "we have some results with no failures" do
3
+ @suite = Neospec::Suite.new
4
+ @results = Neospec::Results.new(suites: [@suite])
5
+
6
+ spec_1 = Neospec::Spec.new(description: "a spec", block: -> {})
7
+ spec_1.result.expectations = 3
8
+ spec_1.result.start = 1
9
+ spec_1.result.finish = 5
10
+ @suite.specs << spec_1
11
+
12
+ spec_2 = Neospec::Spec.new(description: "another spec", block: -> {})
13
+ spec_2.result.expectations = 4
14
+ spec_2.result.start = 6
15
+ spec_2.result.finish = 9.5
16
+ @suite.specs << spec_2
17
+ end
18
+
19
+ Then "it outputs information" do
20
+ @output = TestOutputter.new
21
+ Neospec::Report::Basic.call(@results, output: @output)
22
+
23
+ expect(@output.calls.size).to_equal(1)
24
+ expect(
25
+ @output.calls.last
26
+ ).to_equal(<<~STR)
27
+
28
+ Finished in 7.5 seconds
29
+
30
+ Results:
31
+ Specs:\t2
32
+ Expectations:\t7
33
+ STR
34
+ end
35
+
36
+ When "we have some results with failures" do
37
+ spec_3 = Neospec::Spec.new(description: "more spec", block: -> {})
38
+ spec_3.result.expectations = 4
39
+ spec_3.result.start = 6
40
+ spec_3.result.finish = 9.5
41
+ spec_3.result.failures << Neospec::Spec::Result::Failure.new(
42
+ message: "oops!",
43
+ stack: ["line 1", "line 2", "line 3", "line 4", "line 5", "line 6"]
44
+ )
45
+ @suite.specs << spec_3
46
+
47
+ spec_4 = Neospec::Spec.new(description: "even more spec", block: -> {})
48
+ spec_4.result.expectations = 2
49
+ spec_4.result.start = 10
50
+ spec_4.result.finish = 10.25
51
+ spec_4.result.failures << Neospec::Spec::Result::Failure.new(
52
+ message: "again, oops!",
53
+ stack: ["line 7", "line 8", "line 9", "line 10", "line 11", "line 12"]
54
+ )
55
+ @suite.specs << spec_4
56
+ end
57
+
58
+ Then "it outputs information" do
59
+ Neospec::Report::Basic.call(@results, output: @output)
60
+
61
+ expect(@output.calls.size).to_equal(2)
62
+ expect(
63
+ @output.calls.last
64
+ ).to_equal(<<~STR)
65
+
66
+ Finished in 11.25 seconds
67
+
68
+ Results:
69
+ Specs:\t4
70
+ Expectations:\t13
71
+ Failures:\t2
72
+
73
+ Failures:
74
+ #{Neospec::Color::RED}oops!#{Neospec::Color::RESET}
75
+ > line 1
76
+ > line 2
77
+ > line 3
78
+ > line 4
79
+ > line 5
80
+
81
+ #{Neospec::Color::RED}again, oops!#{Neospec::Color::RESET}
82
+ > line 7
83
+ > line 8
84
+ > line 9
85
+ > line 10
86
+ > line 11
87
+ STR
88
+ end
89
+ end
90
+
91
+ @unit.describe "Neospec::Report::Basic.formatted_duration" do
92
+ Given "some durations" do
93
+ hour = 60 * 60
94
+ day = 24 * 60 * 60
95
+ @milliseconds = 0.0012345
96
+ @seconds = 10.322
97
+ @minute = 61.5
98
+ @minutes = 124
99
+ @hour = hour + 62
100
+ @hours = (2 * hour) + 122
101
+ @day = day + hour + 63
102
+ @days = (3 * day) + (4 * hour) + 120
103
+ end
104
+
105
+ Then "it nicely formats them" do
106
+ expect(Neospec::Report::Basic.formatted_duration(@milliseconds)).to_equal("1.23 milliseconds")
107
+ expect(Neospec::Report::Basic.formatted_duration(@seconds)).to_equal("10.32 seconds")
108
+ expect(Neospec::Report::Basic.formatted_duration(@minute)).to_equal("1 minute 1 second")
109
+ expect(Neospec::Report::Basic.formatted_duration(@minutes)).to_equal("2 minutes 4 seconds")
110
+ expect(Neospec::Report::Basic.formatted_duration(@hour)).to_equal("1 hour 1 minute")
111
+ expect(Neospec::Report::Basic.formatted_duration(@hours)).to_equal("2 hours 2 minutes")
112
+ expect(Neospec::Report::Basic.formatted_duration(@day)).to_equal("1 day 1 hour")
113
+ expect(Neospec::Report::Basic.formatted_duration(@days)).to_equal("3 days 4 hours")
114
+ end
115
+ end
@@ -0,0 +1,151 @@
1
+ @unit.describe "Neospec::Results#initialize" do
2
+ Given "we create a new Neospec::Results instance" do
3
+ @results = Neospec::Results.new(suites: "suites")
4
+ end
5
+
6
+ Then "instance variables are set" do
7
+ expect(@results.suites).to_equal("suites")
8
+ end
9
+ end
10
+
11
+ @unit.describe "Neospec::Results#specs" do
12
+ Given "we create a new Neospec::Results instance" do
13
+ @suite_1 = Neospec::Suite.new
14
+ @suite_2 = Neospec::Suite.new
15
+ @results = Neospec::Results.new(suites: [@suite_1, @suite_2])
16
+ end
17
+
18
+ And "we have defined specs" do
19
+ @suite_1.describe "a spec" do
20
+ expect(true).to_equal(true)
21
+ end
22
+
23
+ @suite_2.describe "a spec" do
24
+ expect(true).to_equal(true)
25
+ end
26
+
27
+ @suite_2.describe "a spec" do
28
+ expect(true).to_equal(true)
29
+ end
30
+ end
31
+
32
+ Then "#specs contains all the suites specs" do
33
+ expect(@results.specs.size).to_equal(3)
34
+ end
35
+ end
36
+
37
+ @unit.describe "Neospec::Results#successful?" do
38
+ Given "we create a new Neospec::Results instance" do
39
+ @suite = Neospec::Suite.new
40
+ @results = Neospec::Results.new(suites: [@suite])
41
+ end
42
+
43
+ And "we run a successful build" do
44
+ @suite.describe "a spec" do
45
+ expect(true).to_equal(true)
46
+ end
47
+ @suite.run(logger: TestLogger.new)
48
+ end
49
+
50
+ Then "it's successful" do
51
+ expect(@results.successful?).to_equal(true)
52
+ end
53
+
54
+ But "we record an unsuccessful result" do
55
+ @suite.describe "a failing spec" do
56
+ expect(true).to_equal(false)
57
+ end
58
+ @suite.run(logger: TestLogger.new)
59
+ end
60
+
61
+ Then "it's not successful" do
62
+ expect(@results.successful?).to_equal(false)
63
+ end
64
+ end
65
+
66
+ @unit.describe "Neospec::Results#expectations" do
67
+ Given "we create a new Neospec::Results instance" do
68
+ @suite = Neospec::Suite.new
69
+ @results = Neospec::Results.new(suites: [@suite])
70
+ end
71
+
72
+ Then "it starts at 0" do
73
+ expect(@results.expectations).to_equal(0)
74
+ end
75
+
76
+ When "we run a build" do
77
+ @suite.describe "a spec" do
78
+ expect(true).to_equal(true)
79
+ expect(true).to_equal(true)
80
+ expect(true).to_equal(true)
81
+ end
82
+
83
+ @suite.describe "another spec" do
84
+ expect(true).to_equal(true)
85
+ expect(true).to_equal(true)
86
+ expect(true).to_equal(true)
87
+ expect(true).to_equal(true)
88
+ end
89
+
90
+ @suite.run(logger: TestLogger.new)
91
+ end
92
+
93
+ Then "it sums the expectations" do
94
+ expect(@results.expectations).to_equal(7)
95
+ end
96
+ end
97
+
98
+ @unit.describe "Neospec::Results#duration" do
99
+ Given "we create a new Neospec::Results instance" do
100
+ @suite = Neospec::Suite.new
101
+ @results = Neospec::Results.new(suites: [@suite])
102
+ end
103
+
104
+ Then "it starts at 0" do
105
+ expect(@results.duration).to_equal(0)
106
+ end
107
+
108
+ When "there are results" do
109
+ spec_1 = Neospec::Spec.new(description: "a spec", block: -> {})
110
+ spec_1.result.start = 1
111
+ spec_1.result.finish = 3
112
+ @suite.specs << spec_1
113
+
114
+ spec_2 = Neospec::Spec.new(description: "another spec", block: -> {})
115
+ spec_2.result.start = 4
116
+ spec_2.result.finish = 9.5
117
+ @suite.specs << spec_2
118
+ end
119
+
120
+ Then "it sums the durations" do
121
+ expect(@results.duration).to_equal(7.5)
122
+ end
123
+ end
124
+
125
+ @unit.describe "Neospec::Results#failures" do
126
+ Given "we create a new Neospec::Results instance" do
127
+ @suite = Neospec::Suite.new
128
+ @results = Neospec::Results.new(suites: [@suite])
129
+ end
130
+
131
+ When "there are failures" do
132
+ spec_1 = Neospec::Spec.new(description: "a spec", block: -> {})
133
+ spec_1.result.failures << "failure 1"
134
+ @suite.specs << spec_1
135
+
136
+ spec_2 = Neospec::Spec.new(description: "another spec", block: -> {})
137
+ spec_2.result.failures << "failure 2"
138
+ spec_2.result.failures << "failure 3"
139
+ @suite.specs << spec_2
140
+ end
141
+
142
+ Then "it combines all the failures" do
143
+ expect(@results.failures).to_equal(
144
+ [
145
+ "failure 1",
146
+ "failure 2",
147
+ "failure 3"
148
+ ]
149
+ )
150
+ end
151
+ end