minitest-descriptive 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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in minitest-descriptive.gemspec
4
+ gemspec
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,5 @@
1
+ module MiniTest
2
+ module Descriptive
3
+ VERSION = "0.0.1"
4
+ end
5
+ 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: []