wrong 0.6.0 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +20 -2
- data/lib/wrong/assert.rb +12 -1
- data/lib/wrong/chunk.rb +2 -4
- data/lib/wrong/version.rb +1 -1
- data/test/adapters/rspec_test.rb +6 -3
- data/test/adapters/test_unit_test.rb +1 -1
- data/test/verbose_test.rb +66 -0
- metadata +62 -20
data/README.markdown
CHANGED
@@ -4,7 +4,9 @@
|
|
4
4
|
|
5
5
|
## Abstract ##
|
6
6
|
|
7
|
-
Wrong provides a general assert method that takes a
|
7
|
+
Wrong provides a simple, general assert method that takes a block, and understands the code inside it, providing verbose failure messages for free.
|
8
|
+
|
9
|
+
The Wrong idea is to replace `assert_equal` and all those countless `assert\_this`, `assert\_that`, `should\_something` library methods which only exist to give a failure message that's not simply "assertion failed". Wrong replaces all of them in one fell swoop, since if you can write it in Ruby, Wrong can make a sensible failure message out of it.
|
8
10
|
|
9
11
|
We'd very much appreciate feedback and bug reports. There are plenty of things left to be done to make the results look uniformly clean and beautiful. We want your feedback, and especially to give us cases where either it blows up or the output is ugly or uninformative.
|
10
12
|
|
@@ -113,7 +115,11 @@ Remember, if you want `d` to work at runtime (e.g. in a webapp) then you must `i
|
|
113
115
|
|
114
116
|
### eventually
|
115
117
|
|
116
|
-
If you care that something is going to be true *soon*, but maybe not *right* now, use `eventually`.
|
118
|
+
If you care that something is going to be true *soon*, but maybe not *right* now, use `eventually`.
|
119
|
+
|
120
|
+
eventually { night? }
|
121
|
+
|
122
|
+
It will keep executing the block, up to 4 times a second, until either
|
117
123
|
|
118
124
|
* the block returns true(ish)
|
119
125
|
* 5 seconds elapse
|
@@ -428,6 +434,18 @@ Here are some suggestions:
|
|
428
434
|
|
429
435
|
Just don't use "`aver`" since we took that one for an internal method in `Wrong::Assert`.
|
430
436
|
|
437
|
+
### Verbose ###
|
438
|
+
|
439
|
+
Wrong works inside frameworks like Test::Unit and RSpec, but sometimes you just want to stick a bunch of assertions in a file and run it. In that case, *verbose mode* might come in handy. It prints every *successful* assertion to the console (including explanations, if provided, and in color, if desired).
|
440
|
+
|
441
|
+
Wrong.config.verbose
|
442
|
+
assert("basic math") { 2 + 2 == 4}
|
443
|
+
|
444
|
+
prints
|
445
|
+
|
446
|
+
basic math: ((2 + 2) == 4)
|
447
|
+
|
448
|
+
|
431
449
|
## Helper Assert Methods ##
|
432
450
|
|
433
451
|
If you really want to, you can define your proc in one method, pass it in to another method, and have that method assert it. This is a challenge for Wrong and you probably shouldn't do it. Wrong will do its best to figure out where the actual assertion code is but it might not succeed.
|
data/lib/wrong/assert.rb
CHANGED
@@ -6,6 +6,7 @@ require "wrong/chunk"
|
|
6
6
|
require "wrong/config"
|
7
7
|
require "wrong/failure_message"
|
8
8
|
require "wrong/ruby2ruby_patch" # need to patch it after some other stuff loads
|
9
|
+
require "wrong/rainbow"
|
9
10
|
|
10
11
|
module Wrong
|
11
12
|
module Assert
|
@@ -65,7 +66,17 @@ module Wrong
|
|
65
66
|
|
66
67
|
value = block.call
|
67
68
|
value = !value if valence == :deny
|
68
|
-
|
69
|
+
if value
|
70
|
+
if Wrong.config[:verbose]
|
71
|
+
code = Wrong::Chunk.from_block(block, depth + 2).code
|
72
|
+
if Wrong.config[:color]
|
73
|
+
explanation = explanation.color(:blue) if explanation
|
74
|
+
code = code.color(:green)
|
75
|
+
end
|
76
|
+
message = "#{explanation + ": " if explanation}#{code}"
|
77
|
+
puts message
|
78
|
+
end
|
79
|
+
else
|
69
80
|
chunk = Wrong::Chunk.from_block(block, depth + 2)
|
70
81
|
|
71
82
|
message = FailureMessage.new(chunk, valence, explanation).full
|
data/lib/wrong/chunk.rb
CHANGED
@@ -6,7 +6,8 @@ def require_optionally(library)
|
|
6
6
|
begin
|
7
7
|
require library
|
8
8
|
rescue LoadError => e
|
9
|
-
raise e unless e.message == "no such file to load -- #{library}"
|
9
|
+
raise e unless e.message == "no such file to load -- #{library}" or
|
10
|
+
e.message == "cannot load such file -- #{library}" # 1.9.3 changed the error message
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
@@ -27,10 +28,7 @@ module Wrong
|
|
27
28
|
as_proc.source_location
|
28
29
|
else
|
29
30
|
# in Ruby 1.8, it reads the source location from the call stack
|
30
|
-
# # $stderr.puts "---"
|
31
|
-
# $stderr.puts caller.join("\n")
|
32
31
|
relevant_caller = caller[depth]
|
33
|
-
# $stderr.puts "*** #{relevant_caller}"
|
34
32
|
relevant_caller.split(":")
|
35
33
|
end
|
36
34
|
|
data/lib/wrong/version.rb
CHANGED
data/test/adapters/rspec_test.rb
CHANGED
@@ -5,6 +5,7 @@ require "fileutils"
|
|
5
5
|
|
6
6
|
require "./test/test_helper"
|
7
7
|
require "wrong/adapters/minitest"
|
8
|
+
require "bundler"
|
8
9
|
|
9
10
|
include Wrong
|
10
11
|
|
@@ -31,10 +32,12 @@ describe "testing rspec" do
|
|
31
32
|
assert { line =~ /rspec[-\w]* \(#{rspec_version}\.[\w.]*\)/ }
|
32
33
|
end
|
33
34
|
end
|
34
|
-
|
35
|
-
|
35
|
+
|
36
|
+
Bundler.with_clean_env do
|
37
|
+
spec_output = sys "ruby #{dir}/failing_spec.rb",
|
36
38
|
(rspec_version == 1 || RUBY_VERSION =~ /^1\.8\./ || RUBY_VERSION == '1.9.1' ? nil : 1) # RSpec v1 exits with 0 on failure :-(
|
37
|
-
|
39
|
+
end
|
40
|
+
end
|
38
41
|
|
39
42
|
assert { spec_output.include? "1 failure" }
|
40
43
|
assert { spec_output.include? "Expected ((2 + 2) == 5), but" }
|
@@ -0,0 +1,66 @@
|
|
1
|
+
here = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require "#{here}/test_helper"
|
4
|
+
require "wrong/assert"
|
5
|
+
require "wrong/helpers"
|
6
|
+
require "wrong/d"
|
7
|
+
require "wrong/rainbow"
|
8
|
+
|
9
|
+
describe "verbose assert" do
|
10
|
+
|
11
|
+
include Wrong::Helpers
|
12
|
+
include Wrong::D
|
13
|
+
|
14
|
+
before do
|
15
|
+
@m = Module.new do
|
16
|
+
extend Wrong::Assert
|
17
|
+
end
|
18
|
+
Wrong.config.verbose
|
19
|
+
@color_enabled = Sickill::Rainbow.enabled
|
20
|
+
end
|
21
|
+
|
22
|
+
after do
|
23
|
+
Wrong.config[:verbose] = nil
|
24
|
+
Wrong.config[:color] = nil
|
25
|
+
Sickill::Rainbow.enabled = @color_enabled
|
26
|
+
end
|
27
|
+
|
28
|
+
it "sets the verbose flag" do
|
29
|
+
assert Wrong.config[:verbose]
|
30
|
+
end
|
31
|
+
|
32
|
+
it "prints the contents of a successful assert" do
|
33
|
+
out = capturing {
|
34
|
+
@m.assert { 2 + 2 == 4 }
|
35
|
+
}
|
36
|
+
assert_equal "((2 + 2) == 4)\n", out
|
37
|
+
end
|
38
|
+
|
39
|
+
it "prints the message and contents of a successful assert" do
|
40
|
+
out = capturing {
|
41
|
+
@m.assert("basic math") { 2 + 2 == 4 }
|
42
|
+
}
|
43
|
+
assert_equal "basic math: ((2 + 2) == 4)\n", out
|
44
|
+
end
|
45
|
+
|
46
|
+
it "prints in color" do
|
47
|
+
Wrong.config.color
|
48
|
+
Sickill::Rainbow.enabled = true
|
49
|
+
out = capturing {
|
50
|
+
@m.assert { 2 + 2 == 4 }
|
51
|
+
}
|
52
|
+
colored = ["((2 + 2) == 4)".color(:green), "\n"].join
|
53
|
+
assert_equal colored, out
|
54
|
+
end
|
55
|
+
|
56
|
+
it "prints in color with an explanation" do
|
57
|
+
Wrong.config.color
|
58
|
+
Sickill::Rainbow.enabled = true
|
59
|
+
out = capturing {
|
60
|
+
@m.assert("basic math") { 2 + 2 == 4 }
|
61
|
+
}
|
62
|
+
colored = ["basic math".color(:blue), ": ", "((2 + 2) == 4)".color(:green), "\n"].join
|
63
|
+
assert_equal colored, out
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wrong
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2012-03-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: predicated
|
17
|
-
requirement:
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,15 @@ dependencies:
|
|
22
22
|
version: 0.2.3
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements:
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 0.2.3
|
26
31
|
- !ruby/object:Gem::Dependency
|
27
32
|
name: ruby_parser
|
28
|
-
requirement:
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
29
34
|
none: false
|
30
35
|
requirements:
|
31
36
|
- - ~>
|
@@ -33,10 +38,15 @@ dependencies:
|
|
33
38
|
version: 2.0.4
|
34
39
|
type: :runtime
|
35
40
|
prerelease: false
|
36
|
-
version_requirements:
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.0.4
|
37
47
|
- !ruby/object:Gem::Dependency
|
38
48
|
name: ruby2ruby
|
39
|
-
requirement:
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
40
50
|
none: false
|
41
51
|
requirements:
|
42
52
|
- - ~>
|
@@ -44,10 +54,15 @@ dependencies:
|
|
44
54
|
version: '1.2'
|
45
55
|
type: :runtime
|
46
56
|
prerelease: false
|
47
|
-
version_requirements:
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.2'
|
48
63
|
- !ruby/object:Gem::Dependency
|
49
64
|
name: sexp_processor
|
50
|
-
requirement:
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
51
66
|
none: false
|
52
67
|
requirements:
|
53
68
|
- - ~>
|
@@ -55,10 +70,15 @@ dependencies:
|
|
55
70
|
version: '3.0'
|
56
71
|
type: :runtime
|
57
72
|
prerelease: false
|
58
|
-
version_requirements:
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ~>
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '3.0'
|
59
79
|
- !ruby/object:Gem::Dependency
|
60
80
|
name: diff-lcs
|
61
|
-
requirement:
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
62
82
|
none: false
|
63
83
|
requirements:
|
64
84
|
- - ~>
|
@@ -66,10 +86,15 @@ dependencies:
|
|
66
86
|
version: 1.1.2
|
67
87
|
type: :runtime
|
68
88
|
prerelease: false
|
69
|
-
version_requirements:
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ~>
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 1.1.2
|
70
95
|
- !ruby/object:Gem::Dependency
|
71
96
|
name: ParseTree
|
72
|
-
requirement:
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
73
98
|
none: false
|
74
99
|
requirements:
|
75
100
|
- - ~>
|
@@ -77,10 +102,15 @@ dependencies:
|
|
77
102
|
version: '3.0'
|
78
103
|
type: :runtime
|
79
104
|
prerelease: false
|
80
|
-
version_requirements:
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
81
111
|
- !ruby/object:Gem::Dependency
|
82
112
|
name: sourcify
|
83
|
-
requirement:
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
84
114
|
none: false
|
85
115
|
requirements:
|
86
116
|
- - ! '>='
|
@@ -88,10 +118,15 @@ dependencies:
|
|
88
118
|
version: 0.3.0
|
89
119
|
type: :runtime
|
90
120
|
prerelease: false
|
91
|
-
version_requirements:
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: 0.3.0
|
92
127
|
- !ruby/object:Gem::Dependency
|
93
128
|
name: file-tail
|
94
|
-
requirement:
|
129
|
+
requirement: !ruby/object:Gem::Requirement
|
95
130
|
none: false
|
96
131
|
requirements:
|
97
132
|
- - ~>
|
@@ -99,7 +134,12 @@ dependencies:
|
|
99
134
|
version: '1.0'
|
100
135
|
type: :runtime
|
101
136
|
prerelease: false
|
102
|
-
version_requirements:
|
137
|
+
version_requirements: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ~>
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '1.0'
|
103
143
|
description: ! 'Wrong provides a general assert method that takes a predicate block.
|
104
144
|
Assertion failure
|
105
145
|
|
@@ -184,6 +224,7 @@ files:
|
|
184
224
|
- test/string_comparison_test.rb
|
185
225
|
- test/suite.rb
|
186
226
|
- test/test_helper.rb
|
227
|
+
- test/verbose_test.rb
|
187
228
|
- test/wrong_test.rb
|
188
229
|
homepage: http://github.com/sconover/wrong
|
189
230
|
licenses: []
|
@@ -199,7 +240,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
199
240
|
version: '0'
|
200
241
|
segments:
|
201
242
|
- 0
|
202
|
-
hash: -
|
243
|
+
hash: -1208132037524365010
|
203
244
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
204
245
|
none: false
|
205
246
|
requirements:
|
@@ -208,7 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
208
249
|
version: '0'
|
209
250
|
requirements: []
|
210
251
|
rubyforge_project: wrong
|
211
|
-
rubygems_version: 1.8.
|
252
|
+
rubygems_version: 1.8.21
|
212
253
|
signing_key:
|
213
254
|
specification_version: 3
|
214
255
|
summary: Wrong provides a general assert method that takes a predicate block. Assertion
|
@@ -256,4 +297,5 @@ test_files:
|
|
256
297
|
- test/string_comparison_test.rb
|
257
298
|
- test/suite.rb
|
258
299
|
- test/test_helper.rb
|
300
|
+
- test/verbose_test.rb
|
259
301
|
- test/wrong_test.rb
|