wrong 0.3.3 → 0.4.0
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 +77 -11
- data/lib/wrong.rb +20 -0
- data/lib/wrong/adapters/minitest.rb +6 -18
- data/lib/wrong/adapters/rspec.rb +18 -7
- data/lib/wrong/adapters/test_unit.rb +2 -2
- data/lib/wrong/assert.rb +45 -90
- data/lib/wrong/chunk.rb +89 -27
- data/lib/wrong/close_to.rb +7 -11
- data/lib/wrong/d.rb +42 -0
- data/lib/wrong/failure_message.rb +43 -0
- data/lib/wrong/helpers.rb +66 -0
- data/lib/wrong/irb.rb +1 -1
- data/lib/wrong/message/array_diff.rb +57 -75
- data/lib/wrong/message/string_comparison.rb +88 -0
- data/lib/wrong/message/test_context.rb +2 -0
- data/lib/{predicated/lib/predicated/sexp_patch.rb → wrong/ruby2ruby_patch.rb} +3 -5
- data/lib/wrong/sexp_ext.rb +12 -4
- data/lib/wrong/version.rb +1 -1
- data/test/adapters/rspec1/failing_spec.rb +23 -0
- data/test/adapters/rspec2/failing_spec.rb +26 -0
- data/test/adapters/rspec_test.rb +65 -4
- data/test/adapters/test_unit_test.rb +6 -1
- data/test/assert_advanced_test.rb +51 -0
- data/test/assert_test.rb +4 -48
- data/test/capturing_test.rb +4 -2
- data/test/chunk_test.rb +36 -11
- data/test/close_to_test.rb +2 -2
- data/test/config_test.rb +5 -5
- data/test/d_test.rb +64 -0
- data/test/failure_message_test.rb +40 -0
- data/test/failures_test.rb +6 -7
- data/test/message/array_diff_test.rb +18 -14
- data/test/message/{test_context_text.rb → test_context_test.rb} +2 -1
- data/test/rescuing_test.rb +5 -4
- data/test/separate.rb +4 -0
- data/test/sexp_ext_test.rb +2 -2
- data/test/string_comparison_test.rb +159 -0
- data/test/suite.rb +7 -4
- data/test/test_helper.rb +2 -0
- data/test/wrong_test.rb +60 -0
- metadata +92 -46
- data/lib/wrong/message/string_diff.rb +0 -42
- data/test/message/string_diff_test.rb +0 -89
data/lib/wrong/version.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
# This is a failing spec for testing RSpec 1.3 integration
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "bundler"
|
5
|
+
Bundler.setup
|
6
|
+
|
7
|
+
require "spec"
|
8
|
+
|
9
|
+
here = File.expand_path(File.dirname(__FILE__))
|
10
|
+
$:.unshift "#{here}/../../../lib"
|
11
|
+
require "wrong/adapters/rspec"
|
12
|
+
|
13
|
+
# since we're not running 'spec' we have to do some stuff ourselves
|
14
|
+
include Spec::DSL::Main
|
15
|
+
|
16
|
+
describe "arithmetic" do
|
17
|
+
it "should not work like this" do
|
18
|
+
assert { 2 + 2 == 5 }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Spec::Runner.options.parse_format("nested")
|
23
|
+
Spec::Runner.options.run_examples
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# This is a failing spec for testing RSpec 2 integration
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "bundler"
|
5
|
+
Bundler.setup
|
6
|
+
|
7
|
+
require "rspec"
|
8
|
+
|
9
|
+
here = File.expand_path(File.dirname(__FILE__))
|
10
|
+
$:.unshift "#{here}/../../../lib"
|
11
|
+
|
12
|
+
# since we're not running 'rspec' we have to do some stuff ourselves
|
13
|
+
require 'rspec'
|
14
|
+
require 'rspec/core'
|
15
|
+
puts RSpec::Core::Version::STRING
|
16
|
+
|
17
|
+
require 'rspec/autorun'
|
18
|
+
require "wrong/adapters/rspec"
|
19
|
+
|
20
|
+
describe "arithmetic" do
|
21
|
+
it "should not work like this" do
|
22
|
+
assert { 2 + 2 == 5 }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# now, thanks to the require 'rspec/autorun', this spec will run and fail
|
data/test/adapters/rspec_test.rb
CHANGED
@@ -1,10 +1,70 @@
|
|
1
|
+
here = File.expand_path(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require "open3"
|
4
|
+
require "fileutils"
|
5
|
+
|
1
6
|
require "./test/test_helper"
|
7
|
+
require "wrong/adapters/minitest"
|
8
|
+
|
9
|
+
include Wrong
|
2
10
|
|
11
|
+
# Okay, this looks like RSpec but it's actually minitest
|
3
12
|
describe "testing rspec" do
|
4
|
-
it "works" do
|
5
13
|
|
6
|
-
|
7
|
-
|
14
|
+
def sys(cmd, expected_status = 0)
|
15
|
+
start_time = Time.now
|
16
|
+
$stderr.print cmd
|
17
|
+
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thread|
|
18
|
+
# in Ruby 1.8, wait_thread is nil :-( so just pretend the process was successful (status 0)
|
19
|
+
exit_status = (wait_thread.value.exitstatus if wait_thread) || 0
|
20
|
+
output = stdout.read + stderr.read
|
21
|
+
unless expected_status.nil?
|
22
|
+
assert { output and exit_status == expected_status }
|
23
|
+
end
|
24
|
+
yield output if block_given?
|
25
|
+
output
|
26
|
+
end
|
27
|
+
ensure
|
28
|
+
$stderr.puts " (#{"%.2f" % (Time.now - start_time)} sec)"
|
29
|
+
end
|
30
|
+
|
31
|
+
def clear_bundler_env
|
32
|
+
# Bundler inherits its environment by default, so clear it here
|
33
|
+
%w{BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE}.each { |var| ENV.delete(var) }
|
34
|
+
end
|
35
|
+
|
36
|
+
[1, 2].each do |rspec_version|
|
37
|
+
it "version #{rspec_version}" do
|
38
|
+
dir = "#{here}/rspec#{rspec_version}"
|
39
|
+
spec_output = nil
|
40
|
+
Dir.chdir(dir) do
|
41
|
+
clear_bundler_env
|
42
|
+
FileUtils.rm "#{dir}/Gemfile.lock", :force => true
|
43
|
+
|
44
|
+
sys "bundle check" do |output|
|
45
|
+
unless output == "The Gemfile's dependencies are satisfied\n"
|
46
|
+
sys "bundle install --gemfile=#{dir}/Gemfile --local"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
sys "bundle list" do |output|
|
51
|
+
lines = output.split("\n")
|
52
|
+
lines.grep(/rspec/) do |line|
|
53
|
+
assert { line =~ /rspec[-\w]* \(#{rspec_version}\.[\w.]*\)/ }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
spec_output = sys "ruby #{dir}/failing_spec.rb",
|
58
|
+
(rspec_version == 1 || RUBY_VERSION =~ /^1\.8\./ || RUBY_VERSION == '1.9.1' ? nil : 1) # RSpec v1 exits with 0 on failure :-(
|
59
|
+
end
|
60
|
+
|
61
|
+
assert { spec_output.include? "1 example, 1 failure" }
|
62
|
+
assert { spec_output.include? "Expected ((2 + 2) == 5), but" }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
=begin
|
8
68
|
# I would use
|
9
69
|
# out, err = capturing(:stdout, :stderr) do
|
10
70
|
# but minitest does its own arcane stream munging and it's not working
|
@@ -38,6 +98,7 @@ inside rspec land
|
|
38
98
|
assert !failures.empty?
|
39
99
|
exception = failures.first.exception
|
40
100
|
assert(exception.is_a?(Spec::Expectations::ExpectationNotMetError))
|
41
|
-
assert(exception.message
|
101
|
+
assert(exception.message =~ /^Expected \(sky == \"green\"\), but/, "message is #{exception.message.inspect}")
|
42
102
|
end
|
43
103
|
end
|
104
|
+
=end
|
@@ -2,9 +2,14 @@ require "./test/test_helper"
|
|
2
2
|
|
3
3
|
require "test/unit"
|
4
4
|
|
5
|
-
require "wrong/assert"
|
5
|
+
#require "wrong/assert"
|
6
6
|
require "wrong/adapters/test_unit"
|
7
7
|
|
8
|
+
# get rid of atrocious Test::Unit color scheme (gray on green = puke)
|
9
|
+
Test::Unit::AutoRunner.setup_option do |auto_runner, opts|
|
10
|
+
auto_runner.runner_options[:use_color] = false
|
11
|
+
end
|
12
|
+
|
8
13
|
class MyFailingAssertTest < Test::Unit::TestCase
|
9
14
|
|
10
15
|
def test_wrong_assert_and_deny_are_available_to_test_unit_tests
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "./test/test_helper"
|
2
|
+
require "wrong/assert"
|
3
|
+
require "wrong/adapters/minitest"
|
4
|
+
|
5
|
+
describe "advanced assert features" do
|
6
|
+
|
7
|
+
def assert_later(&p)
|
8
|
+
assert(&p)
|
9
|
+
end
|
10
|
+
|
11
|
+
# dunno why, but this fails under JRuby (both 1.8 and 1.9)
|
12
|
+
unless Object.const_defined? :JRuby
|
13
|
+
it "is possible (but hardly advisable) to define procs in different places from the assert call" do
|
14
|
+
x = 10
|
15
|
+
e = get_error do
|
16
|
+
assert_later { x > 10 }
|
17
|
+
end
|
18
|
+
|
19
|
+
assert(e.message =~ /Expected \(x > 10\), but.*x is 10/m, e.message)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
xit "can parse a here doc defined inside the block" do
|
24
|
+
# todo: test in Chunk too
|
25
|
+
assert { "123\n456" == <<-TEXT
|
26
|
+
123
|
27
|
+
456
|
28
|
+
TEXT
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
xit "can parse a here doc defined outside the block" do
|
33
|
+
# todo: test in Chunk too
|
34
|
+
assert { "123\n456" == <<-TEXT }
|
35
|
+
123
|
36
|
+
456
|
37
|
+
TEXT
|
38
|
+
end
|
39
|
+
|
40
|
+
it "finds the file to parse even when inside a chdir to a child directory" do
|
41
|
+
e = get_error do
|
42
|
+
Dir.chdir("test") do
|
43
|
+
assert { (1 + 2) == 5 }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
assert { e.message.include? "Expected ((1 + 2) == 5), but" }
|
47
|
+
end
|
48
|
+
|
49
|
+
# todo: test for finding it if you'd changed dirs into a parent or sibling or cousin dir
|
50
|
+
|
51
|
+
end
|
data/test/assert_test.rb
CHANGED
@@ -47,14 +47,14 @@ describe "basic assert features" do
|
|
47
47
|
sky = "green"
|
48
48
|
@m.assert("the sky should be blue") { sky == "blue" }
|
49
49
|
}
|
50
|
-
assert e.message =~ /^the sky should be blue:
|
50
|
+
assert e.message =~ /^the sky should be blue: /, e.message
|
51
51
|
end
|
52
52
|
|
53
53
|
it "gives a meaningful error when passed no block" do
|
54
54
|
e = get_error {
|
55
55
|
@m.assert(2+2 == 5)
|
56
56
|
}
|
57
|
-
assert e.message =~ /a block
|
57
|
+
assert e.message =~ /a block/, e.message
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -68,53 +68,9 @@ describe "basic assert features" do
|
|
68
68
|
sky = "blue"
|
69
69
|
@m.deny("the sky should not be blue") { sky == "blue" }
|
70
70
|
}
|
71
|
-
assert e.message =~ /^the sky should not be blue:
|
71
|
+
assert e.message =~ /^the sky should not be blue: /,
|
72
|
+
e.message + "\n\t" + e.backtrace.join("\n\t")
|
72
73
|
end
|
73
74
|
end
|
74
75
|
end
|
75
76
|
end
|
76
|
-
|
77
|
-
describe "advanced assert features" do
|
78
|
-
include Wrong::Assert
|
79
|
-
|
80
|
-
def assert_many(*procs)
|
81
|
-
failures = []
|
82
|
-
procs.each do |proc|
|
83
|
-
begin
|
84
|
-
assert(nil, 3, &proc)
|
85
|
-
rescue => e
|
86
|
-
failures << e
|
87
|
-
end
|
88
|
-
end
|
89
|
-
assert { failures.empty? }
|
90
|
-
end
|
91
|
-
|
92
|
-
it "is possible (but not advisable) to define procs in different places from the assert call" do
|
93
|
-
x = 10
|
94
|
-
e = rescuing do
|
95
|
-
assert_many(lambda { x == 10 })
|
96
|
-
assert_many(lambda { x > 10 })
|
97
|
-
end
|
98
|
-
|
99
|
-
assert { e.message =~ /^Expected failures.empty\?/ }
|
100
|
-
assert { e.message =~ /x is 10/ }
|
101
|
-
end
|
102
|
-
|
103
|
-
xit "can parse a here doc defined inside the block" do
|
104
|
-
# todo: test in Chunk too
|
105
|
-
assert { "123\n456" == <<-TEXT
|
106
|
-
123
|
107
|
-
456
|
108
|
-
TEXT
|
109
|
-
}
|
110
|
-
end
|
111
|
-
|
112
|
-
xit "can parse a here doc defined outside the block" do
|
113
|
-
# todo: test in Chunk too
|
114
|
-
assert { "123\n456" == <<-TEXT }
|
115
|
-
123
|
116
|
-
456
|
117
|
-
TEXT
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
data/test/capturing_test.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require "./test/test_helper"
|
2
2
|
|
3
3
|
require "wrong/assert"
|
4
|
-
require "wrong/
|
4
|
+
require "wrong/helpers"
|
5
5
|
|
6
6
|
describe "a tool for capturing output" do
|
7
7
|
|
8
|
+
include Wrong::Assert
|
9
|
+
include Wrong::Helpers
|
10
|
+
|
8
11
|
it "captures stdout" do
|
9
12
|
assert {
|
10
13
|
capturing { puts "hi" } == "hi\n"
|
@@ -29,7 +32,6 @@ describe "a tool for capturing output" do
|
|
29
32
|
end
|
30
33
|
|
31
34
|
it "supports nesting" do
|
32
|
-
outside = nil
|
33
35
|
inside = nil
|
34
36
|
outside = capturing do
|
35
37
|
puts "bread"
|
data/test/chunk_test.rb
CHANGED
@@ -27,12 +27,12 @@ describe Chunk do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
describe "
|
30
|
+
describe "parsing" do
|
31
31
|
it "reads a statement on a line by itself" do
|
32
32
|
chunk = Chunk.new(__FILE__, __LINE__ + 1); <<-CODE
|
33
33
|
"hi"
|
34
34
|
CODE
|
35
|
-
code = chunk.
|
35
|
+
code = chunk.sexp.to_ruby
|
36
36
|
assert(code == '"hi"')
|
37
37
|
end
|
38
38
|
|
@@ -42,7 +42,7 @@ describe Chunk do
|
|
42
42
|
"hi"
|
43
43
|
end
|
44
44
|
CODE
|
45
|
-
code = chunk.
|
45
|
+
code = chunk.sexp.to_ruby
|
46
46
|
assert(code == "proc { \"hi\" }")
|
47
47
|
end
|
48
48
|
|
@@ -50,29 +50,38 @@ describe Chunk do
|
|
50
50
|
chunk = Chunk.new(__FILE__, __LINE__ + 1); <<-CODE
|
51
51
|
"hi" )
|
52
52
|
CODE
|
53
|
-
assert(chunk.
|
53
|
+
assert(chunk.sexp.nil?)
|
54
54
|
end
|
55
55
|
|
56
56
|
it "fails if there's a stray close-block symbol on the last line (sorry)" do
|
57
57
|
chunk = Chunk.new(__FILE__, __LINE__ + 1); <<-CODE
|
58
58
|
"hi" }
|
59
59
|
CODE
|
60
|
-
assert(chunk.
|
60
|
+
assert(chunk.sexp.nil?)
|
61
61
|
end
|
62
62
|
|
63
63
|
it "fails if it can't parse the code" do
|
64
64
|
chunk = Chunk.new(__FILE__, __LINE__ + 1); <<-CODE
|
65
65
|
}
|
66
66
|
CODE
|
67
|
-
assert(chunk.
|
67
|
+
assert(chunk.sexp.nil?)
|
68
68
|
end
|
69
69
|
|
70
70
|
it "fails if it can't find the file" do
|
71
71
|
chunk = Chunk.new("nonexistent_file.rb", 0)
|
72
|
-
error = get_error { chunk.
|
72
|
+
error = get_error { chunk.sexp }
|
73
73
|
assert error.is_a? Errno::ENOENT
|
74
74
|
end
|
75
75
|
|
76
|
+
it "finds the file to parse even when inside a chdir to a child directory" do
|
77
|
+
Dir.chdir("test") do
|
78
|
+
chunk = Chunk.new __FILE__, __LINE__ + 1; <<-CODE
|
79
|
+
"hi"
|
80
|
+
CODE
|
81
|
+
code = chunk.sexp.to_ruby
|
82
|
+
assert(code == '"hi"')
|
83
|
+
end
|
84
|
+
end
|
76
85
|
end
|
77
86
|
|
78
87
|
describe "#claim" do
|
@@ -80,7 +89,7 @@ describe Chunk do
|
|
80
89
|
chunk = Chunk.new(__FILE__, __LINE__ + 1); <<-CODE
|
81
90
|
assert { x == 5 }
|
82
91
|
CODE
|
83
|
-
full_code = chunk.
|
92
|
+
full_code = chunk.sexp.to_ruby
|
84
93
|
assert(full_code == "assert { (x == 5) }")
|
85
94
|
claim_code = chunk.claim.to_ruby
|
86
95
|
assert claim_code == "(x == 5)"
|
@@ -158,6 +167,14 @@ z
|
|
158
167
|
10
|
159
168
|
PARTS
|
160
169
|
end
|
170
|
+
|
171
|
+
it "omits the method-call-sans-block part of a method call with a block" do
|
172
|
+
chunk = Chunk.new(__FILE__, __LINE__ + 1); <<-CODE
|
173
|
+
assert { rescuing { 1 + 2 } }
|
174
|
+
CODE
|
175
|
+
code_parts = chunk.parts
|
176
|
+
assert !code_parts.include?("rescuing")
|
177
|
+
end
|
161
178
|
end
|
162
179
|
|
163
180
|
describe "#details" do
|
@@ -209,15 +226,21 @@ z
|
|
209
226
|
end
|
210
227
|
|
211
228
|
it "shows exceptions" do
|
212
|
-
d = details { assert { (raise "hi") == 1} }
|
229
|
+
d = details { assert { (raise "hi") == 1 } }
|
213
230
|
assert d == "\n raise(\"hi\") raises RuntimeError: hi\n"
|
214
231
|
end
|
215
232
|
|
216
233
|
it "indents newlines inside the exception message" do
|
217
|
-
d = details { assert { (raise "hello\nsailor") == 1} }
|
234
|
+
d = details { assert { (raise "hello\nsailor") == 1 } }
|
218
235
|
assert d == "\n raise(\"hello\\nsailor\") raises RuntimeError: hello\n sailor\n"
|
219
236
|
end
|
220
237
|
|
238
|
+
it "abridges exceptions with no message" do
|
239
|
+
d = details { assert { (raise Exception.new) == 1 } }
|
240
|
+
assert d == "\n raise(Exception.new) raises Exception\n" +
|
241
|
+
" Exception.new is #<Exception: Exception>\n"
|
242
|
+
end
|
243
|
+
|
221
244
|
it "inspects values" do
|
222
245
|
x = "flavor:\tvanilla"
|
223
246
|
d = details { assert { x == "flavor:\tchocolate" } }
|
@@ -227,11 +250,13 @@ z
|
|
227
250
|
|
228
251
|
it "indents unescaped newlines inside the inspected value" do
|
229
252
|
weirdo = Object.new
|
253
|
+
|
230
254
|
def weirdo.inspect
|
231
255
|
"first\nsecond\nthird"
|
232
256
|
end
|
257
|
+
|
233
258
|
x = weirdo
|
234
|
-
d = details { assert { x == "foo" }}
|
259
|
+
d = details { assert { x == "foo" } }
|
235
260
|
assert d == "\n x is first\n second\n third\n"
|
236
261
|
end
|
237
262
|
|
data/test/close_to_test.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require "./test/test_helper"
|
2
2
|
require "wrong/close_to"
|
3
|
-
require "wrong
|
3
|
+
require "wrong"
|
4
4
|
|
5
5
|
describe "#close_to? (monkey patch for float comparison)" do
|
6
|
-
include Wrong
|
6
|
+
include Wrong
|
7
7
|
|
8
8
|
it "says two equal floats are equal" do
|
9
9
|
assert { 5.0.close_to? 5.0 }
|
data/test/config_test.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require "./test/test_helper"
|
2
|
-
require "wrong/config"
|
3
|
-
require "wrong/assert"
|
4
|
-
require "wrong/message/string_diff"
|
5
2
|
|
3
|
+
require "wrong"
|
4
|
+
require "wrong/config"
|
5
|
+
require "wrong/message/string_comparison"
|
6
6
|
|
7
7
|
describe Wrong::Config do
|
8
8
|
|
9
9
|
# hope this doesn't blow up, but I'll try to use Wrong to test the Config object
|
10
|
-
include Wrong
|
10
|
+
include Wrong
|
11
11
|
|
12
12
|
before do
|
13
13
|
Wrong.config.clear
|
@@ -20,7 +20,7 @@ describe Wrong::Config do
|
|
20
20
|
assert { c.object_id == c2.object_id }
|
21
21
|
end
|
22
22
|
|
23
|
-
# it "
|
23
|
+
# it "reads from a .wrong file"
|
24
24
|
|
25
25
|
it "getting an undeclared setting" do
|
26
26
|
assert { Wrong.config[:foo].nil? }
|