assert 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/README.md +8 -8
  2. data/lib/assert.rb +9 -62
  3. data/lib/assert/assert_runner.rb +15 -30
  4. data/lib/assert/assertions.rb +105 -41
  5. data/lib/assert/cli.rb +1 -1
  6. data/lib/assert/config.rb +56 -0
  7. data/lib/assert/context.rb +44 -150
  8. data/lib/assert/context/setup_dsl.rb +70 -0
  9. data/lib/assert/context/subject_dsl.rb +39 -0
  10. data/lib/assert/context/suite_dsl.rb +20 -0
  11. data/lib/assert/context/test_dsl.rb +51 -0
  12. data/lib/assert/runner.rb +8 -2
  13. data/lib/assert/suite.rb +33 -12
  14. data/lib/assert/test.rb +11 -8
  15. data/lib/assert/utils.rb +23 -11
  16. data/lib/assert/version.rb +1 -1
  17. data/lib/assert/view.rb +9 -7
  18. data/lib/assert/view/base.rb +26 -4
  19. data/lib/assert/view/default_view.rb +1 -1
  20. data/lib/assert/view/helpers/ansi_styles.rb +1 -1
  21. data/lib/assert/view/helpers/common.rb +16 -6
  22. data/test/helper.rb +1 -94
  23. data/test/support/factory.rb +70 -0
  24. data/test/system/running_tests.rb +55 -28
  25. data/test/unit/assert_tests.rb +6 -33
  26. data/test/unit/assertions/assert_block_tests.rb +3 -3
  27. data/test/unit/assertions/assert_empty_tests.rb +6 -4
  28. data/test/unit/assertions/assert_equal_tests.rb +19 -22
  29. data/test/unit/assertions/assert_file_exists_tests.rb +6 -4
  30. data/test/unit/assertions/assert_includes_tests.rb +8 -4
  31. data/test/unit/assertions/assert_instance_of_tests.rb +8 -6
  32. data/test/unit/assertions/assert_kind_of_tests.rb +8 -5
  33. data/test/unit/assertions/assert_match_tests.rb +8 -4
  34. data/test/unit/assertions/assert_nil_tests.rb +6 -4
  35. data/test/unit/assertions/assert_raises_tests.rb +2 -2
  36. data/test/unit/assertions/assert_respond_to_tests.rb +7 -5
  37. data/test/unit/assertions/assert_same_tests.rb +75 -6
  38. data/test/unit/assertions/assert_true_false_tests.rb +116 -0
  39. data/test/unit/assertions_tests.rb +7 -5
  40. data/test/unit/config_tests.rb +58 -0
  41. data/test/unit/context/{setup_teardown_singleton_tests.rb → setup_dsl_tests.rb} +17 -19
  42. data/test/unit/context/subject_dsl_tests.rb +78 -0
  43. data/test/unit/context/suite_dsl_tests.rb +47 -0
  44. data/test/unit/context/{test_should_singleton_tests.rb → test_dsl_tests.rb} +33 -34
  45. data/test/unit/context_tests.rb +19 -15
  46. data/test/unit/runner_tests.rb +9 -3
  47. data/test/unit/suite_tests.rb +20 -23
  48. data/test/unit/test_tests.rb +22 -14
  49. data/test/unit/utils_tests.rb +15 -21
  50. data/test/unit/view_tests.rb +12 -5
  51. metadata +23 -10
  52. data/test/unit/context/basic_singleton_tests.rb +0 -86
data/README.md CHANGED
@@ -11,22 +11,22 @@ require 'assert'
11
11
 
12
12
  class MyTests < Assert::Context
13
13
 
14
- def test_something
14
+ test "something" do
15
15
  assert_equal 1, 1
16
16
  end
17
17
 
18
18
  end
19
19
  ```
20
20
 
21
- ```sh
21
+ ```
22
22
  $ assert test/my_tests.rb
23
23
  Loaded suite (1 test)
24
- Running tests in random order, seeded with "33650"
24
+ Running tests in random order, seeded with "56382"
25
25
  .
26
26
 
27
27
  1 result: pass
28
28
 
29
- (0.000199 seconds)
29
+ (0.000128 seconds, 7812.500000 tests/s, 7812.500000 results/s)
30
30
  ```
31
31
 
32
32
  ## What Assert is
@@ -226,11 +226,11 @@ git ls-files --others --exclude-standard # added files
226
226
 
227
227
  The git cmds have ` -- #{test_paths}` appended to them to scope their results to just the test paths specified by the CLI and are run together using ` && `.
228
228
 
229
- This, of course, assumes you are working in a git repository. If you are not or you want to use custom logic to determine the changed files, configure a custom proc. The proc should take a single parameter which is an array of test paths specified by the CLI.
229
+ This, of course, assumes you are working in a git repository. If you are not or you want to use custom logic to determine the changed files, configure a custom proc. The proc should take two parameters: the config and an array of test paths specified by the CLI.
230
230
 
231
231
  ```ruby
232
232
  Assert.configure do |config|
233
- config.changed_files do |test_paths|
233
+ config.changed_proc Proc.new do |config, test_paths|
234
234
  `git diff --name-only master -- #{test_paths.join(' ')}`.split("\n") # or whatever
235
235
  end
236
236
  end
@@ -242,10 +242,10 @@ If you just want to disable this feature completely:
242
242
  Assert.configure do |config|
243
243
 
244
244
  # run nothing if the `-c` flag is given
245
- config.changed_files{ |test_paths| [] }
245
+ config.changed_proc Proc.new{ |test_paths| [] }
246
246
 
247
247
  # run all test paths if the `-c` flag is given
248
- config.changed_files{ |test_paths| test_paths }
248
+ config.changed_proc Proc.new{ |test_paths| test_paths }
249
249
 
250
250
  end
251
251
  ```
data/lib/assert.rb CHANGED
@@ -1,72 +1,19 @@
1
- require 'singleton'
2
1
  require 'assert/version'
3
2
 
3
+ require 'assert/config'
4
+ require 'assert/context'
5
+ require 'assert/runner'
6
+ require 'assert/suite'
4
7
  require 'assert/utils'
5
8
  require 'assert/view'
6
- require 'assert/suite'
7
- require 'assert/runner'
8
- require 'assert/context'
9
9
 
10
10
  module Assert
11
11
 
12
- def self.view; Config.view; end
13
- def self.suite; Config.suite; end
14
- def self.runner; Config.runner; end
15
-
16
- def self.config; Config; end
17
- def self.configure; yield Config if block_given?; end
18
-
19
- class Config
20
- include Singleton
21
- # map any class methods to the singleton
22
- def self.method_missing(m, *a, &b); self.instance.send(m, *a, &b); end
23
- def self.respond_to?(m); super || self.instance.respond_to?(m); end
24
-
25
- def self.settings(*items)
26
- items.each do |item|
27
- define_method(item) do |*args|
28
- if !(value = args.size > 1 ? args : args.first).nil?
29
- instance_variable_set("@#{item}", value)
30
- end
31
- instance_variable_get("@#{item}")
32
- end
33
- end
34
- end
35
-
36
- settings :view, :suite, :runner, :test_dir, :test_helper, :changed_files
37
- settings :runner_seed, :pp_proc, :use_diff_proc, :run_diff_proc
38
- settings :capture_output, :halt_on_fail, :changed_only, :pp_objects, :debug
39
-
40
- def initialize
41
- @view = Assert::View::DefaultView.new($stdout)
42
- @suite = Assert::Suite.new
43
- @runner = Assert::Runner.new
44
- @test_dir = "test"
45
- @test_helper = "helper.rb"
46
- @changed_files = Assert::AssertRunner::DEFAULT_CHANGED_FILES_PROC
47
-
48
- # default option values
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
55
- @capture_output = false
56
- @halt_on_fail = true
57
- @changed_only = false
58
- @pp_objects = false
59
- @debug = false
60
- end
61
-
62
- def apply(settings)
63
- settings.keys.each do |name|
64
- if !settings[name].nil? && self.respond_to?(name.to_s)
65
- self.send(name.to_s, settings[name])
66
- end
67
- end
68
- end
12
+ def self.config; @config ||= Config.new; end
13
+ def self.configure; yield self.config if block_given?; end
69
14
 
70
- end
15
+ def self.view; self.config.view; end
16
+ def self.suite; self.config.suite; end
17
+ def self.runner; self.config.runner; end
71
18
 
72
19
  end
@@ -3,26 +3,13 @@ require 'assert/cli'
3
3
  module Assert
4
4
 
5
5
  class AssertRunner
6
- TEST_FILE_SUFFIXES = ['_tests.rb', '_test.rb']
7
6
  USER_SETTINGS_FILE = ".assert/init.rb"
8
7
  LOCAL_SETTINGS_FILE = ".assert.rb"
9
8
 
10
- DEFAULT_CHANGED_FILES_PROC = Proc.new do |test_paths|
11
- # use git to determine which files have changes
12
- files = []
13
- cmd = [
14
- "git diff --no-ext-diff --name-only", # changed files
15
- "git ls-files --others --exclude-standard" # added files
16
- ].map{ |c| "#{c} -- #{test_paths.join(' ')}" }.join(' && ')
9
+ attr_reader :config
17
10
 
18
- Assert::CLI.bench('Load only changed files') do
19
- files = `#{cmd}`.split("\n")
20
- end
21
- puts Assert::CLI.debug_msg(" `#{cmd}`") if Assert.config.debug
22
- files
23
- end
24
-
25
- def initialize(test_paths, test_options)
11
+ def initialize(config, test_paths, test_options)
12
+ @config = config
26
13
  Assert::CLI.bench('Apply settings') do
27
14
  apply_user_settings
28
15
  apply_local_settings
@@ -30,30 +17,30 @@ module Assert
30
17
  apply_env_settings
31
18
  end
32
19
 
33
- files = test_files(test_paths.empty? ? [*Assert.config.test_dir] : test_paths)
34
- init(files, path_of(Assert.config.test_dir, files.first))
20
+ files = test_files(test_paths.empty? ? [*self.config.test_dir] : test_paths)
21
+ init(files, path_of(self.config.test_dir, files.first))
35
22
  end
36
23
 
37
24
  def init(test_files, test_dir)
38
25
  # load any test helper file
39
- if test_dir && (h = File.join(test_dir, Config.test_helper)) && File.exists?(h)
26
+ if test_dir && (h = File.join(test_dir, self.config.test_helper)) && File.exists?(h)
40
27
  Assert::CLI.bench('Require test helper'){ require h }
41
28
  end
42
29
 
43
30
  # load the test files
44
- Assert.view.fire(:before_load, test_files)
31
+ self.config.view.fire(:before_load, test_files)
45
32
  Assert::CLI.bench("Require #{test_files.count} test files") do
46
33
  test_files.each{ |p| require p }
47
34
  end
48
- if Assert.config.debug
35
+ if self.config.debug
49
36
  puts Assert::CLI.debug_msg("Test files:")
50
37
  test_files.each{ |f| puts Assert::CLI.debug_msg(" #{f}") }
51
38
  end
52
- Assert.view.fire(:after_load)
39
+ self.config.view.fire(:after_load)
53
40
  end
54
41
 
55
42
  def run
56
- Assert.runner.run(Assert.suite, Assert.view)
43
+ self.config.runner.run(self.config.suite, self.config.view)
57
44
  end
58
45
 
59
46
  protected
@@ -67,19 +54,17 @@ module Assert
67
54
  end
68
55
 
69
56
  def apply_option_settings(options)
70
- Assert.config.apply(options)
57
+ self.config.apply(options)
71
58
  end
72
59
 
73
60
  def apply_env_settings
74
- Assert.configure do |c|
75
- c.runner_seed ENV['ASSERT_RUNNER_SEED'].to_i if ENV['ASSERT_RUNNER_SEED']
76
- end
61
+ self.config.runner_seed ENV['ASSERT_RUNNER_SEED'].to_i if ENV['ASSERT_RUNNER_SEED']
77
62
  end
78
63
 
79
64
  private
80
65
 
81
66
  def test_files(test_paths)
82
- file_paths = if Assert.config.changed_only
67
+ file_paths = if self.config.changed_only
83
68
  changed_test_files(test_paths)
84
69
  else
85
70
  globbed_test_files(test_paths)
@@ -89,7 +74,7 @@ module Assert
89
74
  end
90
75
 
91
76
  def changed_test_files(test_paths)
92
- globbed_test_files(Assert.config.changed_files.call(test_paths))
77
+ globbed_test_files(self.config.changed_proc.call(self.config, test_paths))
93
78
  end
94
79
 
95
80
  def globbed_test_files(test_paths)
@@ -100,7 +85,7 @@ module Assert
100
85
  end
101
86
 
102
87
  def is_test_file?(path)
103
- TEST_FILE_SUFFIXES.inject(false) do |result, suffix|
88
+ self.config.test_file_suffixes.inject(false) do |result, suffix|
104
89
  result || path =~ /#{suffix}$/
105
90
  end
106
91
  end
@@ -9,47 +9,49 @@ module Assert
9
9
  end
10
10
 
11
11
  def assert_not_block(desc = nil)
12
- assert(!yield, desc){ "Expected block to return a false value." }
12
+ assert(!yield, desc){ "Expected block to not return a true value." }
13
13
  end
14
14
  alias_method :refute_block, :assert_not_block
15
15
 
16
16
  def assert_empty(collection, desc = nil)
17
17
  assert(collection.empty?, desc) do
18
- "Expected #{Assert::U.show(collection)} to be empty."
18
+ "Expected #{Assert::U.show(collection, __assert_config__)} to be empty."
19
19
  end
20
20
  end
21
21
 
22
22
  def assert_not_empty(collection, desc = nil)
23
23
  assert(!collection.empty?, desc) do
24
- "Expected #{Assert::U.show(collection)} to not be empty."
24
+ "Expected #{Assert::U.show(collection, __assert_config__)} to not be empty."
25
25
  end
26
26
  end
27
27
  alias_method :refute_empty, :assert_not_empty
28
28
 
29
29
  def assert_equal(exp, act, desc = nil)
30
30
  assert(act == exp, desc) do
31
- exp_show = Assert::U.show_for_diff(exp)
32
- act_show = Assert::U.show_for_diff(act)
31
+ c = __assert_config__
32
+ exp_show = Assert::U.show_for_diff(exp, c)
33
+ act_show = Assert::U.show_for_diff(act, c)
33
34
 
34
- if Assert.config.use_diff_proc.call(exp_show, act_show)
35
+ if c.use_diff_proc.call(exp_show, act_show)
35
36
  "Expected does not equal actual, diff:\n"\
36
- "#{Assert.config.run_diff_proc.call(exp_show, act_show)}"
37
+ "#{c.run_diff_proc.call(exp_show, act_show)}"
37
38
  else
38
- "Expected #{Assert::U.show(exp)}, not #{Assert::U.show(act)}."
39
+ "Expected #{Assert::U.show(act, c)} to be equal to #{Assert::U.show(exp, c)}."
39
40
  end
40
41
  end
41
42
  end
42
43
 
43
44
  def assert_not_equal(exp, act, desc = nil)
44
45
  assert(act != exp, desc) do
45
- exp_show = Assert::U.show_for_diff(exp)
46
- act_show = Assert::U.show_for_diff(act)
46
+ c = __assert_config__
47
+ exp_show = Assert::U.show_for_diff(exp, c)
48
+ act_show = Assert::U.show_for_diff(act, c)
47
49
 
48
- if Assert.config.use_diff_proc.call(exp_show, act_show)
50
+ if c.use_diff_proc.call(exp_show, act_show)
49
51
  "Expected equals actual, diff:\n"\
50
- "#{Assert.config.run_diff_proc.call(exp_show, act_show)}"
52
+ "#{c.run_diff_proc.call(exp_show, act_show)}"
51
53
  else
52
- "#{Assert::U.show(act)} not expected to equal #{Assert::U.show(exp)}."
54
+ "Expected #{Assert::U.show(act, c)} to not be equal to #{Assert::U.show(exp, c)}."
53
55
  end
54
56
  end
55
57
  end
@@ -57,27 +59,29 @@ module Assert
57
59
 
58
60
  def assert_file_exists(file_path, desc = nil)
59
61
  assert(File.exists?(File.expand_path(file_path)), desc) do
60
- "Expected #{Assert::U.show(file_path)} to exist."
62
+ "Expected #{Assert::U.show(file_path, __assert_config__)} to exist."
61
63
  end
62
64
  end
63
65
 
64
66
  def assert_not_file_exists(file_path, desc = nil)
65
67
  assert(!File.exists?(File.expand_path(file_path)), desc) do
66
- "Expected #{Assert::U.show(file_path)} to not exist."
68
+ "Expected #{Assert::U.show(file_path, __assert_config__)} to not exist."
67
69
  end
68
70
  end
69
71
  alias_method :refute_file_exists, :assert_not_file_exists
70
72
 
71
73
  def assert_includes(object, collection, desc = nil)
72
74
  assert(collection.include?(object), desc) do
73
- "Expected #{Assert::U.show(collection)} to include #{Assert::U.show(object)}."
75
+ "Expected #{Assert::U.show(collection, __assert_config__)}"\
76
+ " to include #{Assert::U.show(object, __assert_config__)}."
74
77
  end
75
78
  end
76
79
  alias_method :assert_included, :assert_includes
77
80
 
78
81
  def assert_not_includes(object, collection, desc = nil)
79
82
  assert(!collection.include?(object), desc) do
80
- "Expected #{Assert::U.show(collection)} to not include #{Assert::U.show(object)}."
83
+ "Expected #{Assert::U.show(collection, __assert_config__)}"\
84
+ " to not include #{Assert::U.show(object, __assert_config__)}."
81
85
  end
82
86
  end
83
87
  alias_method :assert_not_included, :assert_not_includes
@@ -86,55 +90,91 @@ module Assert
86
90
 
87
91
  def assert_instance_of(klass, instance, desc = nil)
88
92
  assert(instance.instance_of?(klass), desc) do
89
- "Expected #{Assert::U.show(instance)} (#{instance.class}) to be an instance of #{klass}."
93
+ "Expected #{Assert::U.show(instance, __assert_config__)} (#{instance.class})"\
94
+ " to be an instance of #{klass}."
90
95
  end
91
96
  end
92
97
 
93
98
  def assert_not_instance_of(klass, instance, desc = nil)
94
99
  assert(!instance.instance_of?(klass), desc) do
95
- "#{Assert::U.show(instance)} (#{instance.class}) not expected to be an instance of #{klass}."
100
+ "Expected #{Assert::U.show(instance, __assert_config__)} (#{instance.class})"\
101
+ " to not be an instance of #{klass}."
96
102
  end
97
103
  end
98
104
  alias_method :refute_instance_of, :assert_not_instance_of
99
105
 
100
- def assert_kind_of(klass, instance, desc=nil)
106
+ def assert_kind_of(klass, instance, desc = nil)
101
107
  assert(instance.kind_of?(klass), desc) do
102
- "Expected #{Assert::U.show(instance)} (#{instance.class}) to be a kind of #{klass}."
108
+ "Expected #{Assert::U.show(instance, __assert_config__)} (#{instance.class})"\
109
+ " to be a kind of #{klass}."
103
110
  end
104
111
  end
105
112
 
106
- def assert_not_kind_of(klass, instance, desc=nil)
113
+ def assert_not_kind_of(klass, instance, desc = nil)
107
114
  assert(!instance.kind_of?(klass), desc) do
108
- "#{Assert::U.show(instance)} not expected to be a kind of #{klass}."
115
+ "Expected #{Assert::U.show(instance, __assert_config__)} (#{instance.class})"\
116
+ " to not be a kind of #{klass}."
109
117
  end
110
118
  end
111
119
  alias_method :refute_kind_of, :assert_not_kind_of
112
120
 
113
- def assert_match(exp, act, desc=nil)
121
+ def assert_match(exp, act, desc = nil)
114
122
  exp_regex = String === exp && String === act ? /#{Regexp.escape(exp)}/ : exp
115
123
  assert(act =~ exp_regex, desc) do
116
- "Expected #{Assert::U.show(act)} to match #{Assert::U.show(exp)}."
124
+ "Expected #{Assert::U.show(act, __assert_config__)}"\
125
+ " to match #{Assert::U.show(exp, __assert_config__)}."
117
126
  end
118
127
  end
119
128
 
120
- def assert_not_match(exp, act, desc=nil)
129
+ def assert_not_match(exp, act, desc = nil)
121
130
  exp = String === exp && String === act ? /#{Regexp.escape(exp)}/ : exp
122
131
  assert(act !~ exp, desc) do
123
- "#{Assert::U.show(act)} not expected to match #{Assert::U.show(exp)}."
132
+ "Expected #{Assert::U.show(act, __assert_config__)}"\
133
+ " to not match #{Assert::U.show(exp, __assert_config__)}."
124
134
  end
125
135
  end
126
136
  alias_method :refute_match, :assert_not_match
127
137
  alias_method :assert_no_match, :assert_not_match
128
138
 
129
- def assert_nil(object, desc=nil)
130
- assert(object.nil?, desc){ "Expected nil, not #{Assert::U.show(object)}." }
139
+ def assert_nil(object, desc = nil)
140
+ assert(object.nil?, desc) do
141
+ "Expected #{Assert::U.show(object, __assert_config__)} to be nil."
142
+ end
131
143
  end
132
144
 
133
- def assert_not_nil(object, desc=nil)
134
- assert(!object.nil?, desc){ "Expected #{Assert::U.show(object)} to not be nil." }
145
+ def assert_not_nil(object, desc = nil)
146
+ assert(!object.nil?, desc) do
147
+ "Expected #{Assert::U.show(object, __assert_config__)} to not be nil."
148
+ end
135
149
  end
136
150
  alias_method :refute_nil, :assert_not_nil
137
151
 
152
+ def assert_true(object, desc = nil)
153
+ assert(object == true, desc) do
154
+ "Expected #{Assert::U.show(object, __assert_config__)} to be true."
155
+ end
156
+ end
157
+
158
+ def assert_not_true(object, desc = nil)
159
+ assert(object != true, desc) do
160
+ "Expected #{Assert::U.show(object, __assert_config__)} to not be true."
161
+ end
162
+ end
163
+ alias_method :refute_true, :assert_not_true
164
+
165
+ def assert_false(object, desc = nil)
166
+ assert(object == false, desc) do
167
+ "Expected #{Assert::U.show(object, __assert_config__)} to be false."
168
+ end
169
+ end
170
+
171
+ def assert_not_false(object, desc = nil)
172
+ assert(object != false, desc) do
173
+ "Expected #{Assert::U.show(object, __assert_config__)} to not be false."
174
+ end
175
+ end
176
+ alias_method :refute_false, :assert_not_false
177
+
138
178
  def assert_raises(*exceptions, &block)
139
179
  desc = exceptions.last.kind_of?(String) ? exceptions.pop : nil
140
180
  err = RaisedException.new(exceptions, &block)
@@ -150,33 +190,57 @@ module Assert
150
190
  alias_method :assert_not_raises, :assert_nothing_raised
151
191
  alias_method :assert_not_raise, :assert_nothing_raised
152
192
 
153
- def assert_respond_to(method, object, desc=nil)
193
+ def assert_respond_to(method, object, desc = nil)
154
194
  assert(object.respond_to?(method), desc) do
155
- "Expected #{Assert::U.show(object)} (#{object.class}) to respond to `#{method}`."
195
+ "Expected #{Assert::U.show(object, __assert_config__)} (#{object.class})"\
196
+ " to respond to `#{method}`."
156
197
  end
157
198
  end
158
199
  alias_method :assert_responds_to, :assert_respond_to
159
200
 
160
- def assert_not_respond_to(method, object, desc=nil)
201
+ def assert_not_respond_to(method, object, desc = nil)
161
202
  assert(!object.respond_to?(method), desc) do
162
- "#{Assert::U.show(object)} (#{object.class}) not expected to respond to `#{method}`."
203
+ "Expected #{Assert::U.show(object, __assert_config__)} (#{object.class})"\
204
+ " to not respond to `#{method}`."
163
205
  end
164
206
  end
165
207
  alias_method :assert_not_responds_to, :assert_not_respond_to
166
208
  alias_method :refute_respond_to, :assert_not_respond_to
167
209
  alias_method :refute_responds_to, :assert_not_respond_to
168
210
 
169
- def assert_same(exp, act, desc=nil)
211
+ def assert_same(exp, act, desc = nil)
170
212
  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})."
213
+ c = __assert_config__
214
+ exp_show = Assert::U.show_for_diff(exp, c)
215
+ act_show = Assert::U.show_for_diff(act, c)
216
+ exp_id = "#<#{exp.class}:#{'0x0%x' % (exp.object_id << 1)}>"
217
+ act_id = "#<#{act.class}:#{'0x0%x' % (act.object_id << 1)}>"
218
+
219
+ if c.use_diff_proc.call(exp_show, act_show)
220
+ "Expected #{act_id} to be the same as #{exp_id}, diff:\n"\
221
+ "#{c.run_diff_proc.call(exp_show, act_show)}"
222
+ else
223
+ "Expected #{Assert::U.show(act, c)} (#{act_id}) to be the same as"\
224
+ " #{Assert::U.show(exp, c)} (#{exp_id})."
225
+ end
173
226
  end
174
227
  end
175
228
 
176
- def assert_not_same(exp, act, desc=nil)
229
+ def assert_not_same(exp, act, desc = nil)
177
230
  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})."
231
+ c = __assert_config__
232
+ exp_show = Assert::U.show_for_diff(exp, c)
233
+ act_show = Assert::U.show_for_diff(act, c)
234
+ exp_id = "#<#{exp.class}:#{'0x0%x' % (exp.object_id << 1)}>"
235
+ act_id = "#<#{act.class}:#{'0x0%x' % (act.object_id << 1)}>"
236
+
237
+ if c.use_diff_proc.call(exp_show, act_show)
238
+ "Expected #{act_id} to not be the same as #{exp_id}, diff:\n"\
239
+ "#{c.run_diff_proc.call(exp_show, act_show)}"
240
+ else
241
+ "Expected #{Assert::U.show(act, c)} (#{act_id}) to not be the same as"\
242
+ " #{Assert::U.show(exp, c)} (#{exp_id})."
243
+ end
180
244
  end
181
245
  end
182
246
  alias_method :refute_same, :assert_not_same