assert_same 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README +5 -0
- data/Rakefile +1 -1
- data/assert_same.gemspec +1 -3
- data/assert_same.kdev4 +3 -0
- data/lib/assert_same.rb +93 -12
- data/test/assert_same_test.rb +1 -1
- metadata +24 -54
data/.gitignore
CHANGED
data/README
CHANGED
data/Rakefile
CHANGED
data/assert_same.gemspec
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
SPEC = Gem::Specification.new do |s|
|
4
4
|
s.name = "assert_same"
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.3"
|
6
6
|
s.author = "Pluron, Inc."
|
7
7
|
s.email = "support@pluron.com"
|
8
8
|
s.homepage = "http://github.com/acunote/assert_same"
|
@@ -10,8 +10,6 @@ SPEC = Gem::Specification.new do |s|
|
|
10
10
|
s.description = "assert_same assertion"
|
11
11
|
s.summary = "Assert which checks that two strings (expected and actual) are same and which can magically replace expected value with the actual in case the new behavior (and new actual value) is correct"
|
12
12
|
|
13
|
-
s.add_development_dependency('bundler', '>= 1.0.0')
|
14
|
-
|
15
13
|
s.files = `git ls-files`.split("\n")
|
16
14
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
17
15
|
|
data/assert_same.kdev4
ADDED
data/lib/assert_same.rb
CHANGED
@@ -3,7 +3,53 @@ require 'test/unit/testcase'
|
|
3
3
|
require 'text_diff'
|
4
4
|
require 'pathname'
|
5
5
|
|
6
|
-
|
6
|
+
$assert_same_options = []
|
7
|
+
|
8
|
+
if RUBY_VERSION >= "1.9.0"
|
9
|
+
|
10
|
+
# Test/Unit from Ruby 1.9 can't accept additional options like it did in 1.8:
|
11
|
+
# ruby test.rb -- --foo
|
12
|
+
# Now it has a strict option parser that considers all additional options as files.
|
13
|
+
# The right way to have an option now is to explicitly add it to Test/Unit parser.
|
14
|
+
module Test::Unit
|
15
|
+
|
16
|
+
module AssertSameOption
|
17
|
+
def setup_options(parser, options)
|
18
|
+
super
|
19
|
+
parser.on '--no-interactive', 'assert_same: non-interactive mode' do |flag|
|
20
|
+
$assert_same_options << "--no-interactive"
|
21
|
+
puts $assert_same_options
|
22
|
+
end
|
23
|
+
parser.on '--no-canonicalize', 'assert_same: turn off canonicalization' do |flag|
|
24
|
+
$assert_same_options << "--no-canonicalize"
|
25
|
+
end
|
26
|
+
parser.on '--autoaccept', 'assert_same: automatically accept new actual values' do |flag|
|
27
|
+
$assert_same_options << "--autoaccept"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def non_options(files, options)
|
32
|
+
super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Runner < MiniTest::Unit
|
37
|
+
include Test::Unit::AssertSameOption
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
else
|
43
|
+
|
44
|
+
# In Ruby 1.8 additional test options are simply passed via ARGV
|
45
|
+
$assert_same_options << "--no-interactive" if ARGV.include?("--no-interactive")
|
46
|
+
$assert_same_options << "--no-canonicalize" if ARGV.include?("--no-canonicalize")
|
47
|
+
$assert_same_options << "--autoaccept" if ARGV.include?("--autoaccept")
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
module Test::Unit::Assertions
|
7
53
|
|
8
54
|
#Hash[filename][line_number] = offset
|
9
55
|
#For each line in the original file we store its offset (+N or -N lines)
|
@@ -38,12 +84,19 @@ class Test::Unit::TestCase
|
|
38
84
|
# --no-canonicalize turns off expected and actual value canonicalization (see below for details)
|
39
85
|
#
|
40
86
|
# Additional options can be passed during both single test file run and rake test run:
|
87
|
+
# In Ruby 1.8:
|
41
88
|
# ruby test/unit/foo_test.rb -- --autoaccept
|
42
89
|
# ruby test/unit/foo_test.rb -- --no-interactive
|
43
90
|
#
|
44
91
|
# rake test TESTOPTS="-- --autoaccept"
|
45
92
|
# rake test:units TESTOPTS="-- --no-canonicalize --autoaccept"
|
46
93
|
#
|
94
|
+
# In Ruby 1.9:
|
95
|
+
# ruby test/unit/foo_test.rb --autoaccept
|
96
|
+
# ruby test/unit/foo_test.rb --no-interactive
|
97
|
+
#
|
98
|
+
# rake test TESTOPTS="--autoaccept"
|
99
|
+
# rake test:units TESTOPTS="--no-canonicalize --autoaccept"
|
47
100
|
#
|
48
101
|
#
|
49
102
|
# == Canonicalization ==
|
@@ -59,7 +112,10 @@ class Test::Unit::TestCase
|
|
59
112
|
# You can turn canonicalization off with --no-canonicalize option. This is useful
|
60
113
|
# when you need to regenerate expected test strings.
|
61
114
|
# To regenerate the whole test suite, run:
|
115
|
+
# In Ruby 1.8:
|
62
116
|
# rake test TESTOPTS="-- --no-canonicalize --autoaccept"
|
117
|
+
# In Ruby 1.9:
|
118
|
+
# rake test TESTOPTS="--no-canonicalize --autoaccept"
|
63
119
|
#
|
64
120
|
# Example of assert_same with comments:
|
65
121
|
# assert_same something, <<-END
|
@@ -118,9 +174,9 @@ class Test::Unit::TestCase
|
|
118
174
|
# interactive mode is turned on by default, except when
|
119
175
|
# - --no-interactive is given
|
120
176
|
# - STDIN is not a terminal device (i.e. we can't ask any questions)
|
121
|
-
interactive =
|
122
|
-
canonicalize =
|
123
|
-
autoaccept =
|
177
|
+
interactive = !$assert_same_options.include?("--no-interactive") && STDIN.tty?
|
178
|
+
canonicalize = !$assert_same_options.include?("--no-canonicalize")
|
179
|
+
autoaccept = $assert_same_options.include?("--autoaccept")
|
124
180
|
|
125
181
|
is_same_canonicalized, is_same, diff_canonicalized, diff = compare_for_assert_same(expected, actual)
|
126
182
|
|
@@ -128,8 +184,7 @@ class Test::Unit::TestCase
|
|
128
184
|
diff_to_report = canonicalize ? diff_canonicalized : diff
|
129
185
|
if interactive
|
130
186
|
# print method name and short backtrace
|
131
|
-
|
132
|
-
puts "\n#{failure}"
|
187
|
+
soft_fail(diff_to_report)
|
133
188
|
|
134
189
|
if autoaccept
|
135
190
|
accept = true
|
@@ -138,8 +193,8 @@ class Test::Unit::TestCase
|
|
138
193
|
STDOUT.flush
|
139
194
|
response = STDIN.gets.strip
|
140
195
|
accept = ["", "y", "Y"].include? response
|
141
|
-
|
142
|
-
|
196
|
+
$assert_same_options << "--autoaccept" if response == "Y"
|
197
|
+
$assert_same_options << "--no-interactive" if response == "N"
|
143
198
|
end
|
144
199
|
|
145
200
|
if accept
|
@@ -154,17 +209,43 @@ class Test::Unit::TestCase
|
|
154
209
|
# when change is accepted, we should not report it as a failure because
|
155
210
|
# we want the test method to continue executing (in case there're more
|
156
211
|
# assert_same's in the method)
|
157
|
-
|
212
|
+
succeed
|
158
213
|
else
|
159
|
-
|
214
|
+
fail(diff)
|
160
215
|
end
|
161
216
|
else
|
162
|
-
|
217
|
+
succeed
|
163
218
|
end
|
164
219
|
end
|
165
220
|
|
166
221
|
private
|
167
222
|
|
223
|
+
def succeed
|
224
|
+
if RUBY_VERSION < "1.9.0"
|
225
|
+
add_assertion
|
226
|
+
else
|
227
|
+
true
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
def soft_fail(diff)
|
232
|
+
if RUBY_VERSION < "1.9.0"
|
233
|
+
failure = Test::Unit::Failure.new(name, filter_backtrace(caller(0)), diff)
|
234
|
+
puts "\n#{failure}"
|
235
|
+
else
|
236
|
+
failure = MiniTest::Assertion.new(diff)
|
237
|
+
puts "\n#{failure}"
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
def fail(diff)
|
242
|
+
if RUBY_VERSION < "1.9.0"
|
243
|
+
raise Test::Unit::AssertionFailedError.new(diff)
|
244
|
+
else
|
245
|
+
raise MiniTest::Assertion.new(diff)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
168
249
|
def accept_string(actual, mode)
|
169
250
|
file, method, line = get_caller_location(:depth => 3)
|
170
251
|
|
@@ -209,7 +290,7 @@ private
|
|
209
290
|
@@file_offsets[file][line.to_i] = actual_length - expected_length
|
210
291
|
|
211
292
|
source_file = File.open(file, "w+")
|
212
|
-
source_file.write(source)
|
293
|
+
source_file.write(source.join(''))
|
213
294
|
source_file.fsync
|
214
295
|
source_file.close
|
215
296
|
end
|
data/test/assert_same_test.rb
CHANGED
metadata
CHANGED
@@ -1,51 +1,28 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: assert_same
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.3'
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
version: "0.2"
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Pluron, Inc.
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
dependencies:
|
19
|
-
- !ruby/object:Gem::Dependency
|
20
|
-
name: bundler
|
21
|
-
prerelease: false
|
22
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
-
none: false
|
24
|
-
requirements:
|
25
|
-
- - ">="
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
hash: 23
|
28
|
-
segments:
|
29
|
-
- 1
|
30
|
-
- 0
|
31
|
-
- 0
|
32
|
-
version: 1.0.0
|
33
|
-
type: :development
|
34
|
-
version_requirements: *id001
|
12
|
+
date: 2012-11-14 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
35
14
|
description: assert_same assertion
|
36
15
|
email: support@pluron.com
|
37
16
|
executables: []
|
38
|
-
|
39
17
|
extensions: []
|
40
|
-
|
41
18
|
extra_rdoc_files: []
|
42
|
-
|
43
|
-
files:
|
19
|
+
files:
|
44
20
|
- .gitignore
|
45
21
|
- LICENSE
|
46
22
|
- README
|
47
23
|
- Rakefile
|
48
24
|
- assert_same.gemspec
|
25
|
+
- assert_same.kdev4
|
49
26
|
- init.rb
|
50
27
|
- lib/array_diff.rb
|
51
28
|
- lib/assert_same.rb
|
@@ -54,37 +31,30 @@ files:
|
|
54
31
|
- test/logs/assert_same_with_files.log.ref
|
55
32
|
homepage: http://github.com/acunote/assert_same
|
56
33
|
licenses: []
|
57
|
-
|
58
34
|
post_install_message:
|
59
35
|
rdoc_options: []
|
60
|
-
|
61
|
-
require_paths:
|
36
|
+
require_paths:
|
62
37
|
- lib
|
63
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
39
|
none: false
|
65
|
-
requirements:
|
66
|
-
- -
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
|
69
|
-
|
70
|
-
- 0
|
71
|
-
version: "0"
|
72
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
45
|
none: false
|
74
|
-
requirements:
|
75
|
-
- -
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
|
78
|
-
segments:
|
79
|
-
- 0
|
80
|
-
version: "0"
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
81
50
|
requirements: []
|
82
|
-
|
83
51
|
rubyforge_project:
|
84
|
-
rubygems_version: 1.8.
|
52
|
+
rubygems_version: 1.8.23
|
85
53
|
signing_key:
|
86
54
|
specification_version: 3
|
87
|
-
summary: Assert which checks that two strings (expected and actual) are same and which
|
88
|
-
|
55
|
+
summary: Assert which checks that two strings (expected and actual) are same and which
|
56
|
+
can magically replace expected value with the actual in case the new behavior (and
|
57
|
+
new actual value) is correct
|
58
|
+
test_files:
|
89
59
|
- test/assert_same_test.rb
|
90
60
|
- test/logs/assert_same_with_files.log.ref
|