wrong 0.4.3-java → 0.4.4-java
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/README.markdown +49 -19
- data/lib/wrong.rb +14 -3
- data/lib/wrong/adapters/minitest.rb +5 -2
- data/lib/wrong/assert.rb +1 -33
- data/lib/wrong/chunk.rb +7 -3
- data/lib/wrong/failure_message.rb +54 -0
- data/lib/wrong/message/array_diff.rb +1 -1
- data/lib/wrong/sexp_ext.rb +3 -3
- data/lib/wrong/version.rb +1 -1
- data/test/adapters/minitest_test.rb +2 -3
- data/test/adapters/railsapp/config/initializers/secret_token.rb +1 -1
- data/test/adapters/test_unit_test.rb +2 -2
- data/test/config_test.rb +2 -2
- data/test/failure_message_test.rb +45 -0
- data/test/failures_test.rb +41 -86
- data/test/message/array_diff_test.rb +5 -0
- metadata +4 -4
data/README.markdown
CHANGED
@@ -57,13 +57,16 @@ If your assertion is more than a simple predicate, then Wrong will split it into
|
|
57
57
|
And a companion, 'deny':
|
58
58
|
|
59
59
|
deny{'abc'.include?('bc')}
|
60
|
-
==> Didn't expect "abc".include?("bc")
|
60
|
+
==> Didn't expect "abc".include?("bc")
|
61
61
|
|
62
62
|
There's also a convenience method for catching errors:
|
63
63
|
|
64
64
|
assert{ rescuing{raise "vanilla"}.message == "chocolate" }
|
65
65
|
==>
|
66
|
-
Expected (rescuing { raise("vanilla") }.message == "chocolate"), but
|
66
|
+
Expected (rescuing { raise("vanilla") }.message == "chocolate"), but
|
67
|
+
rescuing { raise("vanilla") }.message is "vanilla"
|
68
|
+
rescuing { raise("vanilla") } is #<RuntimeError: vanilla>
|
69
|
+
raise("vanilla") raises RuntimeError: vanilla
|
67
70
|
|
68
71
|
And one for capturing output streams:
|
69
72
|
|
@@ -89,7 +92,7 @@ We also implement the most amazing debugging method ever, `d`, which gives you a
|
|
89
92
|
d { x } # => prints "x is 7" to the console
|
90
93
|
d { x * 2 } # => prints "(x * 2) is 14" to the console
|
91
94
|
|
92
|
-
(`d` was originally implemented by Rob Sanheim in LogBuddy; as with Assert2 this is a rewrite and homage.) Remember, if you want `d` to work at runtime (e.g. in a webapp) then you must `include
|
95
|
+
(`d` was originally implemented by Rob Sanheim in LogBuddy; as with Assert2 this version is a rewrite and homage.) Remember, if you want `d` to work at runtime (e.g. in a webapp) then you must `include Wrong::D` inside your app, e.g. in your `environment.rb` file.
|
93
96
|
|
94
97
|
More examples are in the file `examples.rb` <http://github.com/alexch/wrong/blob/master/examples.rb>
|
95
98
|
|
@@ -114,7 +117,7 @@ will give you the `assert` and `deny` methods but not the formatters or `rescuin
|
|
114
117
|
require 'wrong/d'
|
115
118
|
include Wrong::D
|
116
119
|
|
117
|
-
To summarize: if you do `require 'wrong'` and `include Wrong` then you will get the whole ball of wax. Most people will probably want this since it's easier, but there is an alternative,
|
120
|
+
To summarize: if you do `require 'wrong'` and `include Wrong` then you will get the whole ball of wax. Most people will probably want this since it's easier, but there is an alternative, which is to `require` and `include` only what you want.
|
118
121
|
|
119
122
|
And beware: if you don't `require 'wrong'`, then `include Wrong` will not do anything at all.
|
120
123
|
|
@@ -144,6 +147,32 @@ Wrong also lets you put the expected and actual values in any order you want! Co
|
|
144
147
|
|
145
148
|
You get all the information you want, and none you don't want. At least, that's the plan! :-)
|
146
149
|
|
150
|
+
## BDD with Wrong ##
|
151
|
+
|
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`.
|
153
|
+
|
154
|
+
Here's an RSpec example:
|
155
|
+
|
156
|
+
require "wrong"
|
157
|
+
require "wrong/adapters/rspec"
|
158
|
+
Wrong.config.alias_assert :expect
|
159
|
+
|
160
|
+
describe BleuCheese do
|
161
|
+
it "stinks" do
|
162
|
+
expect { BleuCheese.new.smell > 9000 }
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
This makes your code read like a BDD-style DSL, without RSpec's arcane "should" syntax (which is, let's face it, pretty weird the first few hundred times you have to use it). Compare
|
167
|
+
|
168
|
+
expect { BleuCheese.new.smell > 9000 }
|
169
|
+
|
170
|
+
to
|
171
|
+
|
172
|
+
BleuCheese.new.smell.should > 9000
|
173
|
+
|
174
|
+
and seriously, tell me which one more clearly describes the desired behavior. The object under test doesn't really have a `should` method, so why should it during a test? And in what human language is "should greater than" a valid phrase?
|
175
|
+
|
147
176
|
## Algorithm ##
|
148
177
|
|
149
178
|
So wait a second. How do we do it? Doesn't Ruby have [poor support for AST introspection](http://blog.zenspider.com/2009/04/parsetree-eol.html)? Well, yes, it does, so we cheat: we figure out what file and line the assert block is defined in, then open the file, read the code, and parse it directly using Ryan Davis' amazing [RubyParser](http://parsetree.rubyforge.org/ruby_parser/) and [Ruby2Ruby](http://seattlerb.rubyforge.org/ruby2ruby/). You can bask in the kludge by examining `chunk.rb` and `assert.rb`. If you find some code it can't parse, please send it our way.
|
@@ -193,13 +222,12 @@ And if your assertion code isn't self-explanatory, then that's a hint that you m
|
|
193
222
|
|
194
223
|
When a failure occurs, the exception message contains all the details you might need to make sense of it. Here's the breakdown:
|
195
224
|
|
196
|
-
Expected [CLAIM], but
|
225
|
+
Expected [CLAIM], but
|
197
226
|
[FORMATTER]
|
198
227
|
[SUBEXP] is [VALUE]
|
199
228
|
...
|
200
229
|
|
201
230
|
* CLAIM is the code inside your assert block, normalized
|
202
|
-
* SUMMARY is a to-English translation of the claim, via the Predicated library. This tries to be very intelligible; e.g. translating "include?" into "does not include" and so on.
|
203
231
|
* If there is a formatter registered for this type of predicate, its output will come next. (See below.)
|
204
232
|
* SUBEXP is each of the subtrees of the claim, minus duplicates and truisms (e.g. literals).
|
205
233
|
* The word "is" is a very nice separator since it doesn't look like code, but is short enough to be easily visually parsed.
|
@@ -209,6 +237,8 @@ We hope this structure lets your eyes focus on the meaningful values and differe
|
|
209
237
|
|
210
238
|
(Why does VALUE use `inspect` and not `to_s`? Because `inspect` on standard objects like String and Array are sure to show all relevant details, such as white space, in a console-safe way, and we hope other libraries follow suit. Also, `to_s` often inserts line breaks and that messes up formatting and legibility.)
|
211
239
|
|
240
|
+
Wrong tries to maintain indentation to improve readability. If the inspected VALUE contains newlines, the succeeding lines will be indented to the correct level.
|
241
|
+
|
212
242
|
## Formatters ##
|
213
243
|
|
214
244
|
Enhancements for error messages sit under wrong/message.
|
@@ -216,22 +246,19 @@ Enhancements for error messages sit under wrong/message.
|
|
216
246
|
Currently we support special messages for
|
217
247
|
|
218
248
|
* String ==
|
219
|
-
*
|
249
|
+
* Array(ish) ==
|
220
250
|
* including nested string elements
|
221
251
|
|
222
|
-
To use
|
252
|
+
To use the Array formatter, you may also need to `gem install diff-lcs` (it's an optional dependency).
|
223
253
|
|
224
|
-
require "wrong/message/
|
254
|
+
require "wrong/message/string_comparison"
|
225
255
|
assert { "the quick brown fox jumped over the lazy dog" ==
|
226
256
|
"the quick brown hamster jumped over the lazy gerbil" }
|
227
257
|
==>
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
^^^
|
233
|
-
the quick brown hamster jumped over the lazy gerbil
|
234
|
-
^^^^^^^
|
258
|
+
Expected ("the quick brown fox jumped over the lazy dog" == "the quick brown hamster jumped over the lazy gerbil"), but
|
259
|
+
Strings differ at position 16:
|
260
|
+
first: ..."quick brown fox jumped over the lazy dog"
|
261
|
+
second: ..."quick brown hamster jumped over the lazy gerbil"
|
235
262
|
--
|
236
263
|
|
237
264
|
require "wrong/message/array_diff"
|
@@ -245,8 +272,6 @@ To use these formatters, you have to explicitly `require` them! You may also nee
|
|
245
272
|
["venus", "earth", "pluto", "neptune"]
|
246
273
|
^ ^
|
247
274
|
|
248
|
-
[Bug: turns out 'diff' and 'diff-lcs' are incompatible with each other. We're working on a fix.]
|
249
|
-
|
250
275
|
## Config ##
|
251
276
|
|
252
277
|
These settings can either be set at runtime on the `Wrong.config` singleton, or inside a `.wrong` file in the current directory or a parent. In the `.wrong` file just pretend every line is preceded with `Wrong.config.` -- e.g. if there's a setting called `ice_cream`, you can do any of these in your `.wrong` file
|
@@ -275,7 +300,12 @@ in your `.wrong` file and get ready to be **bedazzled**. If you need custom colo
|
|
275
300
|
|
276
301
|
### Aliases ###
|
277
302
|
|
278
|
-
An end to the language wars! Name your "assert" and "deny" methods anything you want.
|
303
|
+
An end to the language wars! Name your "assert" and "deny" methods anything you want.
|
304
|
+
|
305
|
+
* In your code, use `Wrong.config.alias_assert` and `Wrong.config.alias_deny`
|
306
|
+
* In your `.wrong` file, put `alias_assert :expect` on a line by itself
|
307
|
+
|
308
|
+
Here are some suggestions:
|
279
309
|
|
280
310
|
alias_assert :expect
|
281
311
|
alias_assert :should # This looks nice in RSpec
|
data/lib/wrong.rb
CHANGED
@@ -20,8 +20,19 @@ module Wrong
|
|
20
20
|
extend Wrong::Helpers
|
21
21
|
end
|
22
22
|
|
23
|
-
# this does some magic; if you don't like it
|
23
|
+
# this does some magic; if you don't like it...
|
24
|
+
|
25
|
+
# ...`require 'wrong/assert'` et al. individually and don't `require 'wrong/close_to'` or `require 'wrong'`
|
24
26
|
require "wrong/close_to"
|
25
27
|
|
26
|
-
#
|
27
|
-
Object
|
28
|
+
# ...don't `require 'wrong'`, and `include Wrong::D` only in the modules you want to call `d` from
|
29
|
+
class Object
|
30
|
+
include Wrong::D
|
31
|
+
end
|
32
|
+
|
33
|
+
# ...don't `require 'wrong'`
|
34
|
+
# this part isn't working yet -- it's supposed to make 'assert' available at the top level but it breaks the minitest adapter
|
35
|
+
# include Wrong
|
36
|
+
# class Object
|
37
|
+
# include Wrong
|
38
|
+
# end
|
@@ -1,7 +1,9 @@
|
|
1
|
-
require "wrong"
|
1
|
+
require "wrong/assert"
|
2
|
+
require "wrong/helpers"
|
2
3
|
|
3
4
|
class MiniTest::Unit::TestCase
|
4
|
-
include Wrong
|
5
|
+
include Wrong::Assert
|
6
|
+
include Wrong::Helpers
|
5
7
|
|
6
8
|
def failure_class
|
7
9
|
MiniTest::Assertion
|
@@ -11,4 +13,5 @@ class MiniTest::Unit::TestCase
|
|
11
13
|
self._assertions += 1 # increment minitest's assert count
|
12
14
|
super(valence, explanation, depth + 1) # apparently this passes along the default block
|
13
15
|
end
|
16
|
+
|
14
17
|
end
|
data/lib/wrong/assert.rb
CHANGED
@@ -48,10 +48,6 @@ module Wrong
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
def summary(method_sym, predicate)
|
52
|
-
method_sym == :deny ? predicate.to_sentence : predicate.to_negative_sentence
|
53
|
-
end
|
54
|
-
|
55
51
|
protected
|
56
52
|
|
57
53
|
# for debugging -- if we couldn't make a predicate out of the code block, then this was why
|
@@ -59,34 +55,6 @@ module Wrong
|
|
59
55
|
@@last_predicated_error ||= nil
|
60
56
|
end
|
61
57
|
|
62
|
-
# todo: move some/all of this into FailureMessage
|
63
|
-
def full_message(chunk, block, valence, explanation)
|
64
|
-
code = chunk.code
|
65
|
-
|
66
|
-
predicate = begin
|
67
|
-
Predicated::Predicate.from_ruby_code_string(code, block.binding)
|
68
|
-
rescue Predicated::Predicate::DontKnowWhatToDoWithThisSexpError, Exception => e
|
69
|
-
# save it off for debugging
|
70
|
-
@@last_predicated_error = e
|
71
|
-
nil
|
72
|
-
end
|
73
|
-
|
74
|
-
code = code.color(:blue) if Wrong.config[:color]
|
75
|
-
message = ""
|
76
|
-
message << "#{explanation}: " if explanation
|
77
|
-
message << "#{valence == :deny ? "Didn't expect" : "Expected"} #{code}, but "
|
78
|
-
if predicate && !(predicate.is_a? Predicated::Conjunction)
|
79
|
-
message << summary(valence, predicate)
|
80
|
-
if formatter = FailureMessage.formatter_for(predicate)
|
81
|
-
failure = formatter.describe
|
82
|
-
failure = failure.bold if Wrong.config[:color]
|
83
|
-
message << failure
|
84
|
-
end
|
85
|
-
end
|
86
|
-
message << chunk.details
|
87
|
-
message
|
88
|
-
end
|
89
|
-
|
90
58
|
def aver(valence, explanation = nil, depth = 0, &block)
|
91
59
|
require "wrong/rainbow" if Wrong.config[:color]
|
92
60
|
|
@@ -96,7 +64,7 @@ module Wrong
|
|
96
64
|
|
97
65
|
chunk = Wrong::Chunk.from_block(block, depth + 2)
|
98
66
|
|
99
|
-
message =
|
67
|
+
message = FailureMessage.new(chunk, block, valence, explanation).full
|
100
68
|
raise failure_class.new(message)
|
101
69
|
end
|
102
70
|
end
|
data/lib/wrong/chunk.rb
CHANGED
@@ -143,7 +143,7 @@ module Wrong
|
|
143
143
|
# todo: extract some of this into Sexp
|
144
144
|
parts_list = []
|
145
145
|
begin
|
146
|
-
unless sexp.first == :arglist
|
146
|
+
unless sexp.first == :arglist # or sexp.first == :iter
|
147
147
|
code = sexp.to_ruby.strip
|
148
148
|
parts_list << code unless code == "" || parts_list.include?(code)
|
149
149
|
end
|
@@ -167,6 +167,12 @@ module Wrong
|
|
167
167
|
end
|
168
168
|
|
169
169
|
def details
|
170
|
+
@details ||= build_details
|
171
|
+
end
|
172
|
+
|
173
|
+
private
|
174
|
+
|
175
|
+
def build_details
|
170
176
|
require "wrong/rainbow" if Wrong.config[:color]
|
171
177
|
s = ""
|
172
178
|
parts = self.parts
|
@@ -215,8 +221,6 @@ module Wrong
|
|
215
221
|
|
216
222
|
end
|
217
223
|
|
218
|
-
private
|
219
|
-
|
220
224
|
def indent(indent, *s)
|
221
225
|
"#{" " * indent}#{s.join('')}"
|
222
226
|
end
|
@@ -39,5 +39,59 @@ module Wrong
|
|
39
39
|
false
|
40
40
|
end
|
41
41
|
end
|
42
|
+
|
43
|
+
|
44
|
+
attr_accessor :chunk, :block, :valence, :explanation
|
45
|
+
|
46
|
+
def initialize(chunk, block, valence, explanation)
|
47
|
+
@chunk, @block, @valence, @explanation = chunk, block, valence, explanation
|
48
|
+
end
|
49
|
+
|
50
|
+
def basic
|
51
|
+
"#{valence == :deny ? "Didn't expect" : "Expected"} #{chunk.code}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def full
|
55
|
+
message = ""
|
56
|
+
message << "#{explanation}: " if explanation
|
57
|
+
message << basic
|
58
|
+
|
59
|
+
formatted_message = if predicate && !(predicate.is_a? Predicated::Conjunction)
|
60
|
+
if formatter = FailureMessage.formatter_for(predicate)
|
61
|
+
failure = formatter.describe
|
62
|
+
failure = failure.bold if Wrong.config[:color]
|
63
|
+
failure
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
unless chunk.details.empty? and formatted_message.nil?
|
68
|
+
message << ", but"
|
69
|
+
end
|
70
|
+
|
71
|
+
message << formatted_message if formatted_message
|
72
|
+
message << chunk.details unless chunk.details.empty?
|
73
|
+
message
|
74
|
+
end
|
75
|
+
|
76
|
+
protected
|
77
|
+
def code
|
78
|
+
@code ||= begin
|
79
|
+
code = chunk.code
|
80
|
+
code = code.color(:blue) if Wrong.config[:color]
|
81
|
+
code
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def predicate
|
86
|
+
@predicate ||= begin
|
87
|
+
Predicated::Predicate.from_ruby_code_string(code, block.binding)
|
88
|
+
rescue Predicated::Predicate::DontKnowWhatToDoWithThisSexpError, Exception => e
|
89
|
+
# save it off for debugging
|
90
|
+
@@last_predicated_error = e
|
91
|
+
nil
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
|
42
96
|
end
|
43
97
|
end
|
data/lib/wrong/sexp_ext.rb
CHANGED
@@ -5,8 +5,8 @@ require 'wrong/config'
|
|
5
5
|
class Sexp < Array
|
6
6
|
|
7
7
|
def to_ruby
|
8
|
-
|
9
|
-
ruby = Ruby2Ruby.new.process(
|
8
|
+
sexp = self.deep_clone
|
9
|
+
ruby = Ruby2Ruby.new.process(sexp)
|
10
10
|
ruby
|
11
11
|
end
|
12
12
|
|
@@ -26,7 +26,7 @@ class Sexp < Array
|
|
26
26
|
self[0] == :iter and
|
27
27
|
self[1].is_a? Sexp and
|
28
28
|
self[1][0] == :call and
|
29
|
-
Wrong.config.assert_methods.include? self[1][2]
|
29
|
+
Wrong.config.assert_methods.include? self[1][2]
|
30
30
|
end
|
31
31
|
|
32
32
|
def assertion
|
data/lib/wrong/version.rb
CHANGED
@@ -61,11 +61,10 @@ describe "basic assert features" do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
msg = rescuing { MyFailingAssertTest.new.test_fail }.message
|
64
|
-
|
65
|
-
assert { msg.include?("1 is not equal to 2") }
|
64
|
+
assert { msg.include?("Expected (1 == 2)") }
|
66
65
|
|
67
66
|
msg = rescuing { MyFailingDenyTest.new.test_fail }.message
|
68
|
-
assert { msg.include?("
|
67
|
+
assert { msg.include?("Didn't expect (1 == 1)") }
|
69
68
|
end
|
70
69
|
end
|
71
70
|
|
@@ -4,4 +4,4 @@
|
|
4
4
|
# If you change this key, all old signed cookies will become invalid!
|
5
5
|
# Make sure the secret is at least 30 characters and all random,
|
6
6
|
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
-
Railsapp::Application.config.secret_token = '
|
7
|
+
Railsapp::Application.config.secret_token = '60ef44ef55c7289c9013546cef8ef9aa67efd47177d7b4dbd85535f25de545a448e97eb62b9ce64df8aad9ec765d6c08d3725b738b9cbb503b978a61d765224b'
|
@@ -32,13 +32,13 @@ class MyFailingAssertTest < Test::Unit::TestCase
|
|
32
32
|
#I can do without all the TU Listener business, thank you
|
33
33
|
failures = result.instance_variable_get("@failures".to_sym)
|
34
34
|
assert{ failures.length==1 }
|
35
|
-
assert{ failures.first.long_display.include?("1
|
35
|
+
assert{ failures.first.long_display.include?("Expected (1 == 2)") }
|
36
36
|
|
37
37
|
result = Test::Unit::TestResult.new
|
38
38
|
failures = result.instance_variable_get("@failures".to_sym)
|
39
39
|
my_failing_deny_test.new("test_fail").run(result) {|started, name| }
|
40
40
|
assert{ failures.length==1 }
|
41
|
-
assert{ failures.first.long_display.include?("
|
41
|
+
assert{ failures.first.long_display.include?("Didn't expect (1 == 1)") }
|
42
42
|
end
|
43
43
|
|
44
44
|
def test_passes_asserts_with_no_block_up_to_the_frameworks_assert_method
|
data/test/config_test.rb
CHANGED
@@ -91,7 +91,7 @@ alias_assert :yum
|
|
91
91
|
is("math is hard") { 2 + 2 == 5 }
|
92
92
|
}
|
93
93
|
expected = <<-FAIL
|
94
|
-
math is hard: Expected ((2 + 2) == 5), but
|
94
|
+
math is hard: Expected ((2 + 2) == 5), but
|
95
95
|
(2 + 2) is 4
|
96
96
|
FAIL
|
97
97
|
assert { e.message == expected }
|
@@ -118,7 +118,7 @@ math is hard: Expected ((2 + 2) == 5), but 4 is not equal to 5
|
|
118
118
|
aint("math is hard") { 2 + 2 == 4 }
|
119
119
|
}
|
120
120
|
expected = <<-FAIL
|
121
|
-
math is hard: Didn't expect ((2 + 2) == 4), but
|
121
|
+
math is hard: Didn't expect ((2 + 2) == 4), but
|
122
122
|
(2 + 2) is 4
|
123
123
|
FAIL
|
124
124
|
assert { e.message == expected }
|
@@ -36,5 +36,50 @@ module Wrong
|
|
36
36
|
assert { FailureMessage.formatters.include?(BogusFormatter)}
|
37
37
|
end
|
38
38
|
|
39
|
+
def message(options = {})
|
40
|
+
block = options[:block] || proc { 2 + 2 == 5 }
|
41
|
+
chunk = Chunk.from_block(block)
|
42
|
+
valence = options[:valence] || :assert
|
43
|
+
explanation = options[:explanation]
|
44
|
+
FailureMessage.new(chunk, block, valence, explanation)
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#basic" do
|
48
|
+
it "shows the code" do
|
49
|
+
assert { message.basic == "Expected ((2 + 2) == 5)" }
|
50
|
+
end
|
51
|
+
|
52
|
+
it "reverses the message for :deny valence" do
|
53
|
+
assert { message(:valence => :deny).basic == "Didn't expect ((2 + 2) == 5)" }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#full' do
|
58
|
+
it "contains the basic message" do
|
59
|
+
assert { message.full.include? message.basic }
|
60
|
+
end
|
61
|
+
|
62
|
+
it "contains the explanation if there is one" do
|
63
|
+
msg = message(:explanation => "the sky is falling")
|
64
|
+
assert { msg.full.include? "the sky is falling" }
|
65
|
+
end
|
66
|
+
|
67
|
+
it "doesn't say 'but' if there are no details" do
|
68
|
+
block = proc { 7 }
|
69
|
+
chunk = Chunk.from_block(block)
|
70
|
+
assert { chunk.details.empty? }
|
71
|
+
msg = message(:block => block)
|
72
|
+
deny { msg.full.include? ", but"}
|
73
|
+
end
|
74
|
+
|
75
|
+
it "say 'but' with if there are details" do
|
76
|
+
block = proc { 2 + 2 == 5 }
|
77
|
+
chunk = Chunk.from_block(block)
|
78
|
+
msg = message(:block => block)
|
79
|
+
assert { msg.full.include? ", but\n (2 + 2) is 4"}
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
39
84
|
end
|
40
85
|
end
|
data/test/failures_test.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "./test/test_helper"
|
2
2
|
|
3
3
|
require "wrong/assert"
|
4
|
+
require "wrong/sexp_ext"
|
4
5
|
|
5
6
|
describe "failures" do
|
6
7
|
|
@@ -25,51 +26,17 @@ describe "failures" do
|
|
25
26
|
end
|
26
27
|
|
27
28
|
it "equality failure" do
|
28
|
-
assert_match "1
|
29
|
+
assert_match "Expected (1 == 2)", get_error {
|
29
30
|
@m.assert { 1==2 }
|
30
31
|
}.message
|
31
|
-
assert_match "
|
32
|
+
assert_match "Didn't expect (1 == 1)", get_error {
|
32
33
|
@m.deny { 1==1 }
|
33
34
|
}.message
|
34
35
|
end
|
35
36
|
|
36
|
-
it "failure of basic operations" do
|
37
|
-
assert_match "1 is not greater than 2", get_error {
|
38
|
-
@m.assert { 1>2 }
|
39
|
-
}.message
|
40
|
-
assert_match "2 is not less than 1", get_error {
|
41
|
-
@m.assert { 2<1 }
|
42
|
-
}.message
|
43
|
-
assert_match "1 is not greater than or equal to 2", get_error {
|
44
|
-
@m.assert { 1>=2 }
|
45
|
-
}.message
|
46
|
-
assert_match "2 is not less than or equal to 1", get_error {
|
47
|
-
@m.assert { 2<=1 }
|
48
|
-
}.message
|
49
|
-
|
50
|
-
assert_match "2 is greater than 1", get_error {
|
51
|
-
@m.deny { 2>1 }
|
52
|
-
}.message
|
53
|
-
assert_match "1 is less than 2", get_error {
|
54
|
-
@m.deny { 1<2 }
|
55
|
-
}.message
|
56
|
-
assert_match "2 is greater than or equal to 1", get_error {
|
57
|
-
@m.deny { 2>=1 }
|
58
|
-
}.message
|
59
|
-
assert_match "1 is less than or equal to 2", get_error {
|
60
|
-
@m.deny { 1<=2 }
|
61
|
-
}.message
|
62
|
-
end
|
63
|
-
|
64
|
-
it "object failure" do
|
65
|
-
assert_match "Color:red is not equal to 2", get_error {
|
66
|
-
@m.assert { Color.new("red")==2 }
|
67
|
-
}.message
|
68
|
-
end
|
69
|
-
|
70
37
|
it %{multiline assert block shouldn't look any different
|
71
38
|
than when there everything is on one line} do
|
72
|
-
assert_match("1
|
39
|
+
assert_match("Expected (1 == 2)", get_error {
|
73
40
|
@m.assert {
|
74
41
|
1==
|
75
42
|
2
|
@@ -82,52 +49,45 @@ describe "failures" do
|
|
82
49
|
describe "accessing and printing values set outside of the assert" do
|
83
50
|
it "use a value in the assert defined outside of it" do
|
84
51
|
a = 1
|
85
|
-
assert_match "
|
52
|
+
assert_match "Expected (a == 2), but", get_error {
|
86
53
|
@m.assert { a==2 }
|
87
54
|
}.message
|
88
|
-
assert_match "
|
55
|
+
assert_match "Didn't expect (a == 1)", get_error {
|
89
56
|
@m.deny { a==1 }
|
90
57
|
}.message
|
91
58
|
end
|
92
59
|
end
|
93
60
|
|
94
|
-
describe "
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
@m.assert {
|
121
|
-
a = "aaa"
|
122
|
-
a=="bbb"
|
123
|
-
}
|
124
|
-
}.message)
|
125
|
-
end
|
126
|
-
end
|
61
|
+
# describe "the assert block has many statements" do
|
62
|
+
# this is not true anymore -- should it be?
|
63
|
+
# it "only pay attention to the final statement" do
|
64
|
+
# assert_match("Expected (1 == 2)", get_error {
|
65
|
+
# @m.assert {
|
66
|
+
# a = "aaa"
|
67
|
+
# b = 1 + 2
|
68
|
+
# c = ["foo", "bar"].length / 3
|
69
|
+
# if a=="aaa"
|
70
|
+
# b = 4
|
71
|
+
# end; 1==2
|
72
|
+
# }
|
73
|
+
# }.message)
|
74
|
+
# end
|
75
|
+
|
76
|
+
# this raises an error trying to evaluate 'a'
|
77
|
+
it "works even if the assertion is based on stuff set previously in the block"
|
78
|
+
# do
|
79
|
+
# assert_match(/Expected.*\(a == "bbb"\)/, get_error {
|
80
|
+
# @m.assert {
|
81
|
+
# a = "aaa"
|
82
|
+
# a=="bbb"
|
83
|
+
# }
|
84
|
+
# }.message)
|
85
|
+
# end
|
86
|
+
# end
|
127
87
|
|
128
88
|
describe "array comparisons" do
|
129
89
|
it "basic" do
|
130
|
-
assert_match
|
90
|
+
assert_match 'Expected ([1, 2] == ["a", "b"])', get_error {
|
131
91
|
@m.assert { [1, 2]==%w{a b} }
|
132
92
|
}.message
|
133
93
|
end
|
@@ -138,19 +98,14 @@ describe "failures" do
|
|
138
98
|
e = get_error {
|
139
99
|
@m.assert { {1=>2}=={"a"=>"b"} }
|
140
100
|
}
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
@m.assert { "abc".include?("cd") }
|
150
|
-
}.message
|
151
|
-
assert_match "\"abc\" includes \"bc\"", get_error {
|
152
|
-
@m.deny { "abc".include?("bc") }
|
153
|
-
}.message
|
101
|
+
# this is weird; it should realize those details are truisms -- must be a whitespace thing
|
102
|
+
expected =<<-TEXT
|
103
|
+
Expected ({ 1 => 2 } == { "a" => "b" }), but
|
104
|
+
{ 1 => 2 } is {1=>2}
|
105
|
+
{ "a" => "b" } is {"a"=>"b"}
|
106
|
+
TEXT
|
107
|
+
|
108
|
+
assert_equal expected, e.message
|
154
109
|
end
|
155
110
|
end
|
156
111
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
8
|
+
- 4
|
9
|
+
version: 0.4.4
|
10
10
|
platform: java
|
11
11
|
authors:
|
12
12
|
- Steve Conover
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-12 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -182,7 +182,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
182
182
|
requirements:
|
183
183
|
- - ">="
|
184
184
|
- !ruby/object:Gem::Version
|
185
|
-
hash:
|
185
|
+
hash: 997316472760642936
|
186
186
|
segments:
|
187
187
|
- 0
|
188
188
|
version: "0"
|