minitest-descriptive 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +107 -0
- data/Rakefile +1 -0
- data/lib/minitest-descriptive.rb +53 -0
- data/lib/minitest-descriptive/version.rb +5 -0
- data/minitest-descriptive.gemspec +21 -0
- metadata +77 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Josep M. Bach
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
# minitest-descriptive
|
2
|
+
|
3
|
+
This little plug-in makes your assertion diffs much smarter about the way you
|
4
|
+
write your tests.
|
5
|
+
|
6
|
+
Let's say you have this failing test:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
class FooTest < MiniTest::Unit::TestCase
|
10
|
+
def test_works
|
11
|
+
@right = 1
|
12
|
+
@wrong = 3
|
13
|
+
assert_equal @right, 3
|
14
|
+
end
|
15
|
+
end
|
16
|
+
```
|
17
|
+
|
18
|
+
Normally Minitest would output this:
|
19
|
+
|
20
|
+
```
|
21
|
+
1) Failure:
|
22
|
+
test_works(FooTest) [test_foo.rb:2]:
|
23
|
+
Expected: 1
|
24
|
+
Actual: 3
|
25
|
+
```
|
26
|
+
|
27
|
+
This is a simple example, but `Expected: 1` doesn't give us much information.
|
28
|
+
What did 1 mean? And what is 3??? After 6 months, you've forgotten. But then you
|
29
|
+
look at the test, "oh, 1 was `@right` and 3 was `@wrong`! of course".
|
30
|
+
|
31
|
+
With `minitest-descriptive`, your output would be like this:
|
32
|
+
|
33
|
+
```
|
34
|
+
1) Failure:
|
35
|
+
test_works(FooTest) [test_foo.rb:2]:
|
36
|
+
Expected: 1 (@right)
|
37
|
+
Actual: 3 (@wrong)
|
38
|
+
```
|
39
|
+
|
40
|
+
Much more descriptive, isn't it?
|
41
|
+
|
42
|
+
## Only instance variables? I want it to be smart about local variables too!
|
43
|
+
|
44
|
+
If you're running on [Rubinius][rubinius], `minitest-descriptive` automatically
|
45
|
+
tries to be smart about local variables too. So if we changed the test case to
|
46
|
+
use a local variable:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
class FooTest < MiniTest::Unit::TestCase
|
50
|
+
def test_works
|
51
|
+
@right = 1
|
52
|
+
wrong = 3
|
53
|
+
assert_equal @right, 3
|
54
|
+
end
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
Your output would be like this:
|
59
|
+
|
60
|
+
```
|
61
|
+
1) Failure:
|
62
|
+
test_works(FooTest) [test_foo.rb:2]:
|
63
|
+
Expected: 1 (@right)
|
64
|
+
Actual: 3 (wrong)
|
65
|
+
```
|
66
|
+
|
67
|
+
Cool eh? :)
|
68
|
+
|
69
|
+
## Installation
|
70
|
+
|
71
|
+
Add this line to your application's Gemfile:
|
72
|
+
|
73
|
+
gem 'minitest-descriptive'
|
74
|
+
|
75
|
+
And then execute:
|
76
|
+
|
77
|
+
$ bundle
|
78
|
+
|
79
|
+
Or install it yourself as:
|
80
|
+
|
81
|
+
$ gem install minitest-descriptive
|
82
|
+
|
83
|
+
And finally add this to your `test_helper.rb` file:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
require 'minitest-descriptive'
|
87
|
+
|
88
|
+
class MiniTest::Unit::TestCase
|
89
|
+
include MiniTest::Descriptive
|
90
|
+
end
|
91
|
+
```
|
92
|
+
|
93
|
+
## Contributing
|
94
|
+
|
95
|
+
1. Fork it
|
96
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
97
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
98
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
99
|
+
5. Create new Pull Request
|
100
|
+
|
101
|
+
[rubinius]: http://rubini.us
|
102
|
+
|
103
|
+
## Who's this
|
104
|
+
|
105
|
+
This was made by [Josep M. Bach (Txus)](http://txustice.me) under the MIT
|
106
|
+
license. I'm [@txustice](http://twitter.com/txustice) on twitter (where you
|
107
|
+
should probably follow me!).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "minitest-descriptive/version"
|
2
|
+
|
3
|
+
module MiniTest
|
4
|
+
module Descriptive
|
5
|
+
class DescriptiveValue < Struct.new(:name, :value)
|
6
|
+
def inspect
|
7
|
+
"#{value.inspect} (#{name})"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def diff(exp, act)
|
12
|
+
exp_name = ivar_value(exp)
|
13
|
+
act_name = ivar_value(act)
|
14
|
+
|
15
|
+
if defined?(Rubinius)
|
16
|
+
test_frame = Rubinius::VM.backtrace(0, true).detect do |loc|
|
17
|
+
loc.name =~ /^test_/
|
18
|
+
end
|
19
|
+
|
20
|
+
vs, cc, cs = test_frame.variables,
|
21
|
+
test_frame.method,
|
22
|
+
test_frame.constant_scope
|
23
|
+
exp_name ||= local_value(exp, vs, cc, cs)
|
24
|
+
act_name ||= local_value(act, vs, cc, cs)
|
25
|
+
end
|
26
|
+
|
27
|
+
super(exp_name || exp, act_name || act)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def local_value(value, vs, cc, cs)
|
33
|
+
binding = ::Binding.setup(vs, cc, cs)
|
34
|
+
|
35
|
+
cc.local_names.map do |local|
|
36
|
+
DescriptiveValue.new(local, (eval(local.to_s, binding) rescue nil))
|
37
|
+
end.detect { |value| value.value }
|
38
|
+
end
|
39
|
+
|
40
|
+
def ivar_value(value)
|
41
|
+
ivar_values.detect { |val| val.value == value }
|
42
|
+
end
|
43
|
+
|
44
|
+
def ivar_values
|
45
|
+
ivars.map { |iv| DescriptiveValue.new(iv, instance_variable_get(iv)) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def ivars
|
49
|
+
example_case = MiniTest::Unit::TestCase.new(nil)
|
50
|
+
instance_variables - example_case.instance_variables - [:@_assertions]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'minitest-descriptive/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "minitest-descriptive"
|
8
|
+
gem.version = MiniTest::Descriptive::VERSION
|
9
|
+
gem.authors = ["Josep M. Bach"]
|
10
|
+
gem.email = ["josep.m.bach@gmail.com"]
|
11
|
+
gem.description = %q{Make your assertion diffs smarter}
|
12
|
+
gem.summary = %q{Make your assertion diffs smarter}
|
13
|
+
gem.homepage = "https://github.com/txus/minitest-descriptive"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_runtime_dependency "minitest"
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: minitest-descriptive
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Josep M. Bach
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
none: false
|
21
|
+
prerelease: false
|
22
|
+
type: :runtime
|
23
|
+
name: minitest
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ! '>='
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
29
|
+
none: false
|
30
|
+
description: Make your assertion diffs smarter
|
31
|
+
email:
|
32
|
+
- josep.m.bach@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- !binary |-
|
38
|
+
LmdpdGlnbm9yZQ==
|
39
|
+
- !binary |-
|
40
|
+
R2VtZmlsZQ==
|
41
|
+
- !binary |-
|
42
|
+
TElDRU5TRS50eHQ=
|
43
|
+
- !binary |-
|
44
|
+
UkVBRE1FLm1k
|
45
|
+
- !binary |-
|
46
|
+
UmFrZWZpbGU=
|
47
|
+
- !binary |-
|
48
|
+
bGliL21pbml0ZXN0LWRlc2NyaXB0aXZlLnJi
|
49
|
+
- !binary |-
|
50
|
+
bGliL21pbml0ZXN0LWRlc2NyaXB0aXZlL3ZlcnNpb24ucmI=
|
51
|
+
- !binary |-
|
52
|
+
bWluaXRlc3QtZGVzY3JpcHRpdmUuZ2Vtc3BlYw==
|
53
|
+
homepage: https://github.com/txus/minitest-descriptive
|
54
|
+
licenses: []
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
none: false
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
none: false
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.8.24
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: Make your assertion diffs smarter
|
77
|
+
test_files: []
|