uspec 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +82 -46
- data/lib/uspec/cli.rb +5 -5
- data/lib/uspec/define.rb +12 -0
- data/lib/uspec/{dsl.rb → harness.rb} +12 -20
- data/lib/uspec/result.rb +1 -1
- data/lib/uspec/spec.rb +13 -12
- data/lib/uspec/stats.rb +10 -0
- data/lib/uspec/version.rb +1 -1
- data/lib/uspec.rb +2 -1
- data/uspec/cli_spec.rb +26 -29
- data/uspec/dsl_spec.rb +24 -18
- data/uspec/stats_spec.rb +4 -4
- data/uspec/test_specs/kill_this_script.sh +7 -8
- data/uspec/uspec_helper.rb +35 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d17e77cb5065265172f613c90f9edfb022c217386b56d34af6858b078ba406d8
|
4
|
+
data.tar.gz: 1c77be04e49ca61e243d7c35aa84c9de56dac3ae8f099ba351f6efa5d9a5ca38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf99ec58c05e076e9060b7ac71271e5fcdfd8ab44e03810b41a1ac2a67a4921777dca4ed2a5c27637f071b20fabb0262118b4a7214448b63ea8193450dc663b6
|
7
|
+
data.tar.gz: eb1c4de66aef1dfef542774fd18b9484bf26778bfe5651c0594fc6cd543472003c32484048435a41d9baacdf3695376fcb1e25fd659ff36183072ddb44eafb41
|
data/README.markdown
CHANGED
@@ -12,26 +12,20 @@ Philosophy / Why Uspec?
|
|
12
12
|
|
13
13
|
> Uspec is just Ruby!
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
- There's no need for special matchers
|
16
|
+
- You never have to worry that your tests lack assertions
|
17
|
+
- There is no monkey patching of core classes
|
18
18
|
|
19
|
-
|
20
|
-
to determine if the test has passed or failed. Standard Ruby comparisons are your friend!
|
21
|
-
No more digging around in your test framework's documentation to figure out what matcher you're supposed to use.
|
22
|
-
This also means *no monkey patching* core classes!
|
19
|
+
No more digging around in your test framework's documentation to figure out what matcher you're supposed to use. Because you just use Ruby!
|
23
20
|
|
24
|
-
Uspec
|
25
|
-
with red for failures, green for successes, and yellow for pending specs. Here's a screenshot:
|
26
|
-
|
27
|
-
![Screenshot!](https://i.imgur.com/Baqggck.png)
|
21
|
+
Uspec is well under 500 lines of code. Most of that is there to gracefully handle the weird edge cases that pop up all the time during development and testing of software. Uspec will catch issues at every stage and display a nicely formatted message to provide hints at what might have gone wrong.
|
28
22
|
|
29
23
|
Uspec is tiny, painless, and easy to use. Download it and give it a try!
|
30
24
|
|
31
|
-
|
32
|
-
|
25
|
+
Writing Tests
|
26
|
+
----------
|
33
27
|
|
34
|
-
Uspec is
|
28
|
+
Uspec is deceptively simple. You only need to remember one method: `spec`.
|
35
29
|
|
36
30
|
Writing a spec is easy:
|
37
31
|
|
@@ -43,31 +37,18 @@ end
|
|
43
37
|
|
44
38
|
That's it!
|
45
39
|
|
46
|
-
Installation
|
47
|
-
------------
|
48
|
-
|
49
|
-
Add this line to your application's Gemfile:
|
50
|
-
|
51
|
-
gem 'uspec'
|
52
|
-
|
53
|
-
And then execute:
|
54
|
-
|
55
|
-
$ bundle
|
56
|
-
|
57
|
-
Or install it directly with:
|
58
|
-
|
59
|
-
$ gem install uspec
|
60
|
-
|
61
|
-
|
62
40
|
Quickstart
|
63
41
|
----------
|
64
42
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
2.
|
43
|
+
1. Install in the typical way using Rubygems or Bundler:
|
44
|
+
- `gem install uspec`
|
45
|
+
- `echo 'gem "uspec"' >> Gemfile && bundle install`
|
46
|
+
2. Create a `uspec` directory to keep your specs in
|
47
|
+
3. Name your specs ending with `_spec.rb`
|
48
|
+
4. Write some specs in Ruby using the `spec` method (example above)
|
49
|
+
5. Use the included `uspec` executable to run your specs
|
69
50
|
|
70
|
-
|
51
|
+
And always remember that Uspec is **just Ruby**!
|
71
52
|
|
72
53
|
Commandline Usage
|
73
54
|
-----------------
|
@@ -78,19 +59,23 @@ uspec - minimalistic ruby testing framework
|
|
78
59
|
usage: uspec [<file_or_path>...]
|
79
60
|
```
|
80
61
|
|
81
|
-
- Without arguments the `uspec` command will
|
62
|
+
- Without arguments the `uspec` command will automatically look for a `uspec` directory and load any `*_spec.rb` files inside it.
|
82
63
|
- You can also pass in arbitrary files and it will attempt to run them as specs.
|
83
64
|
- If you pass in directories `uspec` will scan for and run any specs inside them.
|
84
|
-
- Uspec will return the number of failures as its status code to the
|
65
|
+
- Uspec will return the number of failures as its exit status code to the or `0` if none.
|
85
66
|
|
86
67
|
Output
|
87
68
|
------
|
88
69
|
|
70
|
+
Uspec's output is in beautiful ANSI technicolor, with red for failures, green for successes, and yellow for pending specs.
|
71
|
+
|
72
|
+
![Screenshot!](https://i.imgur.com/Baqggck.png)
|
73
|
+
|
89
74
|
A brief explanation of `uspec`'s output to show you what it can do!
|
90
75
|
|
91
76
|
### Success
|
92
77
|
|
93
|
-
If a spec passes (returns true):
|
78
|
+
If a spec passes (returns `true`):
|
94
79
|
|
95
80
|
```
|
96
81
|
-- AwesomeMcCoolname.generate creates a cool name: true
|
@@ -98,7 +83,7 @@ If a spec passes (returns true):
|
|
98
83
|
|
99
84
|
### Failure
|
100
85
|
|
101
|
-
If a spec fails (returns false):
|
86
|
+
If a spec fails (returns `false`):
|
102
87
|
|
103
88
|
```
|
104
89
|
-- AwesomeMcCoolname.generate creates a cool name: false
|
@@ -106,7 +91,7 @@ If a spec fails (returns false):
|
|
106
91
|
|
107
92
|
### Exception
|
108
93
|
|
109
|
-
If the spec encounters an error (raises an Exception):
|
94
|
+
If the spec encounters an error (raises an `Exception`):
|
110
95
|
|
111
96
|
```
|
112
97
|
-- AwesomeMcCoolname.generate creates a cool name: Exception
|
@@ -132,7 +117,7 @@ end
|
|
132
117
|
|
133
118
|
Then Uspec will let you know so you can debug it:
|
134
119
|
|
135
|
-
```
|
120
|
+
```
|
136
121
|
-- AwesomeMcCoolname.generate creates a badass name: Failed
|
137
122
|
|
138
123
|
Spec did not return a boolean value
|
@@ -155,8 +140,59 @@ When you run the test Uspec will helpfully display:
|
|
155
140
|
-- a feature I have not implemented yet: pending
|
156
141
|
```
|
157
142
|
|
158
|
-
|
159
|
-
|
143
|
+
Reusing Test Code
|
144
|
+
------------
|
145
|
+
|
146
|
+
Test code reuse doesn't require doing anything special. It's just like any other Ruby code. But here are a few examples!
|
147
|
+
|
148
|
+
**Hint:** A lot of people put `require_relative 'spec_helper'` at the top of their test files and put shared code and helper methods in a file called `spec_helper.rb`.
|
149
|
+
|
150
|
+
### Methods
|
151
|
+
|
152
|
+
If you find yourself repeating the same code in tests several times you can extract that code into a method and then call it within your `spec` blocks.
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
def new_generator
|
156
|
+
AwesomeMcCoolname.new max_length: 15
|
157
|
+
end
|
158
|
+
|
159
|
+
spec 'generates a cool name' do
|
160
|
+
new_generator.generate.include? 'Badass'
|
161
|
+
end
|
162
|
+
```
|
163
|
+
|
164
|
+
### Instance Variables
|
165
|
+
|
166
|
+
This also works for instance variables!
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
@favorite_color = 'fuschia'
|
170
|
+
|
171
|
+
spec 'remembers favorite color' do
|
172
|
+
ColorDB.fetch(:favorite) == @favorite_color
|
173
|
+
end
|
174
|
+
```
|
175
|
+
|
176
|
+
### Memoized Methods
|
177
|
+
|
178
|
+
By combining the previous two capabilities of Ruby, it is trivial to memoize method output as well:
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
def reusable_generator
|
182
|
+
@reusable_generator ||= AwesomeMcCoolname.new max_length: 15
|
183
|
+
end
|
184
|
+
|
185
|
+
spec 'generates a cool name' do
|
186
|
+
reusable_generator.generate.include? 'Badass'
|
187
|
+
end
|
188
|
+
```
|
189
|
+
|
190
|
+
This is all the same kind of code that you use when writing any other Ruby object. You can put methods into objects and use those if you like too!
|
191
|
+
|
192
|
+
Test Matching in Plain Ruby
|
193
|
+
-----------
|
194
|
+
|
195
|
+
When the `spec` block is evaluated the `return` value is used (in a very Ruby-like way) to determine if the test has passed or failed. Standard Ruby comparisons are your friend!
|
160
196
|
|
161
197
|
Because there's no matchers and only one method there's no need for specialized reference documentation, but here are some ideas to get you going!
|
162
198
|
|
@@ -198,8 +234,8 @@ end
|
|
198
234
|
```
|
199
235
|
|
200
236
|
If there's no error, then Uspec will see the result of the method call (whatever it might be).
|
201
|
-
|
202
|
-
Ruby will dutifully pass along the error for Uspec to display.
|
237
|
+
|
238
|
+
If the wrong Exception is raised, then because of reraising (by just calling `raise` without parameters), Ruby will dutifully pass along the error for Uspec to display.
|
203
239
|
|
204
240
|
Mocks, Spies, Stubs, and More!
|
205
241
|
-----------------------
|
@@ -218,4 +254,4 @@ Contributing
|
|
218
254
|
Author
|
219
255
|
------
|
220
256
|
|
221
|
-
> Anthony M. Cook 2013-
|
257
|
+
> Anthony M. Cook 2013-2024
|
data/lib/uspec/cli.rb
CHANGED
@@ -8,9 +8,9 @@ class Uspec::CLI
|
|
8
8
|
@paths = args
|
9
9
|
@pwd = Pathname.pwd.freeze
|
10
10
|
@stats = Uspec::Stats.new
|
11
|
-
@
|
11
|
+
@harness = Uspec::Harness.new self
|
12
12
|
end
|
13
|
-
attr :stats, :
|
13
|
+
attr :stats, :harness
|
14
14
|
|
15
15
|
def usage
|
16
16
|
warn "uspec v#{::Uspec::VERSION} - minimalistic ruby testing framework"
|
@@ -74,7 +74,7 @@ class Uspec::CLI
|
|
74
74
|
end
|
75
75
|
elsif path.exist? then
|
76
76
|
puts "#{path.basename path.extname}:"
|
77
|
-
|
77
|
+
harness.define.instance_eval(path.read, path.to_s)
|
78
78
|
else
|
79
79
|
warn "path not found: #{path}"
|
80
80
|
end
|
@@ -101,9 +101,9 @@ class Uspec::CLI
|
|
101
101
|
MSG
|
102
102
|
puts
|
103
103
|
warn message
|
104
|
-
stats
|
104
|
+
stats << Uspec::Result.new(message, error, caller)
|
105
105
|
|
106
|
-
|
106
|
+
handle_interrupt! error
|
107
107
|
end
|
108
108
|
|
109
109
|
end
|
data/lib/uspec/define.rb
ADDED
@@ -2,48 +2,40 @@ require_relative "result"
|
|
2
2
|
require_relative "spec"
|
3
3
|
|
4
4
|
module Uspec
|
5
|
-
class
|
5
|
+
class Harness
|
6
6
|
|
7
7
|
def initialize cli
|
8
|
-
@
|
8
|
+
@cli = cli
|
9
|
+
@define = Uspec::Define.new self
|
9
10
|
end
|
11
|
+
attr_accessor :cli, :define
|
10
12
|
|
11
|
-
def
|
12
|
-
|
13
|
+
def stats
|
14
|
+
cli.stats
|
13
15
|
end
|
14
16
|
|
15
|
-
def
|
16
|
-
@__uspec_cli.stats
|
17
|
-
end
|
18
|
-
|
19
|
-
def spec description, &block
|
17
|
+
def spec_eval description, &block
|
20
18
|
state = 0
|
21
19
|
print ' -- ', description
|
22
20
|
|
23
21
|
if block then
|
24
22
|
begin
|
25
23
|
state = 1
|
26
|
-
raw_result =
|
24
|
+
raw_result = Uspec::Spec.new(self, description, &block).__uspec_block
|
27
25
|
state = 2
|
28
26
|
rescue Exception => raw_result
|
29
27
|
state = 3
|
30
28
|
end
|
31
29
|
end
|
32
30
|
|
33
|
-
result = Result.new description, raw_result, caller
|
31
|
+
result = Uspec::Result.new description, raw_result, caller
|
34
32
|
|
35
33
|
unless block then
|
36
34
|
state = 4
|
37
35
|
result.pending!
|
38
36
|
end
|
39
37
|
|
40
|
-
|
41
|
-
__uspec_stats.success << result
|
42
|
-
elsif result.pending?
|
43
|
-
__uspec_stats.pending << result
|
44
|
-
else
|
45
|
-
__uspec_stats.failure << result
|
46
|
-
end
|
38
|
+
stats << result
|
47
39
|
|
48
40
|
print ': ', result.pretty, "\n"
|
49
41
|
rescue => error
|
@@ -57,9 +49,9 @@ module Uspec
|
|
57
49
|
MSG
|
58
50
|
puts
|
59
51
|
warn message
|
60
|
-
|
52
|
+
stats << Uspec::Result.new(message, error, caller)
|
61
53
|
ensure
|
62
|
-
|
54
|
+
cli.handle_interrupt! result.raw
|
63
55
|
return [state, error, result, raw_result]
|
64
56
|
end
|
65
57
|
end
|
data/lib/uspec/result.rb
CHANGED
@@ -5,7 +5,7 @@ module Uspec
|
|
5
5
|
class Result
|
6
6
|
include Terminal
|
7
7
|
|
8
|
-
PREFIX = "#{Terminal.newline}#{Terminal.yellow}>\t#{Terminal.normal}"
|
8
|
+
PREFIX = "#{Uspec::Terminal.newline}#{Uspec::Terminal.yellow}>\t#{Uspec::Terminal.normal}"
|
9
9
|
|
10
10
|
def initialize spec, raw, source
|
11
11
|
@spec = spec
|
data/lib/uspec/spec.rb
CHANGED
@@ -3,31 +3,32 @@ require_relative "result"
|
|
3
3
|
module Uspec
|
4
4
|
class Spec
|
5
5
|
|
6
|
-
def initialize
|
6
|
+
def initialize harness, description, &block
|
7
7
|
@__uspec_description = description
|
8
|
-
@
|
8
|
+
@__uspec_harness = harness
|
9
|
+
ns = harness.define
|
9
10
|
|
10
|
-
|
11
|
-
self.instance_variable_set(
|
11
|
+
ns.instance_variables.each do |name|
|
12
|
+
self.instance_variable_set(
|
13
|
+
name,
|
14
|
+
ns.instance_variable_get(name)
|
15
|
+
) unless name.to_s.include? '@__uspec'
|
12
16
|
end
|
13
17
|
|
14
|
-
|
18
|
+
ns.methods(false).each do |name|
|
15
19
|
self.define_singleton_method name do |*args, &block|
|
16
|
-
|
20
|
+
ns.send name, *args, &block
|
17
21
|
end unless name.to_s.include? '__uspec'
|
18
22
|
end
|
19
23
|
|
20
24
|
if block then
|
21
|
-
|
25
|
+
self.define_singleton_method :__uspec_block, &block
|
22
26
|
else
|
23
27
|
self.define_singleton_method :__uspec_block do
|
24
|
-
raise "Uspec: No block provided for `#{@__uspec_description}`"
|
28
|
+
raise NotImplementedError, "Uspec: No block provided for `#{@__uspec_description}`"
|
25
29
|
end
|
26
30
|
end
|
27
|
-
end
|
31
|
+
end # initialize
|
28
32
|
|
29
|
-
def spec description, &block
|
30
|
-
@__uspec_dsl.spec description, &block
|
31
|
-
end
|
32
33
|
end
|
33
34
|
end
|
data/lib/uspec/stats.rb
CHANGED
@@ -5,6 +5,16 @@ module Uspec
|
|
5
5
|
end
|
6
6
|
attr :success, :failure, :pending
|
7
7
|
|
8
|
+
def << result
|
9
|
+
if result.success?
|
10
|
+
self.success << result
|
11
|
+
elsif result.pending?
|
12
|
+
self.pending << result
|
13
|
+
else
|
14
|
+
self.failure << result
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
8
18
|
def clear_results!
|
9
19
|
@success = Array.new
|
10
20
|
@failure = Array.new
|
data/lib/uspec/version.rb
CHANGED
data/lib/uspec.rb
CHANGED
data/uspec/cli_spec.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
require_relative 'uspec_helper'
|
2
2
|
|
3
|
+
def new_cli path = '.'
|
4
|
+
Uspec::CLI.new(Array(path))
|
5
|
+
end
|
6
|
+
|
7
|
+
def run_specs path
|
8
|
+
new_cli(path).run_specs
|
9
|
+
end
|
10
|
+
|
11
|
+
|
3
12
|
spec 'shows usage' do
|
4
13
|
output = capture do
|
5
14
|
exec 'bin/uspec -h'
|
@@ -9,73 +18,61 @@ spec 'shows usage' do
|
|
9
18
|
end
|
10
19
|
|
11
20
|
spec 'runs a path of specs' do
|
12
|
-
output =
|
13
|
-
|
14
|
-
Uspec::CLI.new(Array(path)).run_specs
|
21
|
+
output = outstr do
|
22
|
+
run_specs exdir.to_s
|
15
23
|
end
|
16
24
|
|
17
25
|
output.include?('I love passing tests') || output
|
18
26
|
end
|
19
27
|
|
20
28
|
spec 'runs an individual spec' do
|
21
|
-
output =
|
22
|
-
|
23
|
-
Uspec::CLI.new(Array(path)).run_specs
|
29
|
+
output = outstr do
|
30
|
+
run_specs exdir.join('example_spec.rb').to_s
|
24
31
|
end
|
25
32
|
|
26
33
|
output.include?('I love passing tests') || output
|
27
34
|
end
|
28
35
|
|
29
36
|
spec 'broken requires in test files count as test failures' do
|
30
|
-
|
37
|
+
output, status = Open3.capture2e "#{root}/bin/uspec #{testdir.join('broken_require_spec')}"
|
31
38
|
|
32
|
-
|
33
|
-
exec "bin/uspec #{path}"
|
34
|
-
end
|
35
|
-
|
36
|
-
$?.exitstatus == 1 || $?
|
39
|
+
status.exitstatus == 1 || status
|
37
40
|
end
|
38
41
|
|
39
42
|
spec 'displays information about test file with broken require' do
|
40
|
-
|
41
|
-
|
42
|
-
output = capture do
|
43
|
-
exec "bin/uspec #{path}"
|
44
|
-
end
|
43
|
+
output, status = Open3.capture2e "#{root}/bin/uspec #{testdir.join('broken_require_spec')}"
|
45
44
|
|
46
45
|
output.include?('cannot load such file') || output
|
47
46
|
end
|
48
47
|
|
49
48
|
spec 'exit code is the number of failures' do
|
50
49
|
expected = 50
|
51
|
-
|
52
|
-
@__uspec_dsl.__uspec_stats.clear_results! # because we're forking, we will have a copy of the current results
|
50
|
+
cli = new_cli
|
53
51
|
|
52
|
+
outstr do
|
54
53
|
expected.times do |count|
|
55
|
-
spec "fail ##{count + 1}" do
|
54
|
+
cli.harness.define.spec "fail ##{count + 1}" do
|
56
55
|
false
|
57
56
|
end
|
58
57
|
end
|
59
|
-
|
60
|
-
exit @__uspec_dsl.__uspec_cli.exit_code
|
61
58
|
end
|
62
|
-
actual = $?.exitstatus
|
63
59
|
|
60
|
+
actual = cli.exit_code
|
64
61
|
actual == expected || output
|
65
62
|
end
|
66
63
|
|
67
64
|
spec 'when more than 255 failures, exit status is 255' do
|
68
|
-
|
69
|
-
|
65
|
+
expected = 255
|
66
|
+
cli = new_cli
|
70
67
|
|
68
|
+
output = outstr do
|
71
69
|
500.times do
|
72
|
-
spec 'fail' do
|
70
|
+
cli.harness.define.spec 'fail' do
|
73
71
|
false
|
74
72
|
end
|
75
73
|
end
|
76
|
-
|
77
|
-
exit @__uspec_dsl.__uspec_cli.exit_code
|
78
74
|
end
|
79
75
|
|
80
|
-
|
76
|
+
actual = cli.exit_code
|
77
|
+
actual == expected || [$?, output]
|
81
78
|
end
|
data/uspec/dsl_spec.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require_relative "uspec_helper"
|
2
2
|
|
3
3
|
spec 'catches errors' do
|
4
|
-
|
5
|
-
|
4
|
+
cli = new_cli
|
5
|
+
|
6
|
+
output = outstr do
|
7
|
+
cli.harness.define.spec 'exception' do
|
6
8
|
raise 'test exception'
|
7
9
|
end
|
8
10
|
end
|
@@ -11,8 +13,10 @@ spec 'catches errors' do
|
|
11
13
|
end
|
12
14
|
|
13
15
|
spec 'catches even non-StandardError-subclass exceptions' do
|
14
|
-
|
15
|
-
|
16
|
+
cli = new_cli
|
17
|
+
|
18
|
+
output = outstr do
|
19
|
+
cli.harness.define.spec 'not implemented error' do
|
16
20
|
raise ::NotImplementedError, 'test exception'
|
17
21
|
end
|
18
22
|
end
|
@@ -21,9 +25,9 @@ spec 'catches even non-StandardError-subclass exceptions' do
|
|
21
25
|
end
|
22
26
|
|
23
27
|
spec 'Uspec exits when sent a termination signal' do
|
24
|
-
path =
|
28
|
+
path = testdir.join('kill_this_spec')
|
25
29
|
|
26
|
-
stdin, allout, thread = Open3.popen2e "
|
30
|
+
stdin, allout, thread = Open3.popen2e "#{testdir}/kill_this_script.sh \"#{path}\""
|
27
31
|
stdin.close
|
28
32
|
output = allout.read
|
29
33
|
|
@@ -40,8 +44,10 @@ spec 'Uspec exits when sent a termination signal' do
|
|
40
44
|
end
|
41
45
|
|
42
46
|
spec 'complains when spec block returns non boolean' do
|
43
|
-
|
44
|
-
|
47
|
+
cli = new_cli
|
48
|
+
|
49
|
+
output = outstr do
|
50
|
+
cli.harness.define.spec 'whatever' do
|
45
51
|
"string"
|
46
52
|
end
|
47
53
|
end
|
@@ -50,10 +56,10 @@ spec 'complains when spec block returns non boolean' do
|
|
50
56
|
end
|
51
57
|
|
52
58
|
spec 'marks test as pending when no block supplied' do
|
53
|
-
path =
|
59
|
+
path = testdir.join('pending_spec')
|
54
60
|
|
55
61
|
output = capture do
|
56
|
-
exec "bin/uspec #{path}"
|
62
|
+
exec "#{root}/bin/uspec #{path}"
|
57
63
|
end
|
58
64
|
|
59
65
|
output.include?('1 pending') || output
|
@@ -64,40 +70,40 @@ spec 'should not define DSL methods on arbitrary objects' do
|
|
64
70
|
end
|
65
71
|
|
66
72
|
spec 'when return used in spec, capture it as an error' do
|
67
|
-
path =
|
73
|
+
path = testdir.join('return_spec')
|
68
74
|
|
69
75
|
output = capture do
|
70
|
-
exec "bin/uspec #{path}"
|
76
|
+
exec "#{root}/bin/uspec #{path}"
|
71
77
|
end
|
72
78
|
|
73
79
|
output.include?('Invalid return') || output.include?('Spec did not return a boolean value') || output
|
74
80
|
end
|
75
81
|
|
76
82
|
spec 'when break used in spec, capture it as an error' do
|
77
|
-
path =
|
83
|
+
path = testdir.join('break_spec')
|
78
84
|
|
79
85
|
output = capture do
|
80
|
-
exec "bin/uspec #{path}"
|
86
|
+
exec "#{root}/bin/uspec #{path}"
|
81
87
|
end
|
82
88
|
|
83
89
|
output.include?('Invalid break') || output.include?('Spec did not return a boolean value') || output
|
84
90
|
end
|
85
91
|
|
86
92
|
spec 'when instance variables are defined in the DSL instance, they are available in the spec body' do
|
87
|
-
path =
|
93
|
+
path = testdir.join('ivar_spec')
|
88
94
|
|
89
95
|
output = capture do
|
90
|
-
exec "bin/uspec #{path}"
|
96
|
+
exec "#{root}/bin/uspec #{path}"
|
91
97
|
end
|
92
98
|
|
93
99
|
output.include?('1 successful') || output
|
94
100
|
end
|
95
101
|
|
96
102
|
spec 'when methods are defined in the DSL instance, they are available in the spec body' do
|
97
|
-
path =
|
103
|
+
path = testdir.join('method_spec')
|
98
104
|
|
99
105
|
output = capture do
|
100
|
-
exec "bin/uspec #{path}"
|
106
|
+
exec "#{root}/bin/uspec #{path}"
|
101
107
|
end
|
102
108
|
|
103
109
|
output.include?('1 successful') || output
|
data/uspec/stats_spec.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require_relative 'uspec_helper'
|
2
2
|
|
3
3
|
spec 'stats can be inspected' do
|
4
|
-
actual = @
|
4
|
+
actual = @__uspec_harness.stats.inspect
|
5
5
|
actual.include?("failure") || actual
|
6
6
|
end
|
7
7
|
|
8
8
|
spec 'stats inspect does not have any stray whitespace' do
|
9
|
-
output = @
|
10
|
-
match = output.match(
|
11
|
-
match == nil
|
9
|
+
output = @__uspec_harness.stats.inspect
|
10
|
+
match = output.match /(.*(?: |\n))/m
|
11
|
+
match == nil || match
|
12
12
|
end
|
@@ -6,22 +6,21 @@ THISDIR="$(realpath "$(dirname "$0")")"
|
|
6
6
|
ROOTDIR="$(realpath "$THISDIR/../..")"
|
7
7
|
|
8
8
|
path="$1"
|
9
|
-
name="$(basename "$path")"
|
10
9
|
|
11
10
|
if ! [ -f "$path" ]; then
|
12
11
|
echo "file not found: $path"
|
13
12
|
exit 255
|
14
13
|
fi
|
15
14
|
|
16
|
-
mkdir -v -p tmp
|
17
15
|
if command_exists bundle; then
|
18
|
-
|
16
|
+
echo running with bundler
|
17
|
+
bundle exec "$ROOTDIR/bin/uspec" "$path" 2>&1 &
|
18
|
+
pid="$!"
|
19
19
|
else
|
20
|
-
|
20
|
+
echo running directly
|
21
|
+
"$ROOTDIR/bin/uspec" "$path" 2>&1 &
|
22
|
+
pid="$!"
|
21
23
|
fi
|
22
24
|
|
23
|
-
pid=$!
|
24
25
|
sleep 1
|
25
|
-
kill $pid
|
26
|
-
cat "tmp/$name.output"
|
27
|
-
rm -v "tmp/$name.output"
|
26
|
+
kill "$pid"
|
data/uspec/uspec_helper.rb
CHANGED
@@ -4,6 +4,7 @@ rescue LoadError => err
|
|
4
4
|
nil
|
5
5
|
end
|
6
6
|
require 'open3'
|
7
|
+
require 'stringio'
|
7
8
|
|
8
9
|
require_relative '../lib/uspec'
|
9
10
|
extend Uspec
|
@@ -24,3 +25,37 @@ def capture
|
|
24
25
|
|
25
26
|
output
|
26
27
|
end
|
28
|
+
|
29
|
+
def outstr
|
30
|
+
old_stdout = $stdout
|
31
|
+
old_stderr = $stderr
|
32
|
+
|
33
|
+
outio = StringIO.new
|
34
|
+
$stdout = outio
|
35
|
+
|
36
|
+
errio = StringIO.new
|
37
|
+
$stderr = errio
|
38
|
+
|
39
|
+
val = yield
|
40
|
+
|
41
|
+
outio.string + errio.string
|
42
|
+
ensure
|
43
|
+
$stdout = old_stdout
|
44
|
+
$stderr = old_stderr
|
45
|
+
end
|
46
|
+
|
47
|
+
def root
|
48
|
+
Pathname.new(__FILE__).parent.parent
|
49
|
+
end
|
50
|
+
|
51
|
+
def exdir
|
52
|
+
root.join('example_specs')
|
53
|
+
end
|
54
|
+
|
55
|
+
def specdir
|
56
|
+
root.join('uspec')
|
57
|
+
end
|
58
|
+
|
59
|
+
def testdir
|
60
|
+
specdir.join('test_specs')
|
61
|
+
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.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony M. Cook
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: that_object_is_so_basic
|
@@ -49,7 +49,8 @@ files:
|
|
49
49
|
- example_specs/spec_helper.rb
|
50
50
|
- lib/uspec.rb
|
51
51
|
- lib/uspec/cli.rb
|
52
|
-
- lib/uspec/
|
52
|
+
- lib/uspec/define.rb
|
53
|
+
- lib/uspec/harness.rb
|
53
54
|
- lib/uspec/result.rb
|
54
55
|
- lib/uspec/spec.rb
|
55
56
|
- lib/uspec/stats.rb
|