wrong 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  require "./test/test_helper"
2
2
  require "wrong/adapters/rspec"
3
3
 
4
- regarding "testing rspec" do
4
+ describe "testing rspec" do
5
5
  it "works" do
6
6
  # I would use
7
7
  # out, err = capturing(:stdout, :stderr) do
@@ -6,19 +6,8 @@ require "wrong/assert"
6
6
  require "wrong/adapters/test_unit"
7
7
 
8
8
  class MyFailingAssertTest < Test::Unit::TestCase
9
-
10
- def test_strip_out_other_assert_methods
11
- #because they call into assert and we're redfining that method so it's potentially confusing
12
-
13
- begin
14
- Class.new(Test::Unit::TestCase).assert_equal(1, 1)
15
- rescue StandardError => e
16
- e.message.include?("has been disabled")
17
- end
18
- end
19
-
20
-
21
- def test_assert_and_deny_are_available_to_test_unit_tests
9
+
10
+ def test_wrong_assert_and_deny_are_available_to_test_unit_tests
22
11
  my_failing_assert_test = Class.new(Test::Unit::TestCase)
23
12
  my_failing_assert_test.class_eval do
24
13
  def test_fail
@@ -46,5 +35,20 @@ class MyFailingAssertTest < Test::Unit::TestCase
46
35
  assert{ failures.length==1 }
47
36
  assert{ failures.first.long_display.include?("1 is equal to 1") }
48
37
  end
49
-
38
+
39
+ def test_passes_asserts_with_no_block_up_to_the_frameworks_assert_method
40
+ e = rescuing { assert(1 == 2) }
41
+ assert { e.message == "<false> is not true." }
42
+
43
+ e = rescuing { assert(1 == 2, "black is white") }
44
+ assert { e.message == "black is white.\n<false> is not true." }
45
+ end
46
+
47
+ def test_passes_denys_with_no_block_up_to_the_frameworks_assert_method
48
+ e = rescuing { deny(2 + 2 == 4) }
49
+ assert { e.message == "<false> is not true." }
50
+
51
+ e = rescuing { deny(2 + 2 == 4, "up is down") }
52
+ assert { e.message == "up is down.\n<false> is not true." }
53
+ end
50
54
  end
@@ -1,7 +1,7 @@
1
1
  require "./test/test_helper"
2
2
  require "wrong/assert"
3
3
 
4
- regarding "basic assert features" do
4
+ describe "basic assert features" do
5
5
 
6
6
  before do
7
7
  @m = Module.new do
@@ -9,8 +9,8 @@ regarding "basic assert features" do
9
9
  end
10
10
  end
11
11
 
12
- regarding "pass/fail basics" do
13
- test "passes when the result is true. deny does the reverse" do
12
+ describe "pass/fail basics" do
13
+ it "passes when the result is true. deny does the reverse" do
14
14
  @m.assert { true }
15
15
  @m.assert { 1==1 }
16
16
 
@@ -18,7 +18,7 @@ regarding "basic assert features" do
18
18
  @m.deny { 1==2 }
19
19
  end
20
20
 
21
- test "fails when result is false. deny does the reverse" do
21
+ it "fails when result is false. deny does the reverse" do
22
22
  get_error {
23
23
  @m.assert { false }
24
24
  } || fail
@@ -37,31 +37,44 @@ regarding "basic assert features" do
37
37
  class MyError < StandardError;
38
38
  end
39
39
 
40
- test "both deny and assert fail when an error is thrown. bubbles up the error." do
41
- assert_raises(MyError) { @m.assert { raise MyError.new } }
42
- assert_raises(MyError) { @m.deny { raise MyError.new } }
43
- end
40
+ describe "assert" do
41
+ it "fails when an error is thrown and bubbles up the error" do
42
+ assert_raises(MyError) { @m.assert { raise MyError.new } }
43
+ end
44
+
45
+ it "takes an optional explanation" do
46
+ e = get_error {
47
+ sky = "green"
48
+ @m.assert("the sky should be blue") { sky == "blue" }
49
+ }
50
+ assert e.message =~ /^the sky should be blue: /
51
+ end
44
52
 
45
- test "assert takes an optional explanation" do
46
- e = get_error {
47
- sky = "green"
48
- @m.assert("the sky should be blue") { sky == "blue" }
49
- }
50
- assert e.message =~ /^the sky should be blue: /
53
+ it "gives a meaningful error when passed no block" do
54
+ e = get_error {
55
+ @m.assert (2+2 == 5)
56
+ }
57
+ assert e.message =~ /a block/
58
+ end
51
59
  end
52
60
 
53
- test "deny takes an optional explanation" do
54
- e = get_error {
55
- sky = "blue"
56
- @m.deny("the sky should not be blue") { sky == "blue" }
57
- }
58
- assert e.message =~ /^the sky should not be blue: /
61
+ describe "deny" do
62
+ it "fails when an error is thrown and bubbles up the error" do
63
+ assert_raises(MyError) { @m.deny { raise MyError.new } }
64
+ end
65
+
66
+ it "takes an optional explanation" do
67
+ e = get_error {
68
+ sky = "blue"
69
+ @m.deny("the sky should not be blue") { sky == "blue" }
70
+ }
71
+ assert e.message =~ /^the sky should not be blue: /
72
+ end
59
73
  end
60
74
  end
61
75
  end
62
76
 
63
-
64
- regarding "advanced assert features" do
77
+ describe "advanced assert features" do
65
78
  include Wrong::Assert
66
79
 
67
80
  def assert_many(*procs)
@@ -76,7 +89,7 @@ regarding "advanced assert features" do
76
89
  assert { failures.empty? }
77
90
  end
78
91
 
79
- test "it's possible (but not advisable) to define procs in different places from the assert call" do
92
+ it "is possible (but not advisable) to define procs in different places from the assert call" do
80
93
  x = 10
81
94
  e = rescuing do
82
95
  assert_many(lambda { x == 10 })
@@ -87,4 +100,21 @@ regarding "advanced assert features" do
87
100
  assert { e.message =~ /x is 10/ }
88
101
  end
89
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
+
90
120
  end
@@ -3,21 +3,21 @@ require "./test/test_helper"
3
3
  require "wrong/assert"
4
4
  require "wrong/adapters/minitest"
5
5
 
6
- regarding "a tool for capturing output" do
6
+ describe "a tool for capturing output" do
7
7
 
8
- test "captures stdout" do
8
+ it "captures stdout" do
9
9
  assert {
10
10
  capturing { puts "hi" } == "hi\n"
11
11
  }
12
12
  end
13
13
 
14
- test "captures stderr" do
14
+ it "captures stderr" do
15
15
  assert {
16
16
  capturing(:stderr) { $stderr.puts "hi" } == "hi\n"
17
17
  }
18
18
  end
19
19
 
20
- test "captures both" do
20
+ it "captures both" do
21
21
  out, err = capturing(:stdout, :stderr) do
22
22
  $stdout.puts "hi"
23
23
  $stderr.puts "bye"
@@ -28,7 +28,7 @@ regarding "a tool for capturing output" do
28
28
 
29
29
  end
30
30
 
31
- test "supports nesting" do
31
+ it "supports nesting" do
32
32
  outside = nil
33
33
  inside = nil
34
34
  outside = capturing do
@@ -44,7 +44,7 @@ regarding "a tool for capturing output" do
44
44
  end
45
45
 
46
46
 
47
- test "bails if stream was reassigned" do
47
+ it "bails if stream was reassigned" do
48
48
  e = rescuing do
49
49
  capturing do
50
50
  $stdout = StringIO.new # uh-oh!
@@ -5,9 +5,9 @@ unless Object.const_defined?(:Chunk)
5
5
  Chunk = Wrong::Chunk
6
6
  end
7
7
 
8
- regarding Chunk do
9
- regarding "#from_block" do
10
- test "reads the source location" do
8
+ describe Chunk do
9
+ describe "#from_block" do
10
+ it "reads the source location" do
11
11
  file, line = __FILE__, __LINE__
12
12
  chunk = Chunk.from_block(proc { "hi" })
13
13
  assert(chunk.file == file)
@@ -15,20 +15,20 @@ regarding Chunk do
15
15
  end
16
16
  end
17
17
 
18
- regarding "line numbers" do
18
+ describe "line numbers" do
19
19
  before do
20
20
  @chunk = Wrong::Chunk.new("foo.rb", 10)
21
21
  end
22
- test "#line_index is zero-based" do
22
+ it "#line_index is zero-based" do
23
23
  assert(@chunk.line_index == 9)
24
24
  end
25
- test "#location is one-based" do
25
+ it "#location is one-based" do
26
26
  assert(@chunk.location == "foo.rb:10")
27
27
  end
28
28
  end
29
29
 
30
- regarding "#parse" do
31
- test "reads a statement on a line by itself" do
30
+ describe "#parse" do
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
@@ -36,7 +36,7 @@ regarding Chunk do
36
36
  assert(code == '"hi"')
37
37
  end
38
38
 
39
- test "reads a statement on multiple lines" do
39
+ it "reads a statement on multiple lines" do
40
40
  chunk = Chunk.new(__FILE__, __LINE__ + 1); <<-CODE
41
41
  proc do
42
42
  "hi"
@@ -46,28 +46,28 @@ regarding Chunk do
46
46
  assert(code == "proc { \"hi\" }")
47
47
  end
48
48
 
49
- test "fails if there's a stray close-paren symbol on the last line (sorry)" do
49
+ it "fails if there's a stray close-paren symbol on the last line (sorry)" do
50
50
  chunk = Chunk.new(__FILE__, __LINE__ + 1); <<-CODE
51
51
  "hi" )
52
52
  CODE
53
53
  assert(chunk.parse.nil?)
54
54
  end
55
55
 
56
- test "fails if there's a stray close-block symbol on the last line (sorry)" do
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
60
  assert(chunk.parse.nil?)
61
61
  end
62
62
 
63
- test "fails if it can't parse the code" do
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
67
  assert(chunk.parse.nil?)
68
68
  end
69
69
 
70
- test "fails if it can't find the file" do
70
+ it "fails if it can't find the file" do
71
71
  chunk = Chunk.new("nonexistent_file.rb", 0)
72
72
  error = get_error { chunk.parse }
73
73
  assert error.is_a? Errno::ENOENT
@@ -75,8 +75,8 @@ regarding Chunk do
75
75
 
76
76
  end
77
77
 
78
- regarding "#claim" do
79
- test "returns the part of the assertion statement inside the curly braces" do
78
+ describe "#claim" do
79
+ it "returns the part of the assertion statement inside the curly braces" do
80
80
  chunk = Chunk.new(__FILE__, __LINE__ + 1); <<-CODE
81
81
  assert { x == 5 }
82
82
  CODE
@@ -87,7 +87,7 @@ regarding Chunk do
87
87
  end
88
88
 
89
89
 
90
- test "reads an assert statement on a line by itself" do
90
+ it "reads an assert statement on a line by itself" do
91
91
  chunk = Chunk.new(__FILE__, __LINE__ + 1); <<-CODE
92
92
  assert { x == 5 }
93
93
  CODE
@@ -95,7 +95,7 @@ regarding Chunk do
95
95
  assert claim_code == "(x == 5)"
96
96
  end
97
97
 
98
- test "reads an assert statement on multiple lines" do
98
+ it "reads an assert statement on multiple lines" do
99
99
  chunk = Chunk.new(__FILE__, __LINE__ + 1); <<-CODE
100
100
  assert do
101
101
  x == 5
@@ -110,7 +110,7 @@ regarding Chunk do
110
110
  end
111
111
 
112
112
  if RUBY_VERSION > "1.9"
113
- test "reads an assert statement that's nested inside another yield block on the same line (Ruby 1.9 only)" do
113
+ it "reads an assert statement that's nested inside another yield block on the same line (Ruby 1.9 only)" do
114
114
  chunk = Chunk.new(__FILE__, __LINE__ + 1); <<-CODE
115
115
  yielding { assert { x == 5 }}
116
116
  CODE
@@ -121,7 +121,7 @@ regarding Chunk do
121
121
  # test "goes crazy if you try to nest two asserts on the same line"
122
122
  end
123
123
 
124
- test "if it can't find an assertion, it uses the whole chunk" do
124
+ it "if it can't find an assertion, it uses the whole chunk" do
125
125
  chunk = Chunk.new(__FILE__, __LINE__ + 1); <<-CODE
126
126
  yielding { x == 5 }
127
127
  CODE
@@ -129,7 +129,7 @@ regarding Chunk do
129
129
  assert code == "yielding { (x == 5) }"
130
130
  end
131
131
 
132
- test "fails if it can't parse the code" do
132
+ it "fails if it can't parse the code" do
133
133
  chunk = Chunk.new(__FILE__, __LINE__ + 1); <<-CODE
134
134
  }
135
135
  CODE
@@ -140,8 +140,8 @@ regarding Chunk do
140
140
  end
141
141
  end
142
142
 
143
- regarding "#parts" do
144
- test "returns all unique sub-expressions of the main sexpression" do
143
+ describe "#parts" do
144
+ it "returns all unique sub-expressions of the main sexpression" do
145
145
  chunk = Chunk.new(__FILE__, __LINE__ + 1); <<-CODE
146
146
  assert { (x == 5) && (y == (z + 10)) }
147
147
  CODE
@@ -160,7 +160,7 @@ z
160
160
  end
161
161
  end
162
162
 
163
- regarding "#details" do
163
+ describe "#details" do
164
164
  def details(&block)
165
165
  chunk = Chunk.from_block(block, 1)
166
166
  d = chunk.details
@@ -168,23 +168,23 @@ z
168
168
  d
169
169
  end
170
170
 
171
- test "returns an empty string if there are no parts" do
171
+ it "returns an empty string if there are no parts" do
172
172
  d = details { assert { true } }
173
173
  assert d == ""
174
174
  end
175
175
 
176
- test "returns an string beginning with a newline if there are parts" do
176
+ it "returns an string beginning with a newline if there are parts" do
177
177
  x = 10
178
178
  d = details { assert { x == 10 } }
179
179
  assert d == "\n x is 10\n"
180
180
  end
181
181
 
182
- test "skips literals" do
182
+ it "skips literals" do
183
183
  d = details { assert { 10 == 11 } }
184
184
  assert d == ""
185
185
  end
186
186
 
187
- test "shows lots of details" do
187
+ it "shows lots of details" do
188
188
  x = 10
189
189
  d = details { assert { (x * (x - 10)) == (x / (x + 10)) } }
190
190
  assert d == <<-DETAILS
@@ -197,7 +197,7 @@ z
197
197
  DETAILS
198
198
  end
199
199
 
200
- test "skips duplicates" do
200
+ it "skips duplicates" do
201
201
  x = 10
202
202
  d = details { assert { (x + 5) == 1 + (x + 5) } }
203
203
  assert d == <<-DETAILS
@@ -208,24 +208,24 @@ z
208
208
  DETAILS
209
209
  end
210
210
 
211
- test "shows exceptions" do
211
+ it "shows exceptions" do
212
212
  d = details { assert { (raise "hi") == 1} }
213
213
  assert d == "\n raise(\"hi\") raises RuntimeError: hi\n"
214
214
  end
215
215
 
216
- test "indents newlines inside the exception message" do
216
+ it "indents newlines inside the exception message" do
217
217
  d = details { assert { (raise "hello\nsailor") == 1} }
218
218
  assert d == "\n raise(\"hello\\nsailor\") raises RuntimeError: hello\n sailor\n"
219
219
  end
220
220
 
221
- test "inspects values" do
221
+ it "inspects values" do
222
222
  x = "flavor:\tvanilla"
223
223
  d = details { assert { x == "flavor:\tchocolate" } }
224
224
  # this means it's a literal slash plus t inside double quotes -- i.e. it shows the escaped (inspected) string
225
225
  assert d == "\n" + ' x is "flavor:\tvanilla"' + "\n"
226
226
  end
227
227
 
228
- test "indents unescaped newlines inside the inspected value" do
228
+ it "indents unescaped newlines inside the inspected value" do
229
229
  weirdo = Object.new
230
230
  def weirdo.inspect
231
231
  "first\nsecond\nthird"
@@ -2,7 +2,7 @@ require "./test/test_helper"
2
2
  require "wrong/close_to"
3
3
  require "wrong/assert"
4
4
 
5
- regarding "#close_to? (monkey patch for float comparison)" do
5
+ describe "#close_to? (monkey patch for float comparison)" do
6
6
  include Wrong::Assert
7
7
 
8
8
  it "says two equal floats are equal" do
@@ -1,8 +1,10 @@
1
1
  require "./test/test_helper"
2
2
  require "wrong/config"
3
3
  require "wrong/assert"
4
+ require "wrong/message/string_diff"
4
5
 
5
- regarding Wrong::Config do
6
+
7
+ describe Wrong::Config do
6
8
 
7
9
  # hope this doesn't blow up, but I'll try to use Wrong to test the Config object
8
10
  include Wrong::Assert
@@ -11,22 +13,77 @@ regarding Wrong::Config do
11
13
  Wrong.config.clear
12
14
  end
13
15
 
14
- test "singleton" do
16
+ it "singleton" do
15
17
  c = Wrong.config
16
18
  assert { c.is_a?(Wrong::Config) }
17
19
  c2 = Wrong.config
18
20
  assert { c.object_id == c2.object_id }
19
21
  end
20
22
 
21
- # test "reading from a .wrong file"
23
+ # it "reading from a .wrong file"
22
24
 
23
- test "getting an undeclared setting" do
25
+ it "getting an undeclared setting" do
24
26
  assert { Wrong.config[:foo].nil? }
25
27
  end
26
28
 
27
- test "setting and getting" do
29
+ it "setting and getting" do
28
30
  Wrong.config[:foo] = "bar"
29
31
  assert { Wrong.config[:foo] == "bar" }
30
32
  end
31
-
33
+
34
+ describe "adding aliases for assert" do
35
+ before do
36
+ Wrong.config.alias_assert(:is)
37
+ end
38
+
39
+ it "succeeds" do
40
+ is { 2 + 2 == 4 }
41
+ end
42
+
43
+ it "fails" do
44
+ e = rescuing {
45
+ is("math is hard") { 2 + 2 == 5 }
46
+ }
47
+ expected = <<-FAIL
48
+ math is hard: Expected ((2 + 2) == 5), but 4 is not equal to 5
49
+ (2 + 2) is 4
50
+ FAIL
51
+ assert { e.message == expected }
52
+ end
53
+
54
+ it "doesn't keep aliasing the same word" do
55
+ Wrong.config.alias_assert(:is)
56
+ Wrong.config.alias_assert(:is)
57
+ assert { Wrong.config.assert_method_names == [:assert, :is] }
58
+ end
59
+ end
60
+
61
+ describe "adding aliases for deny" do
62
+ before do
63
+ Wrong.config.alias_deny(:aint)
64
+ end
65
+
66
+ it "succeeds" do
67
+ aint { 2 + 2 == 5 }
68
+ end
69
+
70
+ it "fails" do
71
+ e = rescuing {
72
+ aint("math is hard") { 2 + 2 == 4 }
73
+ }
74
+ expected = <<-FAIL
75
+ math is hard: Didn't expect ((2 + 2) == 4), but 4 is equal to 4
76
+ (2 + 2) is 4
77
+ FAIL
78
+ assert { e.message == expected }
79
+ end
80
+
81
+ it "doesn't keep aliasing the same word" do
82
+ Wrong.config.alias_deny(:aint)
83
+ Wrong.config.alias_deny(:aint)
84
+ assert { Wrong.config.deny_method_names == [:deny, :aint] }
85
+ end
86
+
87
+ end
88
+
32
89
  end