wrong 0.5.0-java → 0.5.2-java
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +80 -33
- data/lib/wrong/adapters/rspec.rb +40 -1
- data/lib/wrong/adapters/test_unit.rb +33 -0
- data/lib/wrong/assert.rb +5 -1
- data/lib/wrong/chunk.rb +5 -1
- data/lib/wrong/close_to.rb +1 -2
- data/lib/wrong/config.rb +11 -6
- data/lib/wrong/d.rb +4 -1
- data/lib/wrong/version.rb +1 -1
- data/test/adapters/rspec1/failing_spec.rb +32 -0
- data/test/adapters/rspec2/failing_spec.rb +32 -0
- data/test/adapters/rspec_test.rb +1 -1
- data/test/adapters/test_unit_test.rb +34 -5
- data/test/capturing_test.rb +7 -0
- data/test/chunk_test.rb +51 -20
- data/test/close_to_test.rb +7 -0
- data/test/d_test.rb +9 -0
- metadata +69 -92
data/README.markdown
CHANGED
@@ -8,8 +8,6 @@ Wrong provides a general assert method that takes a predicate block. Assertion f
|
|
8
8
|
|
9
9
|
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
10
|
|
11
|
-
It relies on [Predicated](http://github.com/sconover/predicated) for its main failure message.
|
12
|
-
|
13
11
|
Inspired by [assert { 2.0 }](http://assert2.rubyforge.org/) but rewritten from scratch. Compatible with Ruby (MRI) 1.8, 1.9, and JRuby 1.5.
|
14
12
|
|
15
13
|
## Installation
|
@@ -22,7 +20,7 @@ We have deployed gems for both Ruby and JRuby; if you get dependency issues on y
|
|
22
20
|
|
23
21
|
Wrong provides a simple assert method that takes a block:
|
24
22
|
|
25
|
-
require "wrong"
|
23
|
+
require "wrong" # or require "wrong/adapters/rspec" (see below)
|
26
24
|
|
27
25
|
include Wrong
|
28
26
|
|
@@ -100,9 +98,41 @@ There's also a spreadsheet showing a translation from Test::Unit and RSpec to Wr
|
|
100
98
|
|
101
99
|
And don't miss the [slideshare presentation](http://www.slideshare.net/alexchaffee/wrong-5069976).
|
102
100
|
|
101
|
+
## Test Framework Adapters ##
|
102
|
+
|
103
|
+
Adapters for various test frameworks sit under wrong/adapters.
|
104
|
+
|
105
|
+
Currently we support
|
106
|
+
|
107
|
+
* Test::Unit - `require 'wrong/adapters/test_unit'`
|
108
|
+
* Minitest - `require 'wrong/adapters/minitest'`
|
109
|
+
* RSpec - `require 'wrong/adapters/rspec'` (now supports both 1.3 and 2.0)
|
110
|
+
|
111
|
+
To use these, put the appropriate `require` in your helper, **after** requiring your test framework; it should extend the framework enough that you can use `assert { }` in your test cases without extra fussing around.
|
112
|
+
|
113
|
+
For example:
|
114
|
+
|
115
|
+
require "test/unit"
|
116
|
+
require "wrong/adapters/test_unit"
|
117
|
+
class PlusTest < Test::Unit::TestCase
|
118
|
+
def test_adding_two_and_two
|
119
|
+
assert { 2 + 2 == 4 }
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
---
|
124
|
+
|
125
|
+
require "rspec"
|
126
|
+
require "wrong/adapters/rspec"
|
127
|
+
describe "plus" do
|
128
|
+
it "adds two and two" do
|
129
|
+
assert { 2 + 2 == 4 }
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
103
133
|
## Piecemeal Usage ##
|
104
134
|
|
105
|
-
We know that sometimes you don't want all the little doodads from a library cluttering up your namespace. If you **don't** do
|
135
|
+
We know that sometimes you don't want all the little doodads from a library cluttering up your namespace. If you **don't** want to do
|
106
136
|
|
107
137
|
require 'wrong'
|
108
138
|
include Wrong
|
@@ -121,6 +151,30 @@ To summarize: if you do `require 'wrong'` and `include Wrong` then you will get
|
|
121
151
|
|
122
152
|
And beware: if you don't `require 'wrong'`, then `include Wrong` will not do anything at all.
|
123
153
|
|
154
|
+
## Gotcha: Side Effects Within the Assert Block ##
|
155
|
+
|
156
|
+
Be careful about making calls within the assert block that cause state changes.
|
157
|
+
|
158
|
+
@x = 1
|
159
|
+
def increment
|
160
|
+
@x += 1
|
161
|
+
end
|
162
|
+
|
163
|
+
assert { increment == 2 }
|
164
|
+
assert { increment == 2 }
|
165
|
+
==> Expected (increment == 2), but
|
166
|
+
increment is 5
|
167
|
+
|
168
|
+
The first time increment fires the result is 2. The second time the result is 3, and then Wrong introspects the block to create a good failure message, causing increment to fire a couple more times.
|
169
|
+
|
170
|
+
Confusing, we know! A few patient Wrong users have hit this when the assert involves ActiveRecord write methods like #create! and #save.
|
171
|
+
|
172
|
+
The fix: introduce a variable:
|
173
|
+
|
174
|
+
value = increment
|
175
|
+
assert { value == 2 }
|
176
|
+
assert { value == 2 }
|
177
|
+
|
124
178
|
## Apology ##
|
125
179
|
|
126
180
|
So does the world need another assertion framework? In fact, it does not! We actually believe the world needs **fewer** assert methods.
|
@@ -149,29 +203,31 @@ You get all the information you want, and none you don't want. At least, that's
|
|
149
203
|
|
150
204
|
## BDD with Wrong ##
|
151
205
|
|
152
|
-
Wrong is compatible with RSpec and MiniTest::Spec, and probably Cucumber too, so you can use it inside your BDD framework of choice. To make your test code even BDD-er, try aliasing `assert` to either `should` or (Alex's favorite) `expect`.
|
206
|
+
Wrong is compatible with RSpec and MiniTest::Spec, and probably Cucumber too, so you can use it inside your BDD framework of choice. To make your test code even BDD-er, try aliasing `assert` to either `should` or (Alex's favorite) `expect`.
|
153
207
|
|
154
|
-
Here's an RSpec example:
|
208
|
+
Here's an RSpec example:
|
155
209
|
|
156
|
-
|
210
|
+
require "wrong"
|
157
211
|
require "wrong/adapters/rspec"
|
158
|
-
Wrong.config.alias_assert :
|
159
|
-
|
212
|
+
Wrong.config.alias_assert :expect_that
|
213
|
+
|
160
214
|
describe BleuCheese do
|
161
215
|
it "stinks" do
|
162
|
-
|
163
|
-
|
216
|
+
expect_that { BleuCheese.new.smell > 9000 }
|
217
|
+
end
|
164
218
|
end
|
165
219
|
|
166
|
-
This makes your code read like a BDD-style DSL, without RSpec's
|
220
|
+
This makes your code read like a BDD-style DSL, without RSpec's "should" syntax (which is, let's face it, pretty weird the first few hundred times you have to use it). Compare
|
167
221
|
|
168
|
-
|
222
|
+
expect_that { BleuCheese.new.smell > 9000 }
|
169
223
|
|
170
224
|
to
|
171
|
-
|
225
|
+
|
172
226
|
BleuCheese.new.smell.should > 9000
|
173
227
|
|
174
|
-
and
|
228
|
+
and consider which one more clearly describes the desired behavior. The object under test doesn't really have a `should` method, so why should it magically get one during a test? And in what human language is "should greater than" a valid phrase?
|
229
|
+
|
230
|
+
Warning: currently the use of `alias_assert :expect` is **not** compatible with RSpec, since RSpec also defines `expect` as a synonym for `lambda`. If you really want to use `expect` as an alias form `assert`, then use `Wrong.config.alias_assert :expect, :override => true`. See [issue #6](https://github.com/sconover/wrong/issues/6) for more details.
|
175
231
|
|
176
232
|
## Algorithm ##
|
177
233
|
|
@@ -191,19 +247,9 @@ Before you get your knickers in a twist about how this is totally unacceptable b
|
|
191
247
|
* You can't use metaprogramming to write your assert blocks.
|
192
248
|
* All variables and methods must be available in the binding of the assert block.
|
193
249
|
* Passing a proc around and eventually calling assert on it might not work in some Ruby implementations.
|
250
|
+
* Beware of Side Effects! (See discussion elsewhere in this document.)
|
194
251
|
* "Doesn't all this parsing slow down my test run"? No - this applies to failure cases only. If the assert block returns true then Wrong simply moves on.
|
195
252
|
|
196
|
-
## Adapters ##
|
197
|
-
|
198
|
-
Adapters for various test frameworks sit under wrong/adapters.
|
199
|
-
|
200
|
-
Currently we support
|
201
|
-
|
202
|
-
* Test::Unit - `require 'wrong/adapters/test_unit'`
|
203
|
-
* Minitest - `require 'wrong/adapters/minitest'`
|
204
|
-
* RSpec - `require 'wrong/adapters/rspec'` (now supports both 1.3 and 2.0)
|
205
|
-
|
206
|
-
To use these, put the appropriate `require` in your helper, **after** requiring your test framework; it should extend the framework enough that you can use `assert { }` in your test cases without extra fussing around.
|
207
253
|
|
208
254
|
## Explanations ##
|
209
255
|
|
@@ -256,11 +302,12 @@ To use the Array formatter, you may also need to `gem install diff-lcs` (it's an
|
|
256
302
|
assert { "the quick brown fox jumped over the lazy dog" ==
|
257
303
|
"the quick brown hamster jumped over the lazy gerbil" }
|
258
304
|
==>
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
305
|
+
Expected ("the quick brown fox jumped over the lazy dog" == "the quick brown hamster jumped over the lazy gerbil"), but
|
306
|
+
Strings differ at position 16:
|
307
|
+
first: ..."quick brown fox jumped over the lazy dog"
|
308
|
+
second: ..."quick brown hamster jumped over the lazy gerbil"
|
309
|
+
|
310
|
+
---
|
264
311
|
|
265
312
|
require "wrong/message/array_diff"
|
266
313
|
assert { ["venus", "mars", "pluto", "saturn"] ==
|
@@ -301,14 +348,14 @@ in your `.wrong` file and get ready to be **bedazzled**. If you need custom colo
|
|
301
348
|
|
302
349
|
### Aliases ###
|
303
350
|
|
304
|
-
An end to the language wars! Name your "assert" and "deny" methods anything you want.
|
351
|
+
An end to the language wars! Name your "assert" and "deny" methods anything you want.
|
305
352
|
|
306
353
|
* In your code, use `Wrong.config.alias_assert` and `Wrong.config.alias_deny`
|
307
354
|
* In your `.wrong` file, put `alias_assert :expect` on a line by itself
|
308
355
|
|
309
356
|
Here are some suggestions:
|
310
357
|
|
311
|
-
alias_assert :expect
|
358
|
+
alias_assert :expect # warning: not compatible with RSpec
|
312
359
|
alias_assert :should # This looks nice in RSpec
|
313
360
|
alias_assert :confirm
|
314
361
|
alias_assert :be
|
data/lib/wrong/adapters/rspec.rb
CHANGED
@@ -28,7 +28,7 @@ if Object.const_defined? :RSpec
|
|
28
28
|
module Core
|
29
29
|
class ExampleGroup
|
30
30
|
include Wrong
|
31
|
-
|
31
|
+
|
32
32
|
def failure_class
|
33
33
|
RSpec::Expectations::ExpectationNotMetError
|
34
34
|
end
|
@@ -36,6 +36,25 @@ if Object.const_defined? :RSpec
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
# Disallow alias_assert :expect
|
40
|
+
module Wrong
|
41
|
+
class Config
|
42
|
+
alias :alias_assert_or_deny_original :alias_assert_or_deny
|
43
|
+
def alias_assert_or_deny(valence, extra_name, options = {})
|
44
|
+
if extra_name.to_sym == :expect
|
45
|
+
if options[:override]
|
46
|
+
RSpec::Matchers.class_eval do
|
47
|
+
remove_method(:expect)
|
48
|
+
end
|
49
|
+
else
|
50
|
+
raise ConfigError.new("RSpec already has a method named #{extra_name}. Use alias_#{valence} :#{extra_name}, :override => true if you really want to do this.")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
alias_assert_or_deny_original(valence, extra_name, options)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
39
58
|
elsif Object.const_defined? :Spec
|
40
59
|
# RSpec 1
|
41
60
|
Spec::Runner.configure do |config|
|
@@ -46,6 +65,26 @@ elsif Object.const_defined? :Spec
|
|
46
65
|
end
|
47
66
|
end
|
48
67
|
|
68
|
+
# Disallow alias_assert :expect
|
69
|
+
module Wrong
|
70
|
+
class Config
|
71
|
+
alias :alias_assert_or_deny_original :alias_assert_or_deny
|
72
|
+
def alias_assert_or_deny(valence, extra_name, options = {})
|
73
|
+
if extra_name.to_sym == :expect
|
74
|
+
if options[:override]
|
75
|
+
Spec::Example::ExampleMethods.class_eval do
|
76
|
+
remove_method(:expect)
|
77
|
+
end
|
78
|
+
else
|
79
|
+
raise ConfigError.new("RSpec already has a method named #{extra_name}. Use alias_#{valence} :#{extra_name}, :override => true if you really want to do this.")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
alias_assert_or_deny_original(valence, extra_name, options)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
|
49
88
|
else
|
50
89
|
raise "Wrong's RSpec adapter can't find RSpec. Please require 'spec' or 'rspec' before requiring 'wrong/adapters/rspec'."
|
51
90
|
end
|
@@ -1,5 +1,32 @@
|
|
1
1
|
require "wrong"
|
2
2
|
|
3
|
+
def wrong_adapter_failure(why)
|
4
|
+
$stderr.puts why
|
5
|
+
$stderr.puts <<-TEXT
|
6
|
+
Make sure to use Bundler or Rubygems to load the test-unit gem. For example:
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
require 'test/unit'
|
10
|
+
require 'wrong/adapters/test_unit'
|
11
|
+
TEXT
|
12
|
+
exit 1
|
13
|
+
end
|
14
|
+
|
15
|
+
if Test::Unit.const_defined? :TEST_UNIT_IMPLEMENTATION
|
16
|
+
wrong_adapter_failure "You are using MiniTest's compatibility layer, not the real Test::Unit."
|
17
|
+
end
|
18
|
+
|
19
|
+
begin
|
20
|
+
require "test/unit/version"
|
21
|
+
v = Test::Unit::VERSION
|
22
|
+
wrong_adapter_failure "Test::Unit version 2.1.2 or greater required." if v < "2.1.2"
|
23
|
+
|
24
|
+
require 'test/unit/failure'
|
25
|
+
Test::Unit::TestResultFailureSupport # this class is only in 2.x, to catch mixups between 1.8's lib and gem versions
|
26
|
+
rescue => e
|
27
|
+
wrong_adapter_failure "You are using an outdated version of Test::Unit."
|
28
|
+
end
|
29
|
+
|
3
30
|
class Test::Unit::TestCase
|
4
31
|
include Wrong
|
5
32
|
|
@@ -7,3 +34,9 @@ class Test::Unit::TestCase
|
|
7
34
|
Test::Unit::AssertionFailedError
|
8
35
|
end
|
9
36
|
end
|
37
|
+
|
38
|
+
module Wrong::Assert
|
39
|
+
def increment_assertion_count
|
40
|
+
@_result.add_assertion if @_result
|
41
|
+
end
|
42
|
+
end
|
data/lib/wrong/assert.rb
CHANGED
@@ -55,13 +55,17 @@ module Wrong
|
|
55
55
|
@@last_predicated_error ||= nil
|
56
56
|
end
|
57
57
|
|
58
|
+
# override (redefine) in adapter if necessary
|
59
|
+
def increment_assertion_count
|
60
|
+
end
|
61
|
+
|
58
62
|
def aver(valence, explanation = nil, depth = 0, &block)
|
63
|
+
increment_assertion_count
|
59
64
|
require "wrong/rainbow" if Wrong.config[:color]
|
60
65
|
|
61
66
|
value = block.call
|
62
67
|
value = !value if valence == :deny
|
63
68
|
unless value
|
64
|
-
|
65
69
|
chunk = Wrong::Chunk.from_block(block, depth + 2)
|
66
70
|
|
67
71
|
message = FailureMessage.new(chunk, valence, explanation).full
|
data/lib/wrong/chunk.rb
CHANGED
@@ -294,7 +294,11 @@ public # don't know exactly why this needs to be public but eval'ed code can't f
|
|
294
294
|
end
|
295
295
|
|
296
296
|
def self.terminal_width
|
297
|
-
terminal_size && terminal_size.first
|
297
|
+
@terminal_width || (terminal_size && terminal_size.first) || 80
|
298
|
+
end
|
299
|
+
|
300
|
+
def self.terminal_width= forced_with
|
301
|
+
@terminal_width = forced_with
|
298
302
|
end
|
299
303
|
|
300
304
|
# Determines if a shell command exists by searching for it in ENV['PATH'].
|
data/lib/wrong/close_to.rb
CHANGED
data/lib/wrong/config.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "wrong/chunk"
|
2
2
|
|
3
3
|
module Wrong
|
4
|
+
|
4
5
|
def self.load_config
|
5
6
|
settings = begin
|
6
7
|
Chunk.read_here_or_higher(".wrong")
|
@@ -20,7 +21,11 @@ module Wrong
|
|
20
21
|
end
|
21
22
|
|
22
23
|
class Config < Hash
|
23
|
-
|
24
|
+
|
25
|
+
class ConfigError < RuntimeError
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(string = nil)
|
24
29
|
self[:aliases] = {:assert => [:assert], :deny => [:deny]}
|
25
30
|
if string
|
26
31
|
instance_eval string.gsub(/^(.*=)/, "self.\\1")
|
@@ -35,18 +40,18 @@ module Wrong
|
|
35
40
|
self[name.to_sym] = value
|
36
41
|
end
|
37
42
|
|
38
|
-
def alias_assert_or_deny(valence, extra_name)
|
43
|
+
def alias_assert_or_deny(valence, extra_name, options)
|
39
44
|
Wrong::Assert.send(:alias_method, extra_name, valence)
|
40
45
|
new_method_name = extra_name.to_sym
|
41
46
|
self[:aliases][valence] << new_method_name unless self[:aliases][valence].include?(new_method_name)
|
42
47
|
end
|
43
48
|
|
44
|
-
def alias_assert(method_name)
|
45
|
-
alias_assert_or_deny(:assert, method_name)
|
49
|
+
def alias_assert(method_name, options = {})
|
50
|
+
alias_assert_or_deny(:assert, method_name, options)
|
46
51
|
end
|
47
52
|
|
48
|
-
def alias_deny(method_name)
|
49
|
-
alias_assert_or_deny(:deny, method_name)
|
53
|
+
def alias_deny(method_name, options = {})
|
54
|
+
alias_assert_or_deny(:deny, method_name, options)
|
50
55
|
end
|
51
56
|
|
52
57
|
def assert_method_names
|
data/lib/wrong/d.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "sexp"
|
2
2
|
require "wrong/chunk"
|
3
|
+
require "pp"
|
3
4
|
|
4
5
|
class ::Sexp < ::Array
|
5
6
|
def d?
|
@@ -26,7 +27,9 @@ module Wrong
|
|
26
27
|
end
|
27
28
|
|
28
29
|
code = sexp.to_ruby
|
29
|
-
value = eval(code, block.binding, called_from[0], called_from[1].to_i)
|
30
|
+
value = eval(code, block.binding, called_from[0], called_from[1].to_i)
|
31
|
+
width = Chunk.terminal_width
|
32
|
+
value = PP.pp(value, "", width - (code.size + 3)).chomp
|
30
33
|
|
31
34
|
if Wrong.config[:color]
|
32
35
|
require "wrong/rainbow"
|
data/lib/wrong/version.rb
CHANGED
@@ -22,6 +22,38 @@ describe "wrong's failure" do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
describe "alias_assert" do
|
26
|
+
it "works for an innocuous name" do
|
27
|
+
e = rescuing {
|
28
|
+
Wrong.config.alias_assert :allow
|
29
|
+
}
|
30
|
+
e.should be_nil
|
31
|
+
end
|
32
|
+
|
33
|
+
describe ":expect" do
|
34
|
+
it "fails if RSpec is active" do
|
35
|
+
e = rescuing {
|
36
|
+
Wrong.config.alias_assert :expect
|
37
|
+
}
|
38
|
+
e.should be_a(Wrong::Config::ConfigError)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "works if we pass :override => true" do
|
42
|
+
e = rescuing {
|
43
|
+
Wrong.config.alias_assert :expect, :override => true
|
44
|
+
}
|
45
|
+
e.should be_nil
|
46
|
+
|
47
|
+
e = rescuing {
|
48
|
+
expect { false }
|
49
|
+
}
|
50
|
+
e.should_not be_nil
|
51
|
+
e.should be_a(Spec::Expectations::ExpectationNotMetError)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
25
57
|
describe "arithmetic" do
|
26
58
|
it "should not work like this" do
|
27
59
|
assert { 2 + 2 == 5 }
|
@@ -17,6 +17,7 @@ puts RSpec::Core::Version::STRING
|
|
17
17
|
require 'rspec/autorun'
|
18
18
|
require "wrong/adapters/rspec"
|
19
19
|
|
20
|
+
# these first ones should pass, since they describe how Wrong works inside the RSpec ecosystem
|
20
21
|
describe "wrong's failure" do
|
21
22
|
it "is an RSpec exception" do
|
22
23
|
e = rescuing {
|
@@ -26,6 +27,37 @@ describe "wrong's failure" do
|
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
30
|
+
describe "alias_assert" do
|
31
|
+
it "works for an innocuous name" do
|
32
|
+
e = rescuing {
|
33
|
+
Wrong.config.alias_assert :allow
|
34
|
+
}
|
35
|
+
e.should be_nil
|
36
|
+
end
|
37
|
+
|
38
|
+
describe ":expect" do
|
39
|
+
it "fails if RSpec is active" do
|
40
|
+
e = rescuing {
|
41
|
+
Wrong.config.alias_assert :expect
|
42
|
+
}
|
43
|
+
e.should be_a(Wrong::Config::ConfigError)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "works if we pass :override => true" do
|
47
|
+
e = rescuing {
|
48
|
+
Wrong.config.alias_assert :expect, :override => true
|
49
|
+
}
|
50
|
+
e.should be_nil
|
51
|
+
|
52
|
+
e = rescuing {
|
53
|
+
expect { false }
|
54
|
+
}
|
55
|
+
e.should_not be_nil
|
56
|
+
e.should be_a(RSpec::Expectations::ExpectationNotMetError)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
29
61
|
describe "arithmetic" do
|
30
62
|
it "should not work like this" do
|
31
63
|
assert { 2 + 2 == 5 }
|
data/test/adapters/rspec_test.rb
CHANGED
@@ -36,7 +36,7 @@ describe "testing rspec" do
|
|
36
36
|
(rspec_version == 1 || RUBY_VERSION =~ /^1\.8\./ || RUBY_VERSION == '1.9.1' ? nil : 1) # RSpec v1 exits with 0 on failure :-(
|
37
37
|
end
|
38
38
|
|
39
|
-
assert { spec_output.include? "
|
39
|
+
assert { spec_output.include? "1 failure" }
|
40
40
|
assert { spec_output.include? "Expected ((2 + 2) == 5), but" }
|
41
41
|
end
|
42
42
|
end
|
@@ -1,8 +1,10 @@
|
|
1
|
-
|
1
|
+
here = File.dirname(__FILE__)
|
2
|
+
$LOAD_PATH.unshift "#{here}/../../lib"
|
2
3
|
|
4
|
+
# gem "test-unit"
|
3
5
|
require "test/unit"
|
6
|
+
require "test/unit/autorunner"
|
4
7
|
|
5
|
-
#require "wrong/assert"
|
6
8
|
require "wrong/adapters/test_unit"
|
7
9
|
|
8
10
|
# get rid of atrocious Test::Unit color scheme (gray on green = puke)
|
@@ -19,21 +21,21 @@ class MyFailingAssertTest < Test::Unit::TestCase
|
|
19
21
|
assert{1==2}
|
20
22
|
end
|
21
23
|
end
|
22
|
-
|
24
|
+
|
23
25
|
my_failing_deny_test = Class.new(Test::Unit::TestCase)
|
24
26
|
my_failing_deny_test.class_eval do
|
25
27
|
def test_fail
|
26
28
|
deny{1==1}
|
27
29
|
end
|
28
30
|
end
|
29
|
-
|
31
|
+
|
30
32
|
result = Test::Unit::TestResult.new
|
31
33
|
my_failing_assert_test.new("test_fail").run(result) {|started, name| }
|
32
34
|
#I can do without all the TU Listener business, thank you
|
33
35
|
failures = result.instance_variable_get("@failures".to_sym)
|
34
36
|
assert{ failures.length==1 }
|
35
37
|
assert{ failures.first.long_display.include?("Expected (1 == 2)") }
|
36
|
-
|
38
|
+
|
37
39
|
result = Test::Unit::TestResult.new
|
38
40
|
failures = result.instance_variable_get("@failures".to_sym)
|
39
41
|
my_failing_deny_test.new("test_fail").run(result) {|started, name| }
|
@@ -57,3 +59,30 @@ class MyFailingAssertTest < Test::Unit::TestCase
|
|
57
59
|
assert { e.message == "up is down.\n<false> is not true." }
|
58
60
|
end
|
59
61
|
end
|
62
|
+
|
63
|
+
class TestUnitAdapterTest < Test::Unit::TestCase
|
64
|
+
def setup
|
65
|
+
@add_assertion_called = 0
|
66
|
+
end
|
67
|
+
|
68
|
+
def add_assertion
|
69
|
+
super
|
70
|
+
@add_assertion_called += 1
|
71
|
+
end
|
72
|
+
|
73
|
+
def current_result
|
74
|
+
@_result
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_assert_bumps_assertion_count
|
78
|
+
assertion_count = current_result.assertion_count
|
79
|
+
assert { true }
|
80
|
+
assert_equal assertion_count+1, current_result.assertion_count
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_assert_calls_add_assertion
|
84
|
+
assert_equal 0, @add_assertion_called
|
85
|
+
assert { true }
|
86
|
+
assert_equal 1, @add_assertion_called
|
87
|
+
end
|
88
|
+
end
|
data/test/capturing_test.rb
CHANGED
@@ -28,7 +28,14 @@ describe "a tool for capturing output" do
|
|
28
28
|
|
29
29
|
assert { out == "hi\n"}
|
30
30
|
assert { err == "bye\n"}
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns an empty string if nothing was emitted" do
|
34
|
+
out, err = capturing(:stdout, :stderr) do
|
35
|
+
end
|
31
36
|
|
37
|
+
assert { out == ""}
|
38
|
+
assert { err == ""}
|
32
39
|
end
|
33
40
|
|
34
41
|
it "supports nesting" do
|
data/test/chunk_test.rb
CHANGED
@@ -2,12 +2,19 @@ here = File.expand_path(File.dirname(__FILE__))
|
|
2
2
|
require "#{here}/test_helper"
|
3
3
|
require "wrong/chunk"
|
4
4
|
require 'yaml'
|
5
|
+
require 'wrong/helpers'
|
5
6
|
|
6
7
|
unless Object.const_defined?(:Chunk)
|
7
8
|
Chunk = Wrong::Chunk
|
8
9
|
end
|
9
10
|
|
10
11
|
describe Chunk do
|
12
|
+
|
13
|
+
# normalize yaml
|
14
|
+
def y(s)
|
15
|
+
s.gsub(/--- $/, "---").chomp
|
16
|
+
end
|
17
|
+
|
11
18
|
describe "#from_block" do
|
12
19
|
it "reads the source location" do
|
13
20
|
file, line = __FILE__, __LINE__
|
@@ -177,21 +184,19 @@ z
|
|
177
184
|
code_parts = chunk.parts
|
178
185
|
assert !code_parts.include?("rescuing")
|
179
186
|
end
|
180
|
-
|
187
|
+
|
181
188
|
it "skips assignments" do
|
182
189
|
chunk = Chunk.new(__FILE__, __LINE__ + 1); <<-CODE
|
183
190
|
x = 7; x
|
184
191
|
CODE
|
185
192
|
assert !chunk.parts.include?("(x = 7)")
|
186
|
-
end
|
193
|
+
end
|
187
194
|
end
|
188
195
|
|
189
196
|
describe "#details" do
|
190
197
|
def details(&block)
|
191
198
|
chunk = Chunk.from_block(block, 1)
|
192
|
-
|
193
|
-
# puts d
|
194
|
-
d
|
199
|
+
chunk.details
|
195
200
|
end
|
196
201
|
|
197
202
|
it "returns an empty string if there are no parts" do
|
@@ -256,14 +261,14 @@ z
|
|
256
261
|
# this means it's a literal slash plus t inside double quotes -- i.e. it shows the escaped (inspected) string
|
257
262
|
assert d == "\n" + ' x is "flavor:\tvanilla"' + "\n"
|
258
263
|
end
|
259
|
-
|
264
|
+
|
260
265
|
it "splits lower-down details correctly (bug)" do
|
261
266
|
hash = {:flavor => "vanilla"}
|
262
267
|
exception_with_newlines = Exception.new(hash.to_yaml.chomp)
|
263
268
|
d = details {
|
264
269
|
rescuing { raise exception_with_newlines }.message.include?(":flavor: chocolate")
|
265
270
|
}
|
266
|
-
assert d.include? "exception_with_newlines is #<Exception:
|
271
|
+
assert (y(d).include? "exception_with_newlines is #<Exception: ---\n :flavor: vanilla>"), d.inspect
|
267
272
|
end
|
268
273
|
|
269
274
|
it "skips assignments" do
|
@@ -277,19 +282,19 @@ z
|
|
277
282
|
def initialize(inspected_value)
|
278
283
|
@inspected_value = inspected_value
|
279
284
|
end
|
280
|
-
|
285
|
+
|
281
286
|
def inspect
|
282
287
|
@inspected_value
|
283
288
|
end
|
284
289
|
end
|
285
|
-
|
290
|
+
|
286
291
|
|
287
292
|
it "indents unescaped newlines inside the inspected value" do
|
288
293
|
x = Weirdo.new("first\nsecond\nthird")
|
289
294
|
d = details { assert { x == "foo" } }
|
290
295
|
assert d == "\n x is first\n second\n third\n"
|
291
296
|
end
|
292
|
-
|
297
|
+
|
293
298
|
describe '#pretty_value' do
|
294
299
|
before do
|
295
300
|
@chunk = chunk = Chunk.new(__FILE__, __LINE__ + 1); <<-CODE
|
@@ -297,23 +302,37 @@ z
|
|
297
302
|
CODE
|
298
303
|
end
|
299
304
|
|
305
|
+
after do
|
306
|
+
Chunk.terminal_width = 80
|
307
|
+
end
|
308
|
+
|
300
309
|
it 'inspects its value' do
|
301
310
|
assert @chunk.pretty_value(12) == "12"
|
302
311
|
assert @chunk.pretty_value("foo") == "\"foo\""
|
303
312
|
end
|
304
|
-
|
313
|
+
|
305
314
|
it 'escapes newlines in strings' do
|
306
315
|
assert @chunk.pretty_value("foo\nbar\nbaz") == "\"foo\\nbar\\nbaz\""
|
307
316
|
end
|
308
|
-
|
317
|
+
|
309
318
|
it 'indents newlines in raw inspect values (e.g. exceptions or YAML or whatever)' do
|
310
319
|
w = Weirdo.new("foo\nbar\nbaz")
|
311
320
|
assert @chunk.pretty_value(w) == "foo\n bar\n baz"
|
312
321
|
end
|
313
|
-
|
322
|
+
|
323
|
+
it "returns the terminal width" do
|
324
|
+
assert Chunk.terminal_width.is_a? Fixnum
|
325
|
+
assert Chunk.terminal_width > 0
|
326
|
+
end
|
327
|
+
|
328
|
+
it "can fake the terminal width" do
|
329
|
+
Chunk.terminal_width = 66
|
330
|
+
assert Chunk.terminal_width == 66
|
331
|
+
end
|
332
|
+
|
314
333
|
# def pretty_value(value, starting_col = 0, indent_wrapped_lines = 3, size = Chunk.terminal_size)
|
315
|
-
|
316
|
-
it 'inserts newlines in really long values, wrapped at the
|
334
|
+
|
335
|
+
it 'inserts newlines in really long values, wrapped at the given width' do
|
317
336
|
abc = Weirdo.new("abcdefghijklmnopqrstuvwxyz")
|
318
337
|
pretty = @chunk.pretty_value(abc, 0, 0, 10)
|
319
338
|
assert pretty == <<-DONE.chomp
|
@@ -322,7 +341,18 @@ klmnopqrst
|
|
322
341
|
uvwxyz
|
323
342
|
DONE
|
324
343
|
end
|
325
|
-
|
344
|
+
|
345
|
+
it 'inserts newlines in really long values, wrapped at the terminal width' do
|
346
|
+
Chunk.terminal_width = 10
|
347
|
+
abc = Weirdo.new("abcdefghijklmnopqrstuvwxyz")
|
348
|
+
pretty = @chunk.pretty_value(abc, 0, 0)
|
349
|
+
assert pretty == <<-DONE.chomp
|
350
|
+
abcdefghij
|
351
|
+
klmnopqrst
|
352
|
+
uvwxyz
|
353
|
+
DONE
|
354
|
+
end
|
355
|
+
|
326
356
|
it 'subtracts the starting column from the wrapped width of the first line' do
|
327
357
|
abc = Weirdo.new("abcdefghijklmnopqrstuvwxyz")
|
328
358
|
pretty = @chunk.pretty_value(abc, 2, 0, 10)
|
@@ -332,7 +362,7 @@ ijklmnopqr
|
|
332
362
|
stuvwxyz
|
333
363
|
DONE
|
334
364
|
end
|
335
|
-
|
365
|
+
|
336
366
|
it "indents wrapped lines" do
|
337
367
|
abc = Weirdo.new("abcdefghijklmnopqrstuvwxyz")
|
338
368
|
pretty = @chunk.pretty_value(abc, 2, 3, 10)
|
@@ -343,17 +373,18 @@ abcdefgh
|
|
343
373
|
wxyz
|
344
374
|
DONE
|
345
375
|
end
|
346
|
-
|
376
|
+
|
347
377
|
it "wraps correctly" do
|
348
378
|
hash = {:flavor => "vanilla"}
|
349
379
|
object = Weirdo.new(hash.to_yaml.chomp)
|
350
380
|
pretty = @chunk.pretty_value(object, 2, 3, 80)
|
351
|
-
assert pretty == <<-DONE.
|
352
|
-
---
|
381
|
+
assert y(pretty) == y(<<-DONE), pretty.inspect
|
382
|
+
---
|
353
383
|
:flavor: vanilla
|
354
384
|
DONE
|
355
385
|
end
|
356
386
|
|
387
|
+
|
357
388
|
end
|
358
389
|
|
359
390
|
end
|
data/test/close_to_test.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "./test/test_helper"
|
2
2
|
require "wrong/close_to"
|
3
3
|
require "wrong"
|
4
|
+
require "bigdecimal"
|
4
5
|
|
5
6
|
describe "#close_to? (monkey patch for float comparison)" do
|
6
7
|
include Wrong
|
@@ -35,5 +36,11 @@ describe "#close_to? (monkey patch for float comparison)" do
|
|
35
36
|
deny { 5.close_to? 5.1 }
|
36
37
|
assert { 5.close_to? 5.1, 0.5 }
|
37
38
|
end
|
39
|
+
|
40
|
+
it "also works for bigdecimals" do
|
41
|
+
assert { BigDecimal.new("5.0").close_to? 5 }
|
42
|
+
assert { BigDecimal.new("5.0").close_to? 5.0001 }
|
43
|
+
deny { BigDecimal.new("5.0").close_to? 5.1 }
|
44
|
+
end
|
38
45
|
|
39
46
|
end
|
data/test/d_test.rb
CHANGED
@@ -22,6 +22,15 @@ describe "d" do
|
|
22
22
|
assert { output == "x is \"one\\ttwo\"\n" }
|
23
23
|
end
|
24
24
|
|
25
|
+
it "pretty-prints the value" do
|
26
|
+
Wrong::Chunk.terminal_width = 80
|
27
|
+
x = {:a => "a" * 60, :b => "b" * 60}
|
28
|
+
output = capturing do
|
29
|
+
d { x }
|
30
|
+
end
|
31
|
+
assert { output == "x is {:a=>\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\n :b=>\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\"}\n" }
|
32
|
+
end
|
33
|
+
|
25
34
|
it "works on an expression" do
|
26
35
|
x = 5
|
27
36
|
output = capturing do
|
metadata
CHANGED
@@ -1,111 +1,93 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: wrong
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 5
|
8
|
-
- 0
|
9
|
-
version: 0.5.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.2
|
5
|
+
prerelease:
|
10
6
|
platform: java
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Steve Conover
|
13
9
|
- Alex Chaffee
|
14
10
|
autorequire:
|
15
11
|
bindir: bin
|
16
12
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
13
|
+
date: 2011-07-07 00:00:00.000000000Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
22
16
|
name: predicated
|
23
|
-
requirement: &
|
17
|
+
requirement: &2162741940 !ruby/object:Gem::Requirement
|
24
18
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
- 0
|
30
|
-
- 2
|
31
|
-
- 2
|
32
|
-
version: 0.2.2
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.2.3
|
33
23
|
type: :runtime
|
34
24
|
prerelease: false
|
35
|
-
version_requirements: *
|
36
|
-
- !ruby/object:Gem::Dependency
|
25
|
+
version_requirements: *2162741940
|
26
|
+
- !ruby/object:Gem::Dependency
|
37
27
|
name: ruby_parser
|
38
|
-
requirement: &
|
28
|
+
requirement: &2162741440 !ruby/object:Gem::Requirement
|
39
29
|
none: false
|
40
|
-
requirements:
|
30
|
+
requirements:
|
41
31
|
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
segments:
|
44
|
-
- 2
|
45
|
-
- 0
|
46
|
-
- 4
|
32
|
+
- !ruby/object:Gem::Version
|
47
33
|
version: 2.0.4
|
48
34
|
type: :runtime
|
49
35
|
prerelease: false
|
50
|
-
version_requirements: *
|
51
|
-
- !ruby/object:Gem::Dependency
|
36
|
+
version_requirements: *2162741440
|
37
|
+
- !ruby/object:Gem::Dependency
|
52
38
|
name: ruby2ruby
|
53
|
-
requirement: &
|
39
|
+
requirement: &2162740980 !ruby/object:Gem::Requirement
|
54
40
|
none: false
|
55
|
-
requirements:
|
41
|
+
requirements:
|
56
42
|
- - ~>
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
|
59
|
-
- 1
|
60
|
-
- 2
|
61
|
-
version: "1.2"
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '1.2'
|
62
45
|
type: :runtime
|
63
46
|
prerelease: false
|
64
|
-
version_requirements: *
|
65
|
-
- !ruby/object:Gem::Dependency
|
47
|
+
version_requirements: *2162740980
|
48
|
+
- !ruby/object:Gem::Dependency
|
66
49
|
name: sexp_processor
|
67
|
-
requirement: &
|
50
|
+
requirement: &2162740520 !ruby/object:Gem::Requirement
|
68
51
|
none: false
|
69
|
-
requirements:
|
52
|
+
requirements:
|
70
53
|
- - ~>
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
|
73
|
-
- 3
|
74
|
-
- 0
|
75
|
-
version: "3.0"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.0'
|
76
56
|
type: :runtime
|
77
57
|
prerelease: false
|
78
|
-
version_requirements: *
|
79
|
-
- !ruby/object:Gem::Dependency
|
58
|
+
version_requirements: *2162740520
|
59
|
+
- !ruby/object:Gem::Dependency
|
80
60
|
name: diff-lcs
|
81
|
-
requirement: &
|
61
|
+
requirement: &2162740060 !ruby/object:Gem::Requirement
|
82
62
|
none: false
|
83
|
-
requirements:
|
63
|
+
requirements:
|
84
64
|
- - ~>
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
segments:
|
87
|
-
- 1
|
88
|
-
- 1
|
89
|
-
- 2
|
65
|
+
- !ruby/object:Gem::Version
|
90
66
|
version: 1.1.2
|
91
67
|
type: :runtime
|
92
68
|
prerelease: false
|
93
|
-
version_requirements: *
|
94
|
-
description:
|
95
|
-
|
69
|
+
version_requirements: *2162740060
|
70
|
+
description: ! 'Wrong provides a general assert method that takes a predicate block.
|
71
|
+
Assertion failure
|
72
|
+
|
96
73
|
messages are rich in detail. The Wrong idea is to replace all those countless assert_this,
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
74
|
+
|
75
|
+
assert_that library methods which only exist to give a more useful failure message
|
76
|
+
than
|
77
|
+
|
78
|
+
"assertion failed". Wrong replaces all of them in one fell swoop, since if you can
|
79
|
+
write it
|
80
|
+
|
81
|
+
in Ruby, Wrong can make a sensible failure message out of it. Also provided are
|
82
|
+
several
|
83
|
+
|
84
|
+
helper methods, like rescuing, capturing, and d.'
|
101
85
|
email: sconover@gmail.com
|
102
86
|
executables: []
|
103
|
-
|
104
87
|
extensions: []
|
105
|
-
|
106
|
-
extra_rdoc_files:
|
88
|
+
extra_rdoc_files:
|
107
89
|
- README.markdown
|
108
|
-
files:
|
90
|
+
files:
|
109
91
|
- lib/wrong/adapters/minitest.rb
|
110
92
|
- lib/wrong/adapters/rspec.rb
|
111
93
|
- lib/wrong/adapters/test_unit.rb
|
@@ -168,40 +150,35 @@ files:
|
|
168
150
|
- test/suite.rb
|
169
151
|
- test/test_helper.rb
|
170
152
|
- test/wrong_test.rb
|
171
|
-
has_rdoc: true
|
172
153
|
homepage: http://github.com/sconover/wrong
|
173
154
|
licenses: []
|
174
|
-
|
175
155
|
post_install_message:
|
176
156
|
rdoc_options: []
|
177
|
-
|
178
|
-
require_paths:
|
157
|
+
require_paths:
|
179
158
|
- lib
|
180
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
181
160
|
none: false
|
182
|
-
requirements:
|
183
|
-
- -
|
184
|
-
- !ruby/object:Gem::Version
|
185
|
-
|
186
|
-
segments:
|
161
|
+
requirements:
|
162
|
+
- - ! '>='
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
segments:
|
187
166
|
- 0
|
188
|
-
|
189
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
hash: 4298502534753736492
|
168
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
169
|
none: false
|
191
|
-
requirements:
|
192
|
-
- -
|
193
|
-
- !ruby/object:Gem::Version
|
194
|
-
|
195
|
-
- 0
|
196
|
-
version: "0"
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
197
174
|
requirements: []
|
198
|
-
|
199
175
|
rubyforge_project: wrong
|
200
|
-
rubygems_version: 1.
|
176
|
+
rubygems_version: 1.8.5
|
201
177
|
signing_key:
|
202
178
|
specification_version: 3
|
203
|
-
summary: Wrong provides a general assert method that takes a predicate block. Assertion
|
204
|
-
|
179
|
+
summary: Wrong provides a general assert method that takes a predicate block. Assertion
|
180
|
+
failure messages are rich in detail.
|
181
|
+
test_files:
|
205
182
|
- test/adapters/minitest_test.rb
|
206
183
|
- test/adapters/railsapp/app/controllers/application_controller.rb
|
207
184
|
- test/adapters/railsapp/app/helpers/application_helper.rb
|