uspec 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +13 -11
- data/.gitignore +3 -0
- data/.ruby-version +1 -1
- data/README.markdown +9 -48
- data/lib/uspec/dsl.rb +28 -5
- data/lib/uspec/result.rb +5 -5
- data/lib/uspec/version.rb +1 -1
- data/uspec/cli_spec.rb +2 -1
- data/uspec/jump_spec.rb +21 -0
- data/uspec/result_spec.rb +7 -8
- data/uspec/test_specs/break_spec +3 -0
- data/uspec/test_specs/pending_spec +6 -0
- data/uspec/test_specs/return_spec +3 -0
- data/uspec/test_specs/value_spec +3 -0
- data/uspec/uspec_helper.rb +2 -1
- data/uspec/uspec_spec.rb +8 -8
- metadata +11 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d937f702b24f432fa7a241bd2fdd4f01a6119f6da79f98f1efd3e5f726cba22
|
4
|
+
data.tar.gz: 297733864622a5a0032918a9c6d83bac21e90df4b141c5898e7309a248cb1982
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6bb5da0e65a04f60292ee4b74184e02081571eaf942c915eb239a9b98b7bb9f420d7a4da0b2fbacb9f370fb0769b2336deee1686fe250c5793953fe7ba8ed41
|
7
|
+
data.tar.gz: 6c1a3721ed8a8d41bc65583812a9abafeacf251dba910867b3567addb412c646237f64c68971a0cbc87e38f0abdaaeb8b652139c9f0b8a412e92dfae9c4e5609
|
data/.circleci/config.yml
CHANGED
@@ -1,21 +1,23 @@
|
|
1
1
|
version: 2.1
|
2
2
|
orbs:
|
3
|
-
ruby: circleci/ruby@0.
|
3
|
+
ruby: circleci/ruby@2.0.0
|
4
4
|
|
5
5
|
jobs:
|
6
6
|
build:
|
7
7
|
docker:
|
8
|
-
- image:
|
9
|
-
|
8
|
+
- image: cimg/ruby:3.1.2
|
9
|
+
|
10
|
+
working_directory: ~/repo
|
11
|
+
|
10
12
|
steps:
|
11
13
|
- checkout
|
12
14
|
- run:
|
13
|
-
name:
|
14
|
-
command:
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
steps:
|
15
|
+
name: install dependencies
|
16
|
+
command: |
|
17
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
18
|
+
|
19
|
+
# run tests!
|
19
20
|
- run:
|
20
|
-
name:
|
21
|
-
command:
|
21
|
+
name: run tests
|
22
|
+
command:
|
23
|
+
bundle exec uspec
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.3.0
|
data/README.markdown
CHANGED
@@ -24,7 +24,7 @@ This also means *no monkey patching* core classes!
|
|
24
24
|
Uspec's output is in beautiful ansi technicolor,
|
25
25
|
with red for failures, green for successes, and yellow for pending specs. Here's a screenshot:
|
26
26
|
|
27
|
-
![Screenshot!](
|
27
|
+
![Screenshot!](https://i.imgur.com/Baqggck.png)
|
28
28
|
|
29
29
|
Uspec is tiny, painless, and easy to use. Download it and give it a try!
|
30
30
|
|
@@ -90,7 +90,7 @@ A brief explanation of `uspec`'s output to show you what it can do!
|
|
90
90
|
|
91
91
|
### Success
|
92
92
|
|
93
|
-
If a spec passes:
|
93
|
+
If a spec passes (returns true):
|
94
94
|
|
95
95
|
```
|
96
96
|
-- AwesomeMcCoolname.generate creates a cool name: true
|
@@ -98,7 +98,7 @@ If a spec passes:
|
|
98
98
|
|
99
99
|
### Failure
|
100
100
|
|
101
|
-
If a spec fails:
|
101
|
+
If a spec fails (returns false):
|
102
102
|
|
103
103
|
```
|
104
104
|
-- AwesomeMcCoolname.generate creates a cool name: false
|
@@ -106,13 +106,13 @@ If a spec fails:
|
|
106
106
|
|
107
107
|
### Exception
|
108
108
|
|
109
|
-
If the spec
|
109
|
+
If the spec encounters an error (raises an Exception):
|
110
110
|
|
111
111
|
```
|
112
112
|
-- AwesomeMcCoolname.generate creates a cool name: Exception
|
113
113
|
|
114
114
|
Encountered an Exception while running spec
|
115
|
-
at uspec/awesome_mc_coolname_spec.rb:3: in `<main>'
|
115
|
+
in spec at uspec/awesome_mc_coolname_spec.rb:3: in `<main>'
|
116
116
|
|
117
117
|
RuntimeError < StandardError: 'wtf'
|
118
118
|
|
@@ -130,13 +130,13 @@ spec 'AwesomeMcCoolname.generate creates a cool name' do
|
|
130
130
|
end
|
131
131
|
```
|
132
132
|
|
133
|
-
Then Uspec will let you know:
|
133
|
+
Then Uspec will let you know so you can debug it:
|
134
134
|
|
135
135
|
```ruby
|
136
|
-
-- AwesomeMcCoolname.generate creates a badass name:
|
136
|
+
-- AwesomeMcCoolname.generate creates a badass name: Failed
|
137
137
|
|
138
138
|
Spec did not return a boolean value
|
139
|
-
at uspec/awesome_mc_coolname_spec.rb:6: in `<main>'
|
139
|
+
in spec at uspec/awesome_mc_coolname_spec.rb:6: in `<main>'
|
140
140
|
|
141
141
|
Integer < Numeric: 5
|
142
142
|
```
|
@@ -206,45 +206,6 @@ Mocks, Spies, Stubs, and More!
|
|
206
206
|
|
207
207
|
Since `uspec` is a very straight forward testing utility it is easy to use any of the standard Ruby mocking frameworks with it. However, the [Impasta gem](https://github.com/acook/impasta) was made specifically for simple but comprehensive mocking, stubbing, and spying.
|
208
208
|
|
209
|
-
Assertions & Debugging
|
210
|
-
----------------------
|
211
|
-
|
212
|
-
You can also use `uspec` to track assertions in an application or any object you want. Every spec block you use will be tracked and recorded. It's really no problem at all to do.
|
213
|
-
|
214
|
-
You can load Uspec's features directly into a class and use its DSL:
|
215
|
-
|
216
|
-
```ruby
|
217
|
-
require 'uspec'
|
218
|
-
|
219
|
-
class MyFoo
|
220
|
-
extend Uspec::DSL
|
221
|
-
|
222
|
-
def assert
|
223
|
-
spec 'foo is valid' do
|
224
|
-
false
|
225
|
-
end
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
MyFoo.new.assert
|
230
|
-
```
|
231
|
-
|
232
|
-
Assertions will be displayed as they occur, success or failure along with any informative output.
|
233
|
-
If there are any specs that fail, when your application exits its error code will equal the number of failures.
|
234
|
-
|
235
|
-
```
|
236
|
-
$ ruby foo.rb
|
237
|
-
-- foo is valid: false
|
238
|
-
$ echo $?
|
239
|
-
1
|
240
|
-
```
|
241
|
-
|
242
|
-
Uspec is just Ruby
|
243
|
-
------------------
|
244
|
-
|
245
|
-
If for some reason you don't want to use the `uspec` command, you can `require 'uspec'` and `extend Uspec::DSL`.
|
246
|
-
From there you can just run the file with ruby: `ruby my_test_spec.rb`
|
247
|
-
|
248
209
|
Contributing
|
249
210
|
------------
|
250
211
|
|
@@ -257,4 +218,4 @@ Contributing
|
|
257
218
|
Author
|
258
219
|
------
|
259
220
|
|
260
|
-
> Anthony M. Cook 2013-
|
221
|
+
> Anthony M. Cook 2013-2021
|
data/lib/uspec/dsl.rb
CHANGED
@@ -2,6 +2,10 @@ require_relative "result"
|
|
2
2
|
|
3
3
|
module Uspec
|
4
4
|
class DSL
|
5
|
+
USPEC_CLI_BLOCK = -> { @__uspec_dsl.__uspec_cli }
|
6
|
+
USPEC_STAT_BLOCK = -> { @__uspec_dsl.__uspec_cli.stats }
|
7
|
+
USPEC_SPEC_BLOCK = ->(description, &block) { @__uspec_dsl.spec description, &block }
|
8
|
+
|
5
9
|
def initialize cli
|
6
10
|
@__uspec_cli = cli
|
7
11
|
end
|
@@ -14,32 +18,49 @@ module Uspec
|
|
14
18
|
@__uspec_cli.stats
|
15
19
|
end
|
16
20
|
|
17
|
-
def
|
21
|
+
def __uspec_eval block
|
22
|
+
o = Object.new
|
23
|
+
o.define_singleton_method :__uspec_stats, USPEC_STAT_BLOCK
|
24
|
+
o.define_singleton_method :__uspec_cli, USPEC_CLI_BLOCK
|
25
|
+
o.instance_variable_set :@__uspec_cli, @__uspec_cli
|
26
|
+
o.instance_variable_set :@__uspec_dsl, self
|
27
|
+
o.define_singleton_method :spec, USPEC_SPEC_BLOCK
|
28
|
+
o.define_singleton_method :spec_block, &block
|
29
|
+
o.spec_block
|
30
|
+
end
|
31
|
+
|
32
|
+
def spec description, &block
|
33
|
+
state = 0
|
18
34
|
print ' -- ', description
|
19
35
|
|
20
|
-
if
|
36
|
+
if block then
|
21
37
|
begin
|
22
|
-
|
38
|
+
state = 1
|
39
|
+
raw_result = __uspec_eval block
|
40
|
+
state = 2
|
23
41
|
rescue Exception => raw_result
|
42
|
+
state = 3
|
24
43
|
end
|
25
44
|
end
|
26
45
|
|
27
46
|
result = Result.new description, raw_result, caller
|
28
47
|
|
29
|
-
unless
|
48
|
+
unless block then
|
49
|
+
state = 4
|
30
50
|
result.pending!
|
31
51
|
end
|
32
52
|
|
33
53
|
if result.success?
|
34
54
|
__uspec_stats.success << result
|
35
55
|
elsif result.pending?
|
36
|
-
|
56
|
+
__uspec_stats.pending << result
|
37
57
|
else
|
38
58
|
__uspec_stats.failure << result
|
39
59
|
end
|
40
60
|
|
41
61
|
print ': ', result.pretty, "\n"
|
42
62
|
rescue => error
|
63
|
+
state = 5
|
43
64
|
message = <<-MSG
|
44
65
|
#{error.class} : #{error.message}
|
45
66
|
|
@@ -50,6 +71,8 @@ module Uspec
|
|
50
71
|
puts
|
51
72
|
warn message
|
52
73
|
__uspec_stats.failure << Uspec::Result.new(message, error, caller)
|
74
|
+
ensure
|
75
|
+
return [state, error, result, raw_result]
|
53
76
|
end
|
54
77
|
end
|
55
78
|
end
|
data/lib/uspec/result.rb
CHANGED
@@ -5,6 +5,8 @@ module Uspec
|
|
5
5
|
class Result
|
6
6
|
include Terminal
|
7
7
|
|
8
|
+
PREFIX = "#{Terminal.newline}#{Terminal.yellow}>\t#{Terminal.normal}"
|
9
|
+
|
8
10
|
def initialize spec, raw, source
|
9
11
|
@spec = spec
|
10
12
|
@raw = raw
|
@@ -33,7 +35,7 @@ module Uspec
|
|
33
35
|
red('Failed'), vspace,
|
34
36
|
hspace, 'Spec did not return a boolean value ', newline,
|
35
37
|
hspace, 'in spec at ', source.first, vspace,
|
36
|
-
hspace, red(subklassinfo), inspector, newline
|
38
|
+
hspace, red(subklassinfo), inspector, (Class === raw ? ' Class' : ''), newline
|
37
39
|
].join
|
38
40
|
end
|
39
41
|
end
|
@@ -56,11 +58,9 @@ module Uspec
|
|
56
58
|
def inspector
|
57
59
|
if String === raw && raw.include?(?\n) then
|
58
60
|
# if object is a multiline string, display it unescaped
|
61
|
+
|
59
62
|
[
|
60
|
-
|
61
|
-
hspace, yellow('"""'), newline,
|
62
|
-
raw, normal, newline,
|
63
|
-
hspace, yellow('"""')
|
63
|
+
raw.split(newline).unshift(newline).join(PREFIX), normal, newline,
|
64
64
|
].join
|
65
65
|
else
|
66
66
|
handler.inspector!
|
data/lib/uspec/version.rb
CHANGED
data/uspec/cli_spec.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require_relative 'uspec_helper'
|
2
|
-
require 'open3'
|
3
2
|
|
4
3
|
spec 'shows usage' do
|
5
4
|
output = capture do
|
@@ -9,6 +8,8 @@ spec 'shows usage' do
|
|
9
8
|
output.include? 'usage'
|
10
9
|
end
|
11
10
|
|
11
|
+
spec 'pending test doesn\'t crash'
|
12
|
+
|
12
13
|
spec 'runs a path of specs' do
|
13
14
|
output = capture do
|
14
15
|
path = Pathname.new(__FILE__).parent.parent.join('example_specs').to_s
|
data/uspec/jump_spec.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative "uspec_helper"
|
2
|
+
|
3
|
+
spec 'when return used in spec, capture it as an error' do
|
4
|
+
path = Pathname.new(__FILE__).parent.join('test_specs', 'return_spec')
|
5
|
+
|
6
|
+
output = capture do
|
7
|
+
exec "bin/uspec #{path}"
|
8
|
+
end
|
9
|
+
|
10
|
+
output.include?('Invalid return') || output.include?('Spec did not return a boolean value') || output
|
11
|
+
end
|
12
|
+
|
13
|
+
spec 'when break used in spec, capture it as an error' do
|
14
|
+
path = Pathname.new(__FILE__).parent.join('test_specs', 'break_spec')
|
15
|
+
|
16
|
+
output = capture do
|
17
|
+
exec "bin/uspec #{path}"
|
18
|
+
end
|
19
|
+
|
20
|
+
output.include?('Invalid break') || output.include?('Spec did not return a boolean value') || output
|
21
|
+
end
|
data/uspec/result_spec.rb
CHANGED
@@ -13,7 +13,7 @@ end
|
|
13
13
|
class ::TestObject < BasicObject; end
|
14
14
|
obj = TestObject.new
|
15
15
|
|
16
|
-
spec "ensure BasicObject
|
16
|
+
spec "ensure BasicObject subclass instances work" do
|
17
17
|
result = Uspec::Result.new "BasicObject Subclass Result", obj, []
|
18
18
|
expected = "#<BasicObject/TestObject:"
|
19
19
|
actual = result.pretty
|
@@ -22,7 +22,7 @@ end
|
|
22
22
|
|
23
23
|
spec "display basic info about Object" do
|
24
24
|
result = Uspec::Result.new "Object Result", Object.new, []
|
25
|
-
expected = "Object < BasicObject"
|
25
|
+
expected = "Object < BasicObject: \e[0m#<Object:"
|
26
26
|
actual = result.pretty
|
27
27
|
actual.include?(expected) || result.pretty
|
28
28
|
end
|
@@ -36,8 +36,7 @@ end
|
|
36
36
|
|
37
37
|
spec "display basic info about Array class" do
|
38
38
|
result = Uspec::Result.new "Array Class Result", Array, []
|
39
|
-
|
40
|
-
expected = "#<Class:Object> < #<Class:BasicObject>: \e[0mArray"
|
39
|
+
expected = "Class < Module: \e[0mArray Class"
|
41
40
|
actual = result.pretty
|
42
41
|
actual.include?(expected) || result.pretty
|
43
42
|
end
|
@@ -62,9 +61,9 @@ spec "display a useful error message when a user-defined inspect method fails" d
|
|
62
61
|
end
|
63
62
|
|
64
63
|
spec "display strings more like their actual contents" do
|
65
|
-
|
66
|
-
|
64
|
+
string = "this string:\nshould display \e\[42;2mproperly"
|
65
|
+
expected = /this string:\n.*should display \e\[42;2mproperly/
|
66
|
+
result = Uspec::Result.new "Inspect Fail Result", string, []
|
67
67
|
actual = result.pretty
|
68
|
-
actual.
|
68
|
+
actual.match?(expected) || result.inspector
|
69
69
|
end
|
70
|
-
|
data/uspec/uspec_helper.rb
CHANGED
data/uspec/uspec_spec.rb
CHANGED
@@ -7,7 +7,7 @@ spec 'catches errors' do
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
output.include?
|
10
|
+
output.include?('Exception') || output
|
11
11
|
end
|
12
12
|
|
13
13
|
spec 'catches even non-StandardError-subclass exceptions' do
|
@@ -17,7 +17,7 @@ spec 'catches even non-StandardError-subclass exceptions' do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
output.include?
|
20
|
+
output.include?('Exception') || output
|
21
21
|
end
|
22
22
|
|
23
23
|
spec 'complains when spec block returns non boolean' do
|
@@ -27,7 +27,7 @@ spec 'complains when spec block returns non boolean' do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
output.include?
|
30
|
+
output.include?('Failed') || output
|
31
31
|
end
|
32
32
|
|
33
33
|
spec 'marks test as pending when no block supplied' do
|
@@ -35,7 +35,7 @@ spec 'marks test as pending when no block supplied' do
|
|
35
35
|
spec 'pending test'
|
36
36
|
end
|
37
37
|
|
38
|
-
output.include?
|
38
|
+
output.include?('pending') || output
|
39
39
|
end
|
40
40
|
|
41
41
|
spec 'should not define DSL methods on arbitrary objects' do
|
@@ -57,11 +57,11 @@ spec 'exit code is the number of failures' do
|
|
57
57
|
end
|
58
58
|
actual = $?.exitstatus
|
59
59
|
|
60
|
-
actual == expected ||
|
60
|
+
actual == expected || output
|
61
61
|
end
|
62
62
|
|
63
|
-
spec '
|
64
|
-
capture do
|
63
|
+
spec 'when more than 255 failures, exit status is 255' do
|
64
|
+
output = capture do
|
65
65
|
__uspec_stats.clear_results! # because we're forking, we will have a copy of the current results
|
66
66
|
|
67
67
|
500.times do
|
@@ -73,5 +73,5 @@ spec 'if more than 255 failures, exit status is 255' do
|
|
73
73
|
exit __uspec_cli.exit_code
|
74
74
|
end
|
75
75
|
|
76
|
-
$?.exitstatus == 255 ||
|
76
|
+
$?.exitstatus == 255 || [$?, output]
|
77
77
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony M. Cook
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: that_object_is_so_basic
|
@@ -84,15 +84,20 @@ files:
|
|
84
84
|
- lib/uspec/version.rb
|
85
85
|
- uspec.gemspec
|
86
86
|
- uspec/cli_spec.rb
|
87
|
+
- uspec/jump_spec.rb
|
87
88
|
- uspec/result_spec.rb
|
89
|
+
- uspec/test_specs/break_spec
|
88
90
|
- uspec/test_specs/broken_require_spec
|
91
|
+
- uspec/test_specs/pending_spec
|
92
|
+
- uspec/test_specs/return_spec
|
93
|
+
- uspec/test_specs/value_spec
|
89
94
|
- uspec/uspec_helper.rb
|
90
95
|
- uspec/uspec_spec.rb
|
91
96
|
homepage: http://github.com/acook/uspec#readme
|
92
97
|
licenses:
|
93
98
|
- MIT
|
94
99
|
metadata: {}
|
95
|
-
post_install_message:
|
100
|
+
post_install_message:
|
96
101
|
rdoc_options: []
|
97
102
|
require_paths:
|
98
103
|
- lib
|
@@ -107,8 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
112
|
- !ruby/object:Gem::Version
|
108
113
|
version: '0'
|
109
114
|
requirements: []
|
110
|
-
rubygems_version: 3.
|
111
|
-
signing_key:
|
115
|
+
rubygems_version: 3.5.3
|
116
|
+
signing_key:
|
112
117
|
specification_version: 4
|
113
118
|
summary: a shiny little spec framework for your apps!
|
114
119
|
test_files: []
|