assert 2.3.3 → 2.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.md CHANGED
@@ -250,6 +250,90 @@ Assert.configure do |config|
250
250
  end
251
251
  ```
252
252
 
253
+ ### Pretty Printing values in fail messages
254
+
255
+ By default, Assert uses `inspect` when outputting value details in failure messages. At times you may want to pretty-print complex objects as their inspect value is not very human-readable. You can tell Assert to pretty print the assertion objects instead.
256
+
257
+ In user/local settings file:
258
+
259
+ ```ruby
260
+ Assert.configure do |config|
261
+ config.pp_objects true
262
+ end
263
+ ```
264
+
265
+ Using the CLI:
266
+
267
+ ```sh
268
+ $ assert [-p|--pp-objects|--no-pp-objects]
269
+ ```
270
+
271
+ #### Default pretty print processor
272
+
273
+ Assert uses the stdlib's `PP.pp` to pretty print objects by default. This is provided by the `Assert::Utils.stdlib_pp_proc` util.
274
+
275
+ Using the default `inspect` (no pretty print):
276
+
277
+ ```
278
+ $ assert
279
+
280
+ FAIL: a test that fails should fail
281
+ Expected nil, not {:now_usec=>164055, :string=>"a really really really really really really really really long string", :now=>Thu Nov 14 10:28:49 -0600 2013}.
282
+ ```
283
+
284
+ Using the default pretty printing (`Assert::Utils.stdlib_pp_proc`):
285
+
286
+ ```
287
+ $ assert -p
288
+
289
+ FAIL: a test that fails should fail
290
+ Expected nil, not
291
+ {:now_usec=>45127,
292
+ :string=>
293
+ "a really really really really really really really really long string",
294
+ :now=>Thu Nov 14 10:28:35 -0600 2013}
295
+ .
296
+ ```
297
+
298
+ You can customize the width used by `PP.pp` by overriding the default `pp_proc` setting:
299
+
300
+ ```ruby
301
+ # set PP.pp width used to 1
302
+ Assert.configure do |config|
303
+ config.pp_proc Assert::Utils.stdlib_pp_proc(1)
304
+ end
305
+ ```
306
+ ```
307
+ $ assert -p
308
+
309
+ FAIL: a test that fails should fail
310
+ Expected nil, not
311
+ {:now_usec=>
312
+ 984698,
313
+ :string=>
314
+ "a really really really really really really really really long string",
315
+ :now=>
316
+ Thu Nov 14 10:30:52 -0600 2013}
317
+ .
318
+ ```
319
+
320
+ You can provide you own custom pretty-print processor if you like:
321
+
322
+ ```ruby
323
+ # set not a very useful pretty print processor
324
+ Assert.configure do |config|
325
+ config.pp_proc Proc.new{ |obj| "herp derp" }
326
+ end
327
+ ```
328
+ ```
329
+ $ assert -p
330
+
331
+ FAIL: a test that fails should fail
332
+ Expected nil, not herp derp.
333
+ ```
334
+
335
+ Use this if you prefer a 3rd-party tool (like awesome_print or something) over the stdlib `PP.pp` for pretty printing.
336
+
253
337
  ## Viewing Test Results
254
338
 
255
339
  `Assert::View::DefaultView` is the default handler for viewing test results. Its output goes something like this:
@@ -1,6 +1,7 @@
1
1
  require 'singleton'
2
2
  require 'assert/version'
3
3
 
4
+ require 'assert/utils'
4
5
  require 'assert/view'
5
6
  require 'assert/suite'
6
7
  require 'assert/runner'
@@ -33,8 +34,8 @@ module Assert
33
34
  end
34
35
 
35
36
  settings :view, :suite, :runner, :test_dir, :test_helper, :changed_files
36
- settings :runner_seed, :capture_output, :halt_on_fail, :changed_only
37
- settings :debug
37
+ settings :runner_seed, :pp_proc, :use_diff_proc, :run_diff_proc
38
+ settings :capture_output, :halt_on_fail, :changed_only, :pp_objects, :debug
38
39
 
39
40
  def initialize
40
41
  @view = Assert::View::DefaultView.new($stdout)
@@ -45,10 +46,16 @@ module Assert
45
46
  @changed_files = Assert::AssertRunner::DEFAULT_CHANGED_FILES_PROC
46
47
 
47
48
  # default option values
48
- @runner_seed = begin; srand; srand % 0xFFFF; end.to_i
49
+ @runner_seed = begin; srand; srand % 0xFFFF; end.to_i
50
+ @pp_proc = Assert::U.stdlib_pp_proc
51
+ @use_diff_proc = Assert::U.default_use_diff_proc
52
+ @run_diff_proc = Assert::U.syscmd_diff_proc
53
+
54
+ # mode flags
49
55
  @capture_output = false
50
56
  @halt_on_fail = true
51
57
  @changed_only = false
58
+ @pp_objects = false
52
59
  @debug = false
53
60
  end
54
61
 
@@ -1,4 +1,7 @@
1
+ require 'assert/utils'
2
+
1
3
  module Assert
4
+
2
5
  module Assertions
3
6
 
4
7
  def assert_block(desc = nil)
@@ -12,53 +15,69 @@ module Assert
12
15
 
13
16
  def assert_empty(collection, desc = nil)
14
17
  assert(collection.empty?, desc) do
15
- "Expected #{collection.inspect} to be empty."
18
+ "Expected #{Assert::U.show(collection)} to be empty."
16
19
  end
17
20
  end
18
21
 
19
22
  def assert_not_empty(collection, desc = nil)
20
23
  assert(!collection.empty?, desc) do
21
- "Expected #{collection.inspect} to not be empty."
24
+ "Expected #{Assert::U.show(collection)} to not be empty."
22
25
  end
23
26
  end
24
27
  alias_method :refute_empty, :assert_not_empty
25
28
 
26
- def assert_equal(expected, actual, desc = nil)
27
- assert(actual == expected, desc) do
28
- "Expected #{expected.inspect}, not #{actual.inspect}."
29
+ def assert_equal(exp, act, desc = nil)
30
+ assert(act == exp, desc) do
31
+ exp_show = Assert::U.show_for_diff(exp)
32
+ act_show = Assert::U.show_for_diff(act)
33
+
34
+ if Assert.config.use_diff_proc.call(exp_show, act_show)
35
+ "Expected does not equal actual, diff:\n"\
36
+ "#{Assert.config.run_diff_proc.call(exp_show, act_show)}"
37
+ else
38
+ "Expected #{Assert::U.show(exp)}, not #{Assert::U.show(act)}."
39
+ end
29
40
  end
30
41
  end
31
42
 
32
- def assert_not_equal(expected, actual, desc = nil)
33
- assert(actual != expected, desc) do
34
- "#{actual.inspect} not expected to equal #{expected.inspect}."
43
+ def assert_not_equal(exp, act, desc = nil)
44
+ assert(act != exp, desc) do
45
+ exp_show = Assert::U.show_for_diff(exp)
46
+ act_show = Assert::U.show_for_diff(act)
47
+
48
+ if Assert.config.use_diff_proc.call(exp_show, act_show)
49
+ "Expected equals actual, diff:\n"\
50
+ "#{Assert.config.run_diff_proc.call(exp_show, act_show)}"
51
+ else
52
+ "#{Assert::U.show(act)} not expected to equal #{Assert::U.show(exp)}."
53
+ end
35
54
  end
36
55
  end
37
56
  alias_method :refute_equal, :assert_not_equal
38
57
 
39
58
  def assert_file_exists(file_path, desc = nil)
40
59
  assert(File.exists?(File.expand_path(file_path)), desc) do
41
- "Expected #{file_path.inspect} to exist."
60
+ "Expected #{Assert::U.show(file_path)} to exist."
42
61
  end
43
62
  end
44
63
 
45
64
  def assert_not_file_exists(file_path, desc = nil)
46
65
  assert(!File.exists?(File.expand_path(file_path)), desc) do
47
- "Expected #{file_path.inspect} to not exist."
66
+ "Expected #{Assert::U.show(file_path)} to not exist."
48
67
  end
49
68
  end
50
69
  alias_method :refute_file_exists, :assert_not_file_exists
51
70
 
52
71
  def assert_includes(object, collection, desc = nil)
53
72
  assert(collection.include?(object), desc) do
54
- "Expected #{collection.inspect} to include #{object.inspect}."
73
+ "Expected #{Assert::U.show(collection)} to include #{Assert::U.show(object)}."
55
74
  end
56
75
  end
57
76
  alias_method :assert_included, :assert_includes
58
77
 
59
78
  def assert_not_includes(object, collection, desc = nil)
60
79
  assert(!collection.include?(object), desc) do
61
- "Expected #{collection.inspect} to not include #{object.inspect}."
80
+ "Expected #{Assert::U.show(collection)} to not include #{Assert::U.show(object)}."
62
81
  end
63
82
  end
64
83
  alias_method :assert_not_included, :assert_not_includes
@@ -67,52 +86,52 @@ module Assert
67
86
 
68
87
  def assert_instance_of(klass, instance, desc = nil)
69
88
  assert(instance.instance_of?(klass), desc) do
70
- "Expected #{instance.inspect} (#{instance.class}) to be an instance of #{klass}."
89
+ "Expected #{Assert::U.show(instance)} (#{instance.class}) to be an instance of #{klass}."
71
90
  end
72
91
  end
73
92
 
74
93
  def assert_not_instance_of(klass, instance, desc = nil)
75
94
  assert(!instance.instance_of?(klass), desc) do
76
- "#{instance.inspect} (#{instance.class}) not expected to be an instance of #{klass}."
95
+ "#{Assert::U.show(instance)} (#{instance.class}) not expected to be an instance of #{klass}."
77
96
  end
78
97
  end
79
98
  alias_method :refute_instance_of, :assert_not_instance_of
80
99
 
81
100
  def assert_kind_of(klass, instance, desc=nil)
82
101
  assert(instance.kind_of?(klass), desc) do
83
- "Expected #{instance.inspect} (#{instance.class}) to be a kind of #{klass}."
102
+ "Expected #{Assert::U.show(instance)} (#{instance.class}) to be a kind of #{klass}."
84
103
  end
85
104
  end
86
105
 
87
106
  def assert_not_kind_of(klass, instance, desc=nil)
88
107
  assert(!instance.kind_of?(klass), desc) do
89
- "#{instance.inspect} not expected to be a kind of #{klass}."
108
+ "#{Assert::U.show(instance)} not expected to be a kind of #{klass}."
90
109
  end
91
110
  end
92
111
  alias_method :refute_kind_of, :assert_not_kind_of
93
112
 
94
- def assert_match(expected, actual, desc=nil)
95
- exp = String === expected && String === actual ? /#{Regexp.escape(expected)}/ : expected
96
- assert(actual =~ exp, desc) do
97
- "Expected #{actual.inspect} to match #{expected.inspect}."
113
+ def assert_match(exp, act, desc=nil)
114
+ exp_regex = String === exp && String === act ? /#{Regexp.escape(exp)}/ : exp
115
+ assert(act =~ exp_regex, desc) do
116
+ "Expected #{Assert::U.show(act)} to match #{Assert::U.show(exp)}."
98
117
  end
99
118
  end
100
119
 
101
- def assert_not_match(expected, actual, desc=nil)
102
- exp = String === expected && String === actual ? /#{Regexp.escape(expected)}/ : expected
103
- assert(actual !~ exp, desc) do
104
- "#{actual.inspect} not expected to match #{expected.inspect}."
120
+ def assert_not_match(exp, act, desc=nil)
121
+ exp = String === exp && String === act ? /#{Regexp.escape(exp)}/ : exp
122
+ assert(act !~ exp, desc) do
123
+ "#{Assert::U.show(act)} not expected to match #{Assert::U.show(exp)}."
105
124
  end
106
125
  end
107
126
  alias_method :refute_match, :assert_not_match
108
127
  alias_method :assert_no_match, :assert_not_match
109
128
 
110
129
  def assert_nil(object, desc=nil)
111
- assert(object.nil?, desc){ "Expected nil, not #{object.inspect}." }
130
+ assert(object.nil?, desc){ "Expected nil, not #{Assert::U.show(object)}." }
112
131
  end
113
132
 
114
133
  def assert_not_nil(object, desc=nil)
115
- assert(!object.nil?, desc){ "Expected #{object.inspect} to not be nil." }
134
+ assert(!object.nil?, desc){ "Expected #{Assert::U.show(object)} to not be nil." }
116
135
  end
117
136
  alias_method :refute_nil, :assert_not_nil
118
137
 
@@ -133,29 +152,31 @@ module Assert
133
152
 
134
153
  def assert_respond_to(method, object, desc=nil)
135
154
  assert(object.respond_to?(method), desc) do
136
- "Expected #{object.inspect} (#{object.class}) to respond to `#{method}`."
155
+ "Expected #{Assert::U.show(object)} (#{object.class}) to respond to `#{method}`."
137
156
  end
138
157
  end
139
158
  alias_method :assert_responds_to, :assert_respond_to
140
159
 
141
160
  def assert_not_respond_to(method, object, desc=nil)
142
161
  assert(!object.respond_to?(method), desc) do
143
- "#{object.inspect} (#{object.class}) not expected to respond to `#{method}`."
162
+ "#{Assert::U.show(object)} (#{object.class}) not expected to respond to `#{method}`."
144
163
  end
145
164
  end
146
165
  alias_method :assert_not_responds_to, :assert_not_respond_to
147
166
  alias_method :refute_respond_to, :assert_not_respond_to
148
167
  alias_method :refute_responds_to, :assert_not_respond_to
149
168
 
150
- def assert_same(expected, actual, desc=nil)
151
- assert(actual.equal?(expected), desc) do
152
- "Expected #{actual} (#{actual.object_id}) to be the same as #{expected} (#{expected.object_id})."
169
+ def assert_same(exp, act, desc=nil)
170
+ assert(act.equal?(exp), desc) do
171
+ "Expected #{Assert::U.show(act)} (#{act.object_id})"\
172
+ " to be the same as #{Assert::U.show(exp)} (#{exp.object_id})."
153
173
  end
154
174
  end
155
175
 
156
- def assert_not_same(expected, actual, desc=nil)
157
- assert(!actual.equal?(expected), desc) do
158
- "#{actual} (#{actual.object_id}) not expected to be the same as #{expected} (#{expected.object_id})."
176
+ def assert_not_same(exp, act, desc=nil)
177
+ assert(!act.equal?(exp), desc) do
178
+ "#{Assert::U.show(act)} (#{act.object_id})"\
179
+ " not expected to be the same as #{Assert::U.show(exp)} (#{exp.object_id})."
159
180
  end
160
181
  end
161
182
  alias_method :refute_same, :assert_not_same
@@ -213,8 +234,8 @@ module Assert
213
234
  if @exception
214
235
  backtrace = Assert::Result::Backtrace.new(@exception.backtrace)
215
236
  [ raised_msg,
216
- "Class: <#{@exception.class}>",
217
- "Message: <#{@exception.message.inspect}>",
237
+ "Class: `#{@exception.class}`",
238
+ "Message: `#{@exception.message.inspect}`",
218
239
  "---Backtrace---",
219
240
  backtrace.filtered.to_s,
220
241
  "---------------"
@@ -238,4 +259,5 @@ module Assert
238
259
  end
239
260
 
240
261
  end
262
+
241
263
  end
@@ -25,6 +25,7 @@ module Assert
25
25
  end
26
26
 
27
27
  def initialize(*args)
28
+ @args = args
28
29
  @cli = CLIRB.new do
29
30
  option 'runner_seed', 'Use a given seed to run tests', {
30
31
  :abbrev => 's', :value => Fixnum
@@ -38,14 +39,17 @@ module Assert
38
39
  option 'changed_only', 'only run test files with changes', {
39
40
  :abbrev => 'c'
40
41
  }
42
+ option 'pp_objects', 'pretty-print objects in fail messages', {
43
+ :abbrev => 'p'
44
+ }
41
45
  # show loaded test files, cli err backtraces, etc
42
46
  option 'debug', 'run in debug mode'
43
47
  end
44
- @cli.parse!(args)
45
48
  end
46
49
 
47
50
  def run
48
51
  begin
52
+ @cli.parse!(@args)
49
53
  Assert::AssertRunner.new(@cli.args, @cli.opts).run
50
54
  rescue CLIRB::HelpExit
51
55
  puts help
@@ -1,3 +1,4 @@
1
+ require 'assert/utils'
1
2
  require 'assert/suite'
2
3
  require 'assert/assertions'
3
4
  require 'assert/result'
@@ -174,19 +175,19 @@ module Assert
174
175
  # check if the assertion is a truthy value, if so create a new pass result, otherwise
175
176
  # create a new fail result with the desc and what failed msg.
176
177
  # all other assertion helpers use this one in the end
177
- def assert(assertion, fail_desc = nil)
178
+ def assert(assertion, desc = nil)
178
179
  if assertion
179
180
  pass
180
181
  else
181
- what_failed_msg = block_given? ? yield : "Failed assert: assertion was <#{assertion.inspect}>."
182
- fail(fail_message(fail_desc, what_failed_msg))
182
+ what = block_given? ? yield : "Failed assert: assertion was `#{Assert::U.show(assertion)}`."
183
+ fail(fail_message(desc, what))
183
184
  end
184
185
  end
185
186
 
186
187
  # the opposite of assert, check if the assertion is a false value, if so create a new pass
187
188
  # result, otherwise create a new fail result with the desc and it's what failed msg
188
189
  def assert_not(assertion, fail_desc = nil)
189
- assert(!assertion, fail_desc){ "Failed assert_not: assertion was <#{assertion.inspect}>." }
190
+ assert(!assertion, fail_desc){ "Failed assert_not: assertion was `#{Assert::U.show(assertion)}`." }
190
191
  end
191
192
  alias_method :refute, :assert_not
192
193
 
@@ -63,7 +63,7 @@ module Assert::Result
63
63
  end
64
64
 
65
65
  def inspect
66
- "#<#{self.class} @message=#{self.message.inspect}>"
66
+ "#<#{self.class}:#{'0x0%x' % (object_id << 1)} @message=#{self.message.inspect}>"
67
67
  end
68
68
 
69
69
  end
@@ -78,7 +78,7 @@ module Assert
78
78
  attributes_string = ([ :name, :context_info, :results ].collect do |attr|
79
79
  "@#{attr}=#{self.send(attr).inspect}"
80
80
  end).join(" ")
81
- "#<#{self.class} #{attributes_string}>"
81
+ "#<#{self.class}:#{'0x0%x' % (object_id << 1)} #{attributes_string}>"
82
82
  end
83
83
 
84
84
  protected
@@ -0,0 +1,70 @@
1
+ require 'assert'
2
+
3
+ module Assert
4
+
5
+ module Utils
6
+
7
+ # show objects in a human-readable manner. Either inspects or pretty-prints
8
+ # them depending on settings.
9
+
10
+ def self.show(obj)
11
+ out = Assert.config.pp_objects ? Assert.config.pp_proc.call(obj) : obj.inspect
12
+ out = out.encode(Encoding.default_external) if defined?(Encoding)
13
+ out
14
+ end
15
+
16
+ # show objects in a human-readable manner and make the output diff-able. This
17
+ # expands on the basic `show` util by escaping newlines and making object id
18
+ # hex-values generic.
19
+
20
+ def self.show_for_diff(obj)
21
+ show(obj).gsub(/\\n/, "\n").gsub(/:0x[a-fA-F0-9]{4,}/m, ':0xXXXXXX')
22
+ end
23
+
24
+ # open a tempfile and yield it
25
+
26
+ def self.tempfile(name, content)
27
+ require "tempfile"
28
+ Tempfile.open(name) do |tmpfile|
29
+ tmpfile.puts(content); tmpfile.flush
30
+ yield tmpfile if block_given?
31
+ end
32
+ end
33
+
34
+ # Get a proc that uses stdlib `PP.pp` to pretty print objects
35
+
36
+ def self.stdlib_pp_proc(width = nil)
37
+ require 'pp'
38
+ Proc.new{ |obj| "\n#{PP.pp(obj, '', width || 79).strip}\n" }
39
+ end
40
+
41
+ # Return true if if either show output has newlines or is bigger than 29 chars
42
+
43
+ def self.default_use_diff_proc
44
+ Proc.new do |exp_show_output, act_show_output|
45
+ exp_show_output.include?("\n") || exp_show_output.size > 29 ||
46
+ act_show_output.include?("\n") || act_show_output.size > 29
47
+ end
48
+ end
49
+
50
+ def self.syscmd_diff_proc(syscmd = "diff --unified=-1")
51
+ Proc.new do |exp_show_output, act_show_output|
52
+ result = ""
53
+ tempfile('exp_show_output', exp_show_output) do |a|
54
+ tempfile('act_show_output', act_show_output) do |b|
55
+ result = `#{syscmd} #{a.path} #{b.path}`
56
+ result.sub!(/^\-\-\- .+/, "--- expected")
57
+ result.sub!(/^\+\+\+ .+/, "+++ actual")
58
+ result = "--- expected\n+++ actual" if result.empty?
59
+ end
60
+ end
61
+ result
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+ # alias for brevity
68
+ U = Utils
69
+
70
+ end
@@ -1,3 +1,3 @@
1
1
  module Assert
2
- VERSION = "2.3.3"
2
+ VERSION = "2.4.0"
3
3
  end
@@ -2,7 +2,8 @@
2
2
  # put any test helpers here
3
3
 
4
4
  # add the root dir to the load path
5
- $LOAD_PATH.unshift(File.expand_path("../..", __FILE__))
5
+ ROOT_PATH = File.expand_path("../..", __FILE__)
6
+ $LOAD_PATH.unshift(ROOT_PATH)
6
7
 
7
8
  # require pry for debugging (`binding.pry`)
8
9
  require 'pry'
@@ -0,0 +1,3 @@
1
+ This is a file
2
+ that is being
3
+ diff'd.
@@ -0,0 +1,3 @@
1
+ This is a file
2
+ that will be
3
+ diff'd.
@@ -1,7 +1,9 @@
1
1
  require 'assert'
2
+
2
3
  require 'assert/view/default_view'
3
4
  require 'assert/runner'
4
5
  require 'assert/suite'
6
+ require 'assert/utils'
5
7
 
6
8
  module Assert
7
9
 
@@ -31,7 +33,8 @@ module Assert
31
33
  subject { Config }
32
34
 
33
35
  should have_imeths :suite, :view, :runner, :test_dir, :test_helper, :changed_files
34
- should have_imeths :runner_seed, :capture_output, :halt_on_fail, :changed_only
36
+ should have_imeths :runner_seed, :pp_proc, :use_diff_proc, :run_diff_proc
37
+ should have_imeths :capture_output, :halt_on_fail, :changed_only, :pp_objects
35
38
  should have_imeths :debug, :apply
36
39
 
37
40
  should "default the view, suite, and runner" do
@@ -40,6 +43,13 @@ module Assert
40
43
  assert_kind_of Assert::Runner, subject.runner
41
44
  end
42
45
 
46
+ should "default the optional values" do
47
+ assert_not_nil subject.runner_seed
48
+ assert_not_nil subject.pp_proc
49
+ assert_not_nil subject.use_diff_proc
50
+ assert_not_nil subject.run_diff_proc
51
+ end
52
+
43
53
  end
44
54
 
45
55
  end
@@ -1,6 +1,8 @@
1
1
  require 'assert'
2
2
  require 'assert/assertions'
3
3
 
4
+ require 'assert/utils'
5
+
4
6
  module Assert::Assertions
5
7
 
6
8
  class AssertEmptyTests < Assert::Context
@@ -23,7 +25,7 @@ module Assert::Assertions
23
25
  end
24
26
 
25
27
  should "have a fail message with custom and generic explanations" do
26
- exp = "#{@args[1]}\nExpected #{@args[0].inspect} to be empty."
28
+ exp = "#{@args[1]}\nExpected #{Assert::U.show(@args[0])} to be empty."
27
29
  assert_equal exp, subject.fail_results.first.message
28
30
  end
29
31
 
@@ -49,7 +51,7 @@ module Assert::Assertions
49
51
  end
50
52
 
51
53
  should "have a fail message with custom and generic explanations" do
52
- exp = "#{@args[1]}\nExpected #{@args[0].inspect} to not be empty."
54
+ exp = "#{@args[1]}\nExpected #{Assert::U.show(@args[0])} to not be empty."
53
55
  assert_equal exp, subject.fail_results.first.message
54
56
  end
55
57
 
@@ -1,10 +1,12 @@
1
1
  require 'assert'
2
2
  require 'assert/assertions'
3
3
 
4
+ require 'assert/utils'
5
+
4
6
  module Assert::Assertions
5
7
 
6
8
  class AssertEqualTests < Assert::Context
7
- desc "the assert_equal helper"
9
+ desc "`assert_equal`"
8
10
  setup do
9
11
  desc = @desc = "assert equal fail desc"
10
12
  args = @args = [ '1', '2', desc ]
@@ -23,14 +25,14 @@ module Assert::Assertions
23
25
  end
24
26
 
25
27
  should "have a fail message with custom and generic explanations" do
26
- exp = "#{@args[2]}\nExpected #{@args[0].inspect}, not #{@args[1].inspect}."
28
+ exp = "#{@args[2]}\nExpected #{Assert::U.show(@args[0])}, not #{Assert::U.show(@args[1])}."
27
29
  assert_equal exp, subject.fail_results.first.message
28
30
  end
29
31
 
30
32
  end
31
33
 
32
34
  class AssertNotEqualTests < Assert::Context
33
- desc "the assert_not_equal helper"
35
+ desc "`assert_not_equal`"
34
36
  setup do
35
37
  desc = @desc = "assert not equal fail desc"
36
38
  args = @args = [ '1', '1', desc ]
@@ -50,7 +52,67 @@ module Assert::Assertions
50
52
 
51
53
  should "have a fail message with custom and generic explanations" do
52
54
  exp = "#{@args[2]}\n"\
53
- "#{@args[1].inspect} not expected to equal #{@args[0].inspect}."
55
+ "#{Assert::U.show(@args[1])} not expected to equal #{Assert::U.show(@args[0])}."
56
+ assert_equal exp, subject.fail_results.first.message
57
+ end
58
+
59
+ end
60
+
61
+ class DiffTests < Assert::Context
62
+ desc "with objects that should use diff when showing"
63
+ setup do
64
+ @exp_obj = "I'm a\nstring"
65
+ @act_obj = "I am a \nstring"
66
+
67
+ @exp_obj_show = Assert::U.show_for_diff(@exp_obj)
68
+ @act_obj_show = Assert::U.show_for_diff(@act_obj)
69
+
70
+ @orig_use_diff_proc = Assert.config.use_diff_proc
71
+ @orig_run_diff_proc = Assert.config.run_diff_proc
72
+
73
+ Assert.config.use_diff_proc(Assert::U.default_use_diff_proc)
74
+ Assert.config.run_diff_proc(Assert::U.syscmd_diff_proc)
75
+ end
76
+ teardown do
77
+ Assert.config.use_diff_proc(@orig_use_diff_proc)
78
+ Assert.config.run_diff_proc(@orig_run_diff_proc)
79
+ end
80
+
81
+ end
82
+
83
+ class AssertEqualDiffTests < DiffTests
84
+ desc "`assert_equal`"
85
+ setup do
86
+ exp_obj, act_obj = @exp_obj, @act_obj
87
+ @test = Factory.test do
88
+ assert_equal(exp_obj, act_obj)
89
+ end
90
+ @test.run
91
+ end
92
+ subject{ @test }
93
+
94
+ should "include diff output in the fail messages" do
95
+ exp = "Expected does not equal actual, diff:\n"\
96
+ "#{Assert::U.syscmd_diff_proc.call(@exp_obj_show, @act_obj_show)}"
97
+ assert_equal exp, subject.fail_results.first.message
98
+ end
99
+
100
+ end
101
+
102
+ class AssertNotEqualDiffTests < DiffTests
103
+ desc "`assert_not_equal`"
104
+ setup do
105
+ exp_obj, act_obj = @exp_obj, @act_obj
106
+ @test = Factory.test do
107
+ assert_not_equal(exp_obj, exp_obj)
108
+ end
109
+ @test.run
110
+ end
111
+ subject{ @test }
112
+
113
+ should "include diff output in the fail messages" do
114
+ exp = "Expected equals actual, diff:\n"\
115
+ "#{Assert::U.syscmd_diff_proc.call(@exp_obj_show, @exp_obj_show)}"
54
116
  assert_equal exp, subject.fail_results.first.message
55
117
  end
56
118
 
@@ -1,6 +1,8 @@
1
1
  require 'assert'
2
2
  require 'assert/assertions'
3
3
 
4
+ require 'assert/utils'
5
+
4
6
  module Assert::Assertions
5
7
 
6
8
  class AssertFileExistsTests < Assert::Context
@@ -23,7 +25,7 @@ module Assert::Assertions
23
25
  end
24
26
 
25
27
  should "have a fail message with custom and generic explanations" do
26
- exp = "#{@args[1]}\nExpected #{@args[0].inspect} to exist."
28
+ exp = "#{@args[1]}\nExpected #{Assert::U.show(@args[0])} to exist."
27
29
  assert_equal exp, subject.fail_results.first.message
28
30
  end
29
31
 
@@ -49,7 +51,7 @@ module Assert::Assertions
49
51
  end
50
52
 
51
53
  should "have a fail message with custom and generic explanations" do
52
- exp = "#{@args[1]}\nExpected #{@args[0].inspect} to not exist."
54
+ exp = "#{@args[1]}\nExpected #{Assert::U.show(@args[0])} to not exist."
53
55
  assert_equal exp, subject.fail_results.first.message
54
56
  end
55
57
 
@@ -1,6 +1,8 @@
1
1
  require 'assert'
2
2
  require 'assert/assertions'
3
3
 
4
+ require 'assert/utils'
5
+
4
6
  module Assert::Assertions
5
7
 
6
8
  class AssertIncludesTests < Assert::Context
@@ -24,7 +26,7 @@ module Assert::Assertions
24
26
 
25
27
  should "have a fail message with custom and generic explanations" do
26
28
  exp = "#{@args[2]}\n"\
27
- "Expected #{@args[1].inspect} to include #{@args[0].inspect}."
29
+ "Expected #{Assert::U.show(@args[1])} to include #{Assert::U.show(@args[0])}."
28
30
  assert_equal exp, subject.fail_results.first.message
29
31
  end
30
32
 
@@ -51,7 +53,7 @@ module Assert::Assertions
51
53
 
52
54
  should "have a fail message with custom and generic explanations" do
53
55
  exp = "#{@args[2]}\n"\
54
- "Expected #{@args[1].inspect} to not include #{@args[0].inspect}."
56
+ "Expected #{Assert::U.show(@args[1])} to not include #{Assert::U.show(@args[0])}."
55
57
  assert_equal exp, subject.fail_results.first.message
56
58
  end
57
59
 
@@ -1,6 +1,8 @@
1
1
  require 'assert'
2
2
  require 'assert/assertions'
3
3
 
4
+ require 'assert/utils'
5
+
4
6
  module Assert::Assertions
5
7
 
6
8
  class AssertInstanceOfTests < Assert::Context
@@ -23,7 +25,7 @@ module Assert::Assertions
23
25
  end
24
26
 
25
27
  should "have a fail message with custom and generic explanations" do
26
- exp = "#{@args[2]}\nExpected #{@args[1].inspect} (#{@args[1].class}) to"\
28
+ exp = "#{@args[2]}\nExpected #{Assert::U.show(@args[1])} (#{@args[1].class}) to"\
27
29
  " be an instance of #{@args[0]}."
28
30
  assert_equal exp, subject.fail_results.first.message
29
31
  end
@@ -50,7 +52,7 @@ module Assert::Assertions
50
52
  end
51
53
 
52
54
  should "have a fail message with custom and generic explanations" do
53
- exp = "#{@args[2]}\n#{@args[1].inspect} (#{@args[1].class}) not expected to"\
55
+ exp = "#{@args[2]}\n#{Assert::U.show(@args[1])} (#{@args[1].class}) not expected to"\
54
56
  " be an instance of #{@args[0]}."
55
57
  assert_equal exp, subject.fail_results.first.message
56
58
  end
@@ -1,6 +1,8 @@
1
1
  require 'assert'
2
2
  require 'assert/assertions'
3
3
 
4
+ require 'assert/utils'
5
+
4
6
  module Assert::Assertions
5
7
 
6
8
  class AssertKindOfTests < Assert::Context
@@ -23,7 +25,7 @@ module Assert::Assertions
23
25
  end
24
26
 
25
27
  should "have a fail message with custom and generic explanations" do
26
- exp = "#{@args[2]}\nExpected #{@args[1].inspect} (#{@args[1].class}) to"\
28
+ exp = "#{@args[2]}\nExpected #{Assert::U.show(@args[1])} (#{@args[1].class}) to"\
27
29
  " be a kind of #{@args[0]}."
28
30
  assert_equal exp, subject.fail_results.first.message
29
31
  end
@@ -50,7 +52,7 @@ module Assert::Assertions
50
52
  end
51
53
 
52
54
  should "have a fail message with custom and generic explanations" do
53
- exp = "#{@args[2]}\n#{@args[1].inspect} not expected to be a kind of #{@args[0]}."
55
+ exp = "#{@args[2]}\n#{Assert::U.show(@args[1])} not expected to be a kind of #{@args[0]}."
54
56
  assert_equal exp, subject.fail_results.first.message
55
57
  end
56
58
 
@@ -1,6 +1,8 @@
1
1
  require 'assert'
2
2
  require 'assert/assertions'
3
3
 
4
+ require 'assert/utils'
5
+
4
6
  module Assert::Assertions
5
7
 
6
8
  class AssertMatchTests < Assert::Context
@@ -23,7 +25,7 @@ module Assert::Assertions
23
25
  end
24
26
 
25
27
  should "have a fail message with custom and generic explanations" do
26
- exp = "#{@args[2]}\nExpected #{@args[1].inspect} to match #{@args[0].inspect}."
28
+ exp = "#{@args[2]}\nExpected #{Assert::U.show(@args[1])} to match #{Assert::U.show(@args[0])}."
27
29
  assert_equal exp, subject.fail_results.first.message
28
30
  end
29
31
 
@@ -49,7 +51,7 @@ module Assert::Assertions
49
51
  end
50
52
 
51
53
  should "have a fail message with custom and generic explanations" do
52
- exp = "#{@args[2]}\n#{@args[1].inspect} not expected to match #{@args[0].inspect}."
54
+ exp = "#{@args[2]}\n#{Assert::U.show(@args[1])} not expected to match #{Assert::U.show(@args[0])}."
53
55
  assert_equal exp, subject.fail_results.first.message
54
56
  end
55
57
 
@@ -1,6 +1,8 @@
1
1
  require 'assert'
2
2
  require 'assert/assertions'
3
3
 
4
+ require 'assert/utils'
5
+
4
6
  module Assert::Assertions
5
7
 
6
8
  class AssertNilTests < Assert::Context
@@ -23,7 +25,7 @@ module Assert::Assertions
23
25
  end
24
26
 
25
27
  should "have a fail message with custom and generic explanations" do
26
- exp = "#{@args[1]}\nExpected nil, not #{@args[0].inspect}."
28
+ exp = "#{@args[1]}\nExpected nil, not #{Assert::U.show(@args[0])}."
27
29
  assert_equal exp, subject.fail_results.first.message
28
30
  end
29
31
 
@@ -49,7 +51,7 @@ module Assert::Assertions
49
51
  end
50
52
 
51
53
  should "have a fail message with custom and generic explanations" do
52
- exp = "#{@args[1]}\nExpected #{@args[0].inspect} to not be nil."
54
+ exp = "#{@args[1]}\nExpected #{Assert::U.show(@args[0])} to not be nil."
53
55
  assert_equal exp, subject.fail_results.first.message
54
56
  end
55
57
 
@@ -1,6 +1,8 @@
1
1
  require 'assert'
2
2
  require 'assert/assertions'
3
3
 
4
+ require 'assert/utils'
5
+
4
6
  module Assert::Assertions
5
7
 
6
8
  class AssertRespondToTest < Assert::Context
@@ -24,7 +26,7 @@ module Assert::Assertions
24
26
 
25
27
  should "have a fail message with custom and generic explanations" do
26
28
  exp = "#{@args[2]}\n"\
27
- "Expected #{@args[1].inspect} (#{@args[1].class})"\
29
+ "Expected #{Assert::U.show(@args[1])} (#{@args[1].class})"\
28
30
  " to respond to `#{@args[0]}`."
29
31
  assert_equal exp, subject.fail_results.first.message
30
32
  end
@@ -52,7 +54,7 @@ module Assert::Assertions
52
54
 
53
55
  should "have a fail message with custom and generic explanations" do
54
56
  exp = "#{@args[2]}\n"\
55
- "#{@args[1].inspect} (#{@args[1].class})"\
57
+ "#{Assert::U.show(@args[1])} (#{@args[1].class})"\
56
58
  " not expected to respond to `#{@args[0]}`."
57
59
  assert_equal exp, subject.fail_results.first.message
58
60
  end
@@ -1,6 +1,8 @@
1
1
  require 'assert'
2
2
  require 'assert/assertions'
3
3
 
4
+ require 'assert/utils'
5
+
4
6
  module Assert::Assertions
5
7
 
6
8
  class AssertSameTest < Assert::Context
@@ -25,8 +27,8 @@ module Assert::Assertions
25
27
 
26
28
  should "have a fail message with custom and generic explanations" do
27
29
  exp = "#{@args[2]}\n"\
28
- "Expected #{@args[1].inspect} (#{@args[1].object_id})"\
29
- " to be the same as #{@args[0].inspect} (#{@args[0].object_id})."
30
+ "Expected #{Assert::U.show(@args[1])} (#{@args[1].object_id})"\
31
+ " to be the same as #{Assert::U.show(@args[0])} (#{@args[0].object_id})."
30
32
  assert_equal exp, subject.fail_results.first.message
31
33
  end
32
34
 
@@ -54,8 +56,8 @@ module Assert::Assertions
54
56
 
55
57
  should "have a fail message with custom and generic explanations" do
56
58
  exp = "#{@args[2]}\n"\
57
- "#{@args[1].inspect} (#{@args[1].object_id}) not expected"\
58
- " to be the same as #{@args[0].inspect} (#{@args[0].object_id})."
59
+ "#{Assert::U.show(@args[1])} (#{@args[1].object_id}) not expected"\
60
+ " to be the same as #{Assert::U.show(@args[0])} (#{@args[0].object_id})."
59
61
  assert_equal exp, subject.fail_results.first.message
60
62
  end
61
63
 
@@ -1,9 +1,11 @@
1
1
  require 'assert'
2
2
  require 'assert/context'
3
3
 
4
+ require 'assert/utils'
5
+
4
6
  class Assert::Context
5
7
 
6
- class BasicTests < Assert::Context
8
+ class UnitTests < Assert::Context
7
9
  desc "Assert context"
8
10
  setup do
9
11
  @test = Factory.test
@@ -27,7 +29,7 @@ class Assert::Context
27
29
 
28
30
  end
29
31
 
30
- class SkipTests < BasicTests
32
+ class SkipTests < UnitTests
31
33
  desc "skip method"
32
34
  setup do
33
35
  @skip_msg = "I need to implement this in the future."
@@ -44,7 +46,7 @@ class Assert::Context
44
46
 
45
47
  end
46
48
 
47
- class IgnoreTests < BasicTests
49
+ class IgnoreTests < UnitTests
48
50
  desc "ignore method"
49
51
  setup do
50
52
  @ignore_msg = "Ignore this for now, will do later."
@@ -59,7 +61,7 @@ class Assert::Context
59
61
 
60
62
  end
61
63
 
62
- class PassTests < BasicTests
64
+ class PassTests < UnitTests
63
65
  desc "pass method"
64
66
  setup do
65
67
  @pass_msg = "That's right, it works."
@@ -74,7 +76,7 @@ class Assert::Context
74
76
 
75
77
  end
76
78
 
77
- class FlunkTests < BasicTests
79
+ class FlunkTests < UnitTests
78
80
  desc "flunk method"
79
81
  setup do
80
82
  @flunk_msg = "It flunked."
@@ -89,7 +91,7 @@ class Assert::Context
89
91
 
90
92
  end
91
93
 
92
- class FailTests < BasicTests
94
+ class FailTests < UnitTests
93
95
  desc "fail method"
94
96
  setup do
95
97
  @result = @context.fail
@@ -137,7 +139,7 @@ class Assert::Context
137
139
 
138
140
  end
139
141
 
140
- class AssertTests < BasicTests
142
+ class AssertTests < UnitTests
141
143
  desc "assert method"
142
144
  setup do
143
145
  @fail_desc = "my fail desc"
@@ -153,6 +155,17 @@ class Assert::Context
153
155
  should "return a fail result given a `false` assertion" do
154
156
  result = subject.assert(false, @fail_desc){ @what_failed }
155
157
  assert_kind_of Assert::Result::Fail, result
158
+ end
159
+
160
+ should "pp the assertion value in the fail message by default" do
161
+ exp_default_what = "Failed assert: assertion was `#{Assert::U.show(false)}`."
162
+ result = subject.assert(false, @fail_desc)
163
+
164
+ assert_equal [@fail_desc, exp_default_what].join("\n"), result.message
165
+ end
166
+
167
+ should "use a custom fail message if one is given" do
168
+ result = subject.assert(false, @fail_desc){ @what_failed }
156
169
  assert_equal [@fail_desc, @what_failed].join("\n"), result.message
157
170
  end
158
171
 
@@ -166,23 +179,28 @@ class Assert::Context
166
179
 
167
180
  end
168
181
 
169
- class AssertNotTests < BasicTests
182
+ class AssertNotTests < UnitTests
170
183
  desc "assert_not method"
171
184
  setup do
172
185
  @fail_desc = "my fail desc"
173
- @what_failed = "Failed assert_not: assertion was <true>."
186
+ end
187
+
188
+ should "return a pass result given a `false` assertion" do
189
+ result = subject.assert_not(false, @fail_desc)
190
+ assert_kind_of Assert::Result::Pass, result
191
+ assert_nil result.message
174
192
  end
175
193
 
176
194
  should "return a fail result given a `true` assertion" do
177
195
  result = subject.assert_not(true, @fail_desc)
178
196
  assert_kind_of Assert::Result::Fail, result
179
- assert_equal [@fail_desc, @what_failed].join("\n"), result.message
180
197
  end
181
198
 
182
- should "return a pass result given a `false` assertion" do
183
- result = subject.assert_not(false, @fail_desc)
184
- assert_kind_of Assert::Result::Pass, result
185
- assert_nil result.message
199
+ should "pp the assertion value in the fail message by default" do
200
+ exp_default_what = "Failed assert_not: assertion was `#{Assert::U.show(true)}`."
201
+ result = subject.assert_not(true, @fail_desc)
202
+
203
+ assert_equal [@fail_desc, exp_default_what].join("\n"), result.message
186
204
  end
187
205
 
188
206
  should "return a fail result given a \"truthy\" assertion" do
@@ -195,7 +213,7 @@ class Assert::Context
195
213
 
196
214
  end
197
215
 
198
- class SubjectTests < BasicTests
216
+ class SubjectTests < UnitTests
199
217
  desc "subject method"
200
218
  setup do
201
219
  expected = @expected = "amazing"
@@ -213,7 +231,7 @@ class Assert::Context
213
231
 
214
232
  end
215
233
 
216
- class WithBacktraceTests < BasicTests
234
+ class WithBacktraceTests < UnitTests
217
235
  desc "with_backtrace method"
218
236
  setup do
219
237
  @from_bt = ['called_from_here']
@@ -240,7 +258,7 @@ class Assert::Context
240
258
 
241
259
  end
242
260
 
243
- class InspectTests < BasicTests
261
+ class InspectTests < UnitTests
244
262
  desc "inspect method"
245
263
  setup do
246
264
  @expected = "#<#{@context.class}>"
@@ -61,7 +61,8 @@ module Assert::Result
61
61
  end
62
62
 
63
63
  should "show only its class and message when inspected" do
64
- exp = "#<#{subject.class} @message=#{subject.message.inspect}>"
64
+ exp = "#<#{subject.class}:#{'0x0%x' % (subject.object_id << 1)}"\
65
+ " @message=#{subject.message.inspect}>"
65
66
  assert_equal exp, subject.inspect
66
67
  end
67
68
 
@@ -39,7 +39,7 @@ class Assert::Test
39
39
  attrs_string = [:name, :context_info, :results].collect do |method|
40
40
  "@#{method}=#{subject.send(method).inspect}"
41
41
  end.join(" ")
42
- expected = "#<#{subject.class} #{attrs_string}>"
42
+ expected = "#<#{subject.class}:#{'0x0%x' % (subject.object_id << 1)} #{attrs_string}>"
43
43
  assert_equal expected, subject.inspect
44
44
  end
45
45
 
@@ -0,0 +1,154 @@
1
+ require 'assert'
2
+ require 'assert/utils'
3
+
4
+ require 'tempfile'
5
+
6
+ module Assert::Utils
7
+
8
+ class UnitTests < Assert::Context
9
+ desc "Assert::Utils"
10
+ subject{ Assert::Utils }
11
+ setup do
12
+ @objs = [ 1, 'hi there', Hash.new, [:a, :b]]
13
+ end
14
+
15
+ should have_imeths :show, :show_for_diff
16
+ should have_imeths :tempfile
17
+ should have_imeths :stdlib_pp_proc, :default_use_diff_proc, :syscmd_diff_proc
18
+
19
+ end
20
+
21
+ class ShowTests < UnitTests
22
+ desc "`show`"
23
+ setup do
24
+ @orig_pp_objs = Assert.config.pp_objects
25
+ @orig_pp_proc = Assert.config.pp_proc
26
+ @new_pp_proc = Proc.new{ |input| 'herp derp' }
27
+ end
28
+ teardown do
29
+ Assert.config.pp_proc(@orig_pp_proc)
30
+ Assert.config.pp_objects(@orig_pp_objs)
31
+ end
32
+
33
+ should "use `inspect` to show objs when `pp_objects` setting is false" do
34
+ Assert.config.pp_objects(false)
35
+
36
+ @objs.each do |obj|
37
+ assert_equal obj.inspect, subject.show(obj)
38
+ end
39
+ end
40
+
41
+ should "use `pp_proc` to show objs when `pp_objects` setting is true" do
42
+ Assert.config.pp_objects(true)
43
+ Assert.config.pp_proc(@new_pp_proc)
44
+
45
+ @objs.each do |obj|
46
+ assert_equal @new_pp_proc.call(obj), subject.show(obj)
47
+ end
48
+ end
49
+
50
+ end
51
+
52
+ class ShowForDiffTests < UnitTests
53
+ desc "`show_for_diff`"
54
+ setup do
55
+ @w_newlines = { :string => "herp derp, derp herp\nherpderpedia" }
56
+ @w_obj_id = Struct.new(:a, :b).new('aye', 'bee')
57
+ end
58
+
59
+ should "call show, escaping newlines" do
60
+ exp_out = "{:string=>\"herp derp, derp herp\nherpderpedia\"}"
61
+ assert_equal exp_out, subject.show_for_diff(@w_newlines)
62
+ end
63
+
64
+ should "make any obj ids generic" do
65
+ exp_out = "#<struct #<Class:0xXXXXXX> a=\"aye\", b=\"bee\">"
66
+ assert_equal exp_out, subject.show_for_diff(@w_obj_id)
67
+ end
68
+
69
+ end
70
+
71
+ class TempfileTests < UnitTests
72
+ desc "`tempfile`"
73
+
74
+ should "require tempfile, open a tempfile, write the given content, and yield it" do
75
+ subject.tempfile('a-name', 'some-content') do |tmpfile|
76
+ assert_equal false, (require 'tempfile')
77
+ assert tmpfile
78
+ assert_kind_of Tempfile, tmpfile
79
+
80
+ tmpfile.pos = 0
81
+ assert_equal "some-content\n", tmpfile.read
82
+ end
83
+ end
84
+
85
+ end
86
+
87
+ class StdlibPpProcTests < UnitTests
88
+ desc "`stdlib_pp_proc`"
89
+
90
+ should "build a pp proc that uses stdlib `PP.pp` to pretty print objects" do
91
+ exp_obj_pps = @objs.map{ |o| "\n#{PP.pp(o, '', 79).strip}\n" }
92
+ act_obj_pps = @objs.map{ |o| subject.stdlib_pp_proc.call(o) }
93
+ assert_equal exp_obj_pps, act_obj_pps
94
+
95
+ cust_width = 1
96
+ exp_obj_pps = @objs.map{ |o| "\n#{PP.pp(o, '', cust_width).strip}\n" }
97
+ act_obj_pps = @objs.map{ |o| subject.stdlib_pp_proc(cust_width).call(o) }
98
+ assert_equal exp_obj_pps, act_obj_pps
99
+ end
100
+
101
+ end
102
+
103
+ class DefaultUseDiffProcTests < UnitTests
104
+ desc "`default_use_diff_proc`"
105
+ setup do
106
+ @longer = "i am a really long string output; use diff when working with me"
107
+ @newlines = "i have\n newlines"
108
+ end
109
+
110
+ should "be true if either output has newlines or is bigger than 29 chars" do
111
+ proc = subject.default_use_diff_proc
112
+
113
+ assert_not proc.call('', '')
114
+ assert proc.call(@longer, '')
115
+ assert proc.call(@newlines, '')
116
+ assert proc.call('', @longer)
117
+ assert proc.call('', @newlines)
118
+ assert proc.call(@longer, @newlines)
119
+ end
120
+
121
+ end
122
+
123
+ class SyscmdDiffProc < UnitTests
124
+ desc "`syscmd_diff_proc`"
125
+ setup do
126
+ @diff_a_file = File.join(ROOT_PATH, 'test/support/diff_a.txt')
127
+ @diff_b_file = File.join(ROOT_PATH, 'test/support/diff_b.txt')
128
+
129
+ @diff_a = File.read(@diff_a_file)
130
+ @diff_b = File.read(@diff_b_file)
131
+ end
132
+
133
+ should "use the diff syscmd to output the diff between the exp/act show output" do
134
+ exp_diff_out = `diff --unified=-1 #{@diff_a_file} #{@diff_b_file}`.tap do |out|
135
+ out.sub!(/^\-\-\- .+/, "--- expected")
136
+ out.sub!(/^\+\+\+ .+/, "+++ actual")
137
+ end
138
+
139
+ assert_equal exp_diff_out, subject.syscmd_diff_proc.call(@diff_a, @diff_b)
140
+ end
141
+
142
+ should "allow you to specify a custom syscmd" do
143
+ cust_syscmd = 'diff'
144
+ exp_diff_out = `#{cust_syscmd} #{@diff_a_file} #{@diff_b_file}`.tap do |out|
145
+ out.sub!(/^\-\-\- .+/, "--- expected")
146
+ out.sub!(/^\+\+\+ .+/, "+++ actual")
147
+ end
148
+
149
+ assert_equal exp_diff_out, subject.syscmd_diff_proc(cust_syscmd).call(@diff_a, @diff_b)
150
+ end
151
+
152
+ end
153
+
154
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assert
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
- - 3
9
- - 3
10
- version: 2.3.3
8
+ - 4
9
+ - 0
10
+ version: 2.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly Redding
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2013-11-11 00:00:00 Z
19
+ date: 2013-11-20 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: ansi
@@ -63,6 +63,7 @@ files:
63
63
  - lib/assert/runner.rb
64
64
  - lib/assert/suite.rb
65
65
  - lib/assert/test.rb
66
+ - lib/assert/utils.rb
66
67
  - lib/assert/version.rb
67
68
  - lib/assert/view.rb
68
69
  - lib/assert/view/base.rb
@@ -71,6 +72,8 @@ files:
71
72
  - lib/assert/view/helpers/common.rb
72
73
  - log/.gitkeep
73
74
  - test/helper.rb
75
+ - test/support/diff_a.txt
76
+ - test/support/diff_b.txt
74
77
  - test/support/inherited_stuff.rb
75
78
  - test/system/running_tests.rb
76
79
  - test/unit/assert_tests.rb
@@ -96,6 +99,7 @@ files:
96
99
  - test/unit/runner_tests.rb
97
100
  - test/unit/suite_tests.rb
98
101
  - test/unit/test_tests.rb
102
+ - test/unit/utils_tests.rb
99
103
  - test/unit/view_tests.rb
100
104
  - tmp/.gitkeep
101
105
  homepage: http://github.com/redding/assert
@@ -133,6 +137,8 @@ specification_version: 3
133
137
  summary: Test::Unit style testing framework, just better than Test::Unit.
134
138
  test_files:
135
139
  - test/helper.rb
140
+ - test/support/diff_a.txt
141
+ - test/support/diff_b.txt
136
142
  - test/support/inherited_stuff.rb
137
143
  - test/system/running_tests.rb
138
144
  - test/unit/assert_tests.rb
@@ -158,4 +164,5 @@ test_files:
158
164
  - test/unit/runner_tests.rb
159
165
  - test/unit/suite_tests.rb
160
166
  - test/unit/test_tests.rb
167
+ - test/unit/utils_tests.rb
161
168
  - test/unit/view_tests.rb