uspec 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +14 -2
- data/README.markdown +134 -36
- data/bin/uspec +9 -0
- data/lib/uspec.rb +1 -1
- data/lib/uspec/dsl.rb +1 -0
- data/lib/uspec/exec.rb +51 -0
- data/lib/uspec/stats.rb +2 -1
- data/lib/uspec/version.rb +1 -1
- data/uspec/exec_spec.rb +27 -0
- data/uspec/uspec_helper.rb +20 -0
- data/uspec/uspec_spec.rb +25 -18
- metadata +18 -12
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f6a6363a2a59ed141811ddbd906b6a47a1494a0b
|
4
|
+
data.tar.gz: 5d21b182f77d0d4101d4a4236775e527aa05972d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 28cd24aed39ea930141a5f0e72ed86c02221610ab610d8b8359e46d4002898b578a554bbf903b5f524e9552edf441f559ce004c356b4abd259215d3720f8df6b
|
7
|
+
data.tar.gz: e54033546d92f8f89651e49df226c293d973952d77d4fd6d9bda32fb3f8f876d6d54cd14e7f7306ca266f6d83d9812f3d7ca9d036c8a7e3baa8fa25e5549df56
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
uspec
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.2.3
|
data/.travis.yml
CHANGED
@@ -1,11 +1,23 @@
|
|
1
1
|
language: ruby
|
2
|
+
|
2
3
|
rvm:
|
4
|
+
- 2.2.3
|
5
|
+
- 2.0.0
|
3
6
|
- 1.9.3
|
4
7
|
- 1.9.2
|
5
|
-
|
8
|
+
|
9
|
+
- jruby-19mode
|
6
10
|
- ruby-head
|
7
|
-
|
11
|
+
|
8
12
|
before_install:
|
9
13
|
- gem update bundler
|
10
14
|
before_script:
|
11
15
|
- bundle exec gem list
|
16
|
+
script: bundle exec uspec
|
17
|
+
|
18
|
+
matrix:
|
19
|
+
allow_failures:
|
20
|
+
- rvm: ruby-head
|
21
|
+
- rvm: jruby-19mode
|
22
|
+
|
23
|
+
sudo: false
|
data/README.markdown
CHANGED
@@ -3,34 +3,76 @@ Uspec
|
|
3
3
|
|
4
4
|
Uspec is a shiny little testing framework for your apps!
|
5
5
|
|
6
|
-
Anthony M. Cook 2013
|
7
|
-
|
8
6
|
[![Build Status](https://travis-ci.org/acook/uspec.png?branch=master)](https://travis-ci.org/acook/uspec)
|
9
7
|
[![Code Climate](https://codeclimate.com/github/acook/uspec.png)](https://codeclimate.com/github/acook/uspec)
|
10
|
-
[![Still Maintained](http://stillmaintained.com/acook/uspec.png)](http://stillmaintained.com/acook/uspec)
|
11
8
|
|
12
9
|
Philosophy / Why Uspec?
|
13
10
|
-----------------------
|
14
11
|
|
15
|
-
|
12
|
+
> Uspec is just Ruby!
|
13
|
+
|
14
|
+
Unlike other testing frameworks there's no need for special matchers,
|
15
|
+
there can only be one assertion per test,
|
16
|
+
and you never have to worry that your tests lack assertions.
|
17
|
+
|
18
|
+
That's because when the `spec` block is evaluated the return value is used (in a very ruby-like way)
|
19
|
+
to determine the validity of the statement. Standard Ruby comparisons are your friend!
|
20
|
+
No more digging around in your test framework's documentation to figure out what matcher you're supposed to use.
|
21
|
+
This also means *no monkey patching* core classes!
|
22
|
+
|
23
|
+
Uspec's output is in beautiful ansi technicolor,
|
24
|
+
with red for failures, green for successes, and yellow for pending specs. Here's a screenshot:
|
25
|
+
|
26
|
+
![Screenshot!](http://i.imgur.com/M2F5YvO.png)
|
27
|
+
|
28
|
+
Uspec is tiny, painless, and easy to use. Download it and give it a shot. :)
|
29
|
+
|
30
|
+
Installation
|
31
|
+
------------
|
32
|
+
|
33
|
+
Add this line to your application's Gemfile:
|
34
|
+
|
35
|
+
gem 'uspec'
|
36
|
+
|
37
|
+
And then execute:
|
38
|
+
|
39
|
+
$ bundle
|
40
|
+
|
41
|
+
Or install it yourself as:
|
42
|
+
|
43
|
+
$ gem install uspec
|
44
|
+
|
45
|
+
|
46
|
+
Quickstart
|
47
|
+
----------
|
16
48
|
|
17
|
-
|
49
|
+
0. Create a `spec` directory to keep your specs in.
|
50
|
+
1. Name your specs ending with `_spec.rb`.
|
51
|
+
2. Write some specs in Ruby using the `spec` method.
|
52
|
+
2. Use the included `uspec` executable to run your specs.
|
18
53
|
|
19
|
-
|
54
|
+
**Hint:** A lot of people also put `require_relative 'spec_helper'` in their tests for global start up code.
|
20
55
|
|
21
56
|
Usage
|
22
57
|
-----
|
23
58
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
extend Uspec
|
59
|
+
```
|
60
|
+
$ uspec --help
|
61
|
+
uspec - minimalistic ruby testing framework
|
62
|
+
usage: uspec [<file_or_path>...]
|
29
63
|
```
|
30
64
|
|
31
|
-
|
65
|
+
- Without arguments the `uspec` command will automatially look for `spec` directories and load any `*_spec.rb` files inside them.
|
66
|
+
- You can also pass in arbitrary files and it will attempt to run them as specs.
|
67
|
+
- If you pass in directories `uspec` will find and run any specs inside them.
|
68
|
+
- Uspec will return `0` if all specs pass and `255` if any fail.
|
69
|
+
|
70
|
+
Syntax
|
71
|
+
------
|
32
72
|
|
33
|
-
|
73
|
+
Uspec is **just Ruby**. The DSL is minimal - there's only one method to remember!
|
74
|
+
|
75
|
+
Writing a spec is easy:
|
34
76
|
|
35
77
|
```ruby
|
36
78
|
spec 'AwesomeMcCoolname.generate creates a cool name' do
|
@@ -38,19 +80,32 @@ spec 'AwesomeMcCoolname.generate creates a cool name' do
|
|
38
80
|
end
|
39
81
|
```
|
40
82
|
|
41
|
-
|
83
|
+
That's it!
|
84
|
+
|
85
|
+
Output
|
86
|
+
------
|
87
|
+
|
88
|
+
Examples of Uspec's output below!
|
89
|
+
|
90
|
+
### Success
|
91
|
+
|
92
|
+
If a spec passes:
|
42
93
|
|
43
94
|
```
|
44
95
|
-- AwesomeMcCoolname.generate creates a cool name: true
|
45
96
|
```
|
46
97
|
|
47
|
-
|
98
|
+
### Failure
|
99
|
+
|
100
|
+
If a spec fails:
|
48
101
|
|
49
102
|
```
|
50
103
|
-- AwesomeMcCoolname.generate creates a cool name: false
|
51
104
|
```
|
52
105
|
|
53
|
-
|
106
|
+
### Exception
|
107
|
+
|
108
|
+
If the spec throws an error:
|
54
109
|
|
55
110
|
```
|
56
111
|
-- AwesomeMcCoolname.generate creates a cool name: Exception
|
@@ -64,6 +119,8 @@ If it throws an error:
|
|
64
119
|
uspec/awesome_mc_coolname_spec.rb:4:in `block in <main>'
|
65
120
|
```
|
66
121
|
|
122
|
+
### Non-boolean values
|
123
|
+
|
67
124
|
If you create a spec that doesn't return a boolean value (`nil` doesn't count either!) like this:
|
68
125
|
|
69
126
|
```ruby
|
@@ -83,7 +140,28 @@ Then Uspec will let you know:
|
|
83
140
|
Integer < Numeric: 5
|
84
141
|
```
|
85
142
|
|
86
|
-
|
143
|
+
### Pending
|
144
|
+
|
145
|
+
If you aren't ready to fill out a spec, maybe as a reminder to add functionality later, just leave off the block and it will be marked as `pending`:
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
spec 'a feature I have not implemented yet'
|
149
|
+
```
|
150
|
+
|
151
|
+
When you run the test Uspec will helpfully display:
|
152
|
+
|
153
|
+
```
|
154
|
+
-- a feature I have not implemented yet: pending
|
155
|
+
```
|
156
|
+
|
157
|
+
Tips & Tricks
|
158
|
+
-------------
|
159
|
+
|
160
|
+
Because there's no matchers and only one method there's no reference documentation to look at, so here are some ideas to get you going!
|
161
|
+
|
162
|
+
### String matching
|
163
|
+
|
164
|
+
Instead of `=~` (which returns either an `Integer` index or `nil`) Ruby has the nifty `include?` method, which returns a boolean:
|
87
165
|
|
88
166
|
```ruby
|
89
167
|
spec 'AwesomeMcCoolname.generate creates a cool name' do
|
@@ -91,6 +169,8 @@ spec 'AwesomeMcCoolname.generate creates a cool name' do
|
|
91
169
|
end
|
92
170
|
```
|
93
171
|
|
172
|
+
### Regex matching
|
173
|
+
|
94
174
|
If you really need to regex, you can always use Ruby's `!!` idiom to coerce a boolean out of any result,
|
95
175
|
but its more precise to specify the index if you know it.
|
96
176
|
And you can always toss in an `||` to drop in more information if a comparison fails too:
|
@@ -102,17 +182,7 @@ spec 'AwesomeMcCoolname.generate creates a cool name' do
|
|
102
182
|
end
|
103
183
|
```
|
104
184
|
|
105
|
-
|
106
|
-
|
107
|
-
```ruby
|
108
|
-
spec 'a feature I have not implemented yet'
|
109
|
-
```
|
110
|
-
|
111
|
-
When you run the test Uspec will helpfully display:
|
112
|
-
|
113
|
-
```
|
114
|
-
-- a feature I have not implemented yet: pending
|
115
|
-
```
|
185
|
+
### Exceptions
|
116
186
|
|
117
187
|
What if you want to test that an error has occured? Just use Ruby!
|
118
188
|
|
@@ -130,20 +200,43 @@ If there's no error, then Uspec will see the result of the method call (whatever
|
|
130
200
|
If the wrong Exception is raised, then because of reraising (by just calling `raise` without parameters),
|
131
201
|
Ruby will dutifully pass along the error for Uspec to display.
|
132
202
|
|
133
|
-
|
134
|
-
|
203
|
+
Assertions & Debugging
|
204
|
+
----------------------
|
135
205
|
|
136
|
-
|
206
|
+
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.
|
137
207
|
|
138
|
-
|
208
|
+
You can load Uspec's features directly into a class and use its DSL:
|
139
209
|
|
140
|
-
|
210
|
+
```ruby
|
211
|
+
require 'uspec'
|
141
212
|
|
142
|
-
|
213
|
+
class MyFoo
|
214
|
+
extend Uspec::DSL
|
215
|
+
|
216
|
+
def assert
|
217
|
+
spec 'foo is valid' do
|
218
|
+
false
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
143
222
|
|
144
|
-
|
223
|
+
MyFoo.new.assert
|
224
|
+
```
|
145
225
|
|
146
|
-
|
226
|
+
If there are any specs that fail, your application will exit with a `255``.
|
227
|
+
|
228
|
+
```
|
229
|
+
$ ruby foo.rb
|
230
|
+
-- foo is valid: false
|
231
|
+
$ echo $?
|
232
|
+
255
|
233
|
+
```
|
234
|
+
|
235
|
+
Uspec is just Ruby
|
236
|
+
------------------
|
237
|
+
|
238
|
+
If for some reason you don't want to use the `uspec` command, you can `require 'uspec'` and `extend Uspec::DSL`.
|
239
|
+
From there you can just run the file with ruby: `ruby my_test_spec.rb`
|
147
240
|
|
148
241
|
Contributing
|
149
242
|
------------
|
@@ -153,3 +246,8 @@ Contributing
|
|
153
246
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
154
247
|
4. Push to the branch (`git push origin my-new-feature`)
|
155
248
|
5. Create new Pull Request
|
249
|
+
|
250
|
+
Author
|
251
|
+
------
|
252
|
+
|
253
|
+
> Anthony M. Cook 2013-2016
|
data/bin/uspec
ADDED
data/lib/uspec.rb
CHANGED
data/lib/uspec/dsl.rb
CHANGED
data/lib/uspec/exec.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require_relative '../uspec'
|
3
|
+
|
4
|
+
class Uspec::Exec
|
5
|
+
class << self
|
6
|
+
def usage
|
7
|
+
warn "uspec - minimalistic ruby testing framework"
|
8
|
+
warn "usage: #{File.basename $0} [<file_or_path>...]"
|
9
|
+
end
|
10
|
+
|
11
|
+
def run_specs paths
|
12
|
+
uspec_exec = self.new paths
|
13
|
+
uspec_exec.run_paths
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize paths
|
18
|
+
@paths = paths
|
19
|
+
@pwd = Pathname.pwd.freeze
|
20
|
+
end
|
21
|
+
|
22
|
+
def paths
|
23
|
+
if @paths.empty? then
|
24
|
+
['spec', 'uspec', 'test'].each do |path|
|
25
|
+
@paths << path if Pathname.new(path).directory?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
@paths
|
30
|
+
end
|
31
|
+
|
32
|
+
def run_paths
|
33
|
+
paths.each do |path|
|
34
|
+
run @pwd.join path
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def run path
|
39
|
+
if path.directory? then
|
40
|
+
Pathname.glob(path.join('**', '**_spec.rb')).each do |spec|
|
41
|
+
run spec
|
42
|
+
end
|
43
|
+
elsif path.exist? then
|
44
|
+
puts "#{path.basename path.extname}:"
|
45
|
+
Uspec::DSL.instance_eval(path.read, path.to_s)
|
46
|
+
else
|
47
|
+
warn "path not found: #{path}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
data/lib/uspec/stats.rb
CHANGED
data/lib/uspec/version.rb
CHANGED
data/uspec/exec_spec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'uspec_helper'
|
2
|
+
|
3
|
+
spec 'shows usage' do
|
4
|
+
output = capture do
|
5
|
+
exec 'bin/uspec -h'
|
6
|
+
end
|
7
|
+
|
8
|
+
output.include? 'usage'
|
9
|
+
end
|
10
|
+
|
11
|
+
spec 'runs a path of specs' do
|
12
|
+
output = capture do
|
13
|
+
path = Pathname.new(__FILE__).parent.parent.join('example_specs').to_s
|
14
|
+
Uspec::Exec.run_specs Array(path)
|
15
|
+
end
|
16
|
+
|
17
|
+
output.include? 'I love passing tests'
|
18
|
+
end
|
19
|
+
|
20
|
+
spec 'runs an individual spec' do
|
21
|
+
output = capture do
|
22
|
+
path = Pathname.new(__FILE__).parent.parent.join('example_specs', 'example_spec.rb').to_s
|
23
|
+
Uspec::Exec.run_specs Array(path)
|
24
|
+
end
|
25
|
+
|
26
|
+
output.include? 'I love passing tests'
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative '../lib/uspec'
|
2
|
+
extend Uspec
|
3
|
+
|
4
|
+
def capture
|
5
|
+
readme, writeme = IO.pipe
|
6
|
+
pid = fork do
|
7
|
+
$stdout.reopen writeme
|
8
|
+
$stderr.reopen writeme
|
9
|
+
readme.close
|
10
|
+
|
11
|
+
yield
|
12
|
+
end
|
13
|
+
|
14
|
+
writeme.close
|
15
|
+
output = readme.read
|
16
|
+
Process.waitpid(pid)
|
17
|
+
|
18
|
+
output
|
19
|
+
end
|
20
|
+
|
data/uspec/uspec_spec.rb
CHANGED
@@ -1,21 +1,4 @@
|
|
1
|
-
require_relative '
|
2
|
-
extend Uspec
|
3
|
-
|
4
|
-
def capture
|
5
|
-
readme, writeme = IO.pipe
|
6
|
-
pid = fork do
|
7
|
-
$stdout.reopen writeme
|
8
|
-
readme.close
|
9
|
-
|
10
|
-
yield
|
11
|
-
end
|
12
|
-
|
13
|
-
writeme.close
|
14
|
-
output = readme.read
|
15
|
-
Process.waitpid(pid)
|
16
|
-
|
17
|
-
output
|
18
|
-
end
|
1
|
+
require_relative 'uspec_helper'
|
19
2
|
|
20
3
|
spec 'catches errors' do
|
21
4
|
output = capture do
|
@@ -48,3 +31,27 @@ end
|
|
48
31
|
spec 'should not define DSL methods on arbitrary objects' do
|
49
32
|
!(Array.respond_to? :spec)
|
50
33
|
end
|
34
|
+
|
35
|
+
spec 'exit code is the number of failures' do
|
36
|
+
capture do
|
37
|
+
50.times do
|
38
|
+
spec 'fail' do
|
39
|
+
false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
$?.exitstatus == 50 || $?
|
45
|
+
end
|
46
|
+
|
47
|
+
spec 'if more than 255 failures, exit status is 255' do
|
48
|
+
capture do
|
49
|
+
500.times do
|
50
|
+
spec 'fail' do
|
51
|
+
false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
$?.exitstatus == 255 || $?
|
57
|
+
end
|
metadata
CHANGED
@@ -1,62 +1,68 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Anthony Cook
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-12-22 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: Uspec is a shiny little spec framework for your apps! Unlike other testing
|
15
14
|
frameworks there's no need for matchers, there can only be one assertion per test,
|
16
15
|
and you never have to worry that your tests lack assertions.
|
17
16
|
email:
|
18
17
|
- anthonymichaelcook@gmail.com
|
19
|
-
executables:
|
18
|
+
executables:
|
19
|
+
- uspec
|
20
20
|
extensions: []
|
21
21
|
extra_rdoc_files: []
|
22
22
|
files:
|
23
|
-
- .gitignore
|
24
|
-
- .
|
23
|
+
- ".gitignore"
|
24
|
+
- ".ruby-gemset"
|
25
|
+
- ".ruby-version"
|
26
|
+
- ".travis.yml"
|
25
27
|
- Gemfile
|
26
28
|
- LICENSE.txt
|
27
29
|
- README.markdown
|
28
30
|
- Rakefile
|
31
|
+
- bin/uspec
|
29
32
|
- example_specs/example_spec.rb
|
30
33
|
- example_specs/spec_helper.rb
|
31
34
|
- lib/uspec.rb
|
32
35
|
- lib/uspec/dsl.rb
|
36
|
+
- lib/uspec/exec.rb
|
33
37
|
- lib/uspec/formatter.rb
|
34
38
|
- lib/uspec/stats.rb
|
35
39
|
- lib/uspec/version.rb
|
36
40
|
- uspec.gemspec
|
41
|
+
- uspec/exec_spec.rb
|
42
|
+
- uspec/uspec_helper.rb
|
37
43
|
- uspec/uspec_spec.rb
|
38
44
|
homepage: http://github.com/acook/uspec#readme
|
39
45
|
licenses: []
|
46
|
+
metadata: {}
|
40
47
|
post_install_message:
|
41
48
|
rdoc_options: []
|
42
49
|
require_paths:
|
43
50
|
- lib
|
44
51
|
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
-
none: false
|
46
52
|
requirements:
|
47
|
-
- -
|
53
|
+
- - ">="
|
48
54
|
- !ruby/object:Gem::Version
|
49
55
|
version: '0'
|
50
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
-
none: false
|
52
57
|
requirements:
|
53
|
-
- -
|
58
|
+
- - ">="
|
54
59
|
- !ruby/object:Gem::Version
|
55
60
|
version: '0'
|
56
61
|
requirements: []
|
57
62
|
rubyforge_project:
|
58
|
-
rubygems_version:
|
63
|
+
rubygems_version: 2.6.8
|
59
64
|
signing_key:
|
60
|
-
specification_version:
|
65
|
+
specification_version: 4
|
61
66
|
summary: a shiny little spec framework for your apps!
|
62
67
|
test_files: []
|
68
|
+
has_rdoc:
|