assert_value 1.2 → 1.3

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/Gemfile CHANGED
@@ -2,6 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
+ # gem 'minitest', '~> 5.0'
5
6
  group :development, :test do
6
7
  gem 'rspec'
7
8
  end
data/README.md CHANGED
@@ -121,6 +121,7 @@ In Ruby 1.9:
121
121
 
122
122
  ## Changelog
123
123
 
124
+ - 1.3: Improve support for various testing frameworks, fix assertion counters
124
125
  - 1.2: Rails 4.1 and minitest gem support
125
126
  - 1.1: RSpec support
126
127
  - 1.0: Rename to assert_value
data/assert_value.gemspec CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  SPEC = Gem::Specification.new do |s|
4
4
  s.name = "assert_value"
5
- s.version = "1.2"
5
+ s.version = "1.3"
6
6
  s.author = "Pluron, Inc."
7
7
  s.email = "support@pluron.com"
8
8
  s.homepage = "http://github.com/acunote/assert_value"
data/lib/assert_value.rb CHANGED
@@ -1,22 +1,46 @@
1
1
  # Copyright (c) 2010-2011 Pluron, Inc.
2
2
 
3
- if defined?(Minitest)
4
- # nothing to require, minitest gem is already loaded
5
- # it's the only way we can detect Minitest presence
3
+ # make sure test/unit or minitest is loaded before assert_value
4
+ # once Ruby 1.8 support is removed, we can replace this code
5
+ # with .gemspec dependency on minitest
6
+ begin
7
+ require 'minitest/unit'
8
+ unless defined?(Minitest) and Minitest.const_defined?("VERSION") and Minitest::VERSION >= "5.0.0"
9
+ # older minitest versions can be combined with test/unit to support overridable command line options
10
+ require 'test/unit'
11
+ end
12
+ rescue LoadError
13
+ require 'test/unit'
14
+ end
15
+
16
+ # there're 3 types of test frameworks we support
17
+ # 1) test/unit from Ruby 1.8
18
+ # 2) old minitest 2.x-4.x, either bundled with Ruby 1.9 - 2.1 or installed via gem
19
+ # 3) new minitest 5.x from minitest gem (required for example by Rails 4.1)
20
+
21
+ if defined?(Minitest) and Minitest.const_defined?("VERSION") and Minitest::VERSION >= "5.0.0"
22
+ ASSERT_VALUE_TEST_FRAMEWORK = :new_minitest
23
+ elsif defined?(MiniTest)
24
+ ASSERT_VALUE_TEST_FRAMEWORK = :old_minitest
25
+ elsif defined?(Test)
26
+ ASSERT_VALUE_TEST_FRAMEWORK = :test_unit
6
27
  else
7
- require 'test/unit/testcase'
28
+ raise LoadError.new("Require assert_value after 'test/unit' or 'minitest/autorun'")
8
29
  end
30
+
9
31
  require 'text_diff'
10
32
  require 'pathname'
11
33
 
12
34
  $assert_value_options = []
13
35
 
14
- if RUBY_VERSION >= "1.9.0" and !defined?(Minitest) # minitest options are handled by minitest/assert_value_plugin.rb
36
+ if ASSERT_VALUE_TEST_FRAMEWORK == :new_minitest
37
+ # minitest options are handled by minitest/assert_value_plugin.rb that is required automatically
15
38
 
16
- # Test/Unit from Ruby 1.9 can't accept additional options like it did in 1.8:
17
- # ruby test.rb -- --foo
18
- # Now it has a strict option parser that considers all additional options as files.
19
- # The right way to have an option now is to explicitly add it to Test/Unit parser.
39
+ elsif ASSERT_VALUE_TEST_FRAMEWORK == :old_minitest and defined?(Test)
40
+ # Test/Unit from Ruby 1.9 has a strict option parser, need to explicitly add options there.
41
+ #
42
+ # Note, this works only for tests that use 'test/unit'. 'minitest/autorun' in old versions
43
+ # is not powerful enough to accept custom options. This is fixed in minitest 5.0.
20
44
  module Test::Unit
21
45
 
22
46
  module AssertValueOption
@@ -44,9 +68,10 @@ if RUBY_VERSION >= "1.9.0" and !defined?(Minitest) # minitest options are handl
44
68
 
45
69
  end
46
70
 
47
- else
71
+ elsif ASSERT_VALUE_TEST_FRAMEWORK == :test_unit
48
72
 
49
73
  # In Ruby 1.8 additional test options are simply passed via ARGV
74
+ # ruby test.rb -- --foo
50
75
  $assert_value_options << "--no-interactive" if ARGV.include?("--no-interactive")
51
76
  $assert_value_options << "--no-canonicalize" if ARGV.include?("--no-canonicalize")
52
77
  $assert_value_options << "--autoaccept" if ARGV.include?("--autoaccept")
@@ -265,28 +290,33 @@ module AssertValueAssertion
265
290
  private
266
291
 
267
292
  def succeed
268
- if RUBY_VERSION < "1.9.0"
269
- add_assertion
270
- else
271
- true
293
+ increment_assertion_count
294
+ true
295
+ end
296
+
297
+ def increment_assertion_count
298
+ case ASSERT_VALUE_TEST_FRAMEWORK
299
+ when :new_minitest then self.assertions += 1
300
+ when :old_minitest then self._assertions += 1
301
+ when :test_unit then add_assertion
272
302
  end
273
303
  end
274
304
 
275
305
  def soft_fail(diff)
276
- if RUBY_VERSION < "1.9.0"
277
- failure = Test::Unit::Failure.new(name, filter_backtrace(caller(0)), diff)
278
- puts "\n#{failure}"
279
- else
306
+ if [:new_minitest, :old_minitest].include?(ASSERT_VALUE_TEST_FRAMEWORK)
280
307
  failure = MiniTest::Assertion.new(diff)
281
- puts "\n#{failure}"
308
+ else
309
+ failure = Test::Unit::Failure.new(name, filter_backtrace(caller(0)), diff)
282
310
  end
311
+ puts "\n#{failure}"
283
312
  end
284
313
 
285
314
  def fail(diff)
286
- if RUBY_VERSION < "1.9.0"
287
- raise Test::Unit::AssertionFailedError.new(diff)
288
- else
315
+ increment_assertion_count
316
+ if [:new_minitest, :old_minitest].include?(ASSERT_VALUE_TEST_FRAMEWORK)
289
317
  raise MiniTest::Assertion.new(diff)
318
+ else
319
+ raise Test::Unit::AssertionFailedError.new(diff)
290
320
  end
291
321
  end
292
322
 
@@ -411,17 +441,15 @@ private
411
441
 
412
442
  end
413
443
 
414
- if RUBY_VERSION >= "1.9.0"
415
- if defined? Minitest::Test
416
- class Minitest::Test
417
- include AssertValueAssertion
418
- end
419
- else
420
- class MiniTest::Unit::TestCase
421
- include AssertValueAssertion
422
- end
444
+ if ASSERT_VALUE_TEST_FRAMEWORK == :new_minitest
445
+ class Minitest::Test
446
+ include AssertValueAssertion
423
447
  end
424
- else
448
+ elsif ASSERT_VALUE_TEST_FRAMEWORK == :old_minitest
449
+ class MiniTest::Unit::TestCase
450
+ include AssertValueAssertion
451
+ end
452
+ elsif ASSERT_VALUE_TEST_FRAMEWORK == :test_unit
425
453
  class Test::Unit::TestCase
426
454
  include AssertValueAssertion
427
455
  end
@@ -1,14 +1,10 @@
1
1
  # Copyright (c) 2011 Pluron, Inc.
2
2
 
3
- begin
4
- require 'minitest/autorun'
5
- rescue LoadError
6
- require 'test/unit'
7
- end
8
-
3
+ require 'test/unit'
4
+ # require 'minitest/autorun' # uncomment to test with minitest 5.x gem (enable it in Gemfile too)
9
5
  require 'assert_value'
10
6
 
11
- class AssertValueTest < ( defined?(Minitest) ? Minitest::Test : Test::Unit::TestCase )
7
+ class AssertValueTest < ASSERT_VALUE_TEST_FRAMEWORK == :new_minitest ? Minitest::Test : Test::Unit::TestCase
12
8
 
13
9
  def test_basic_assert_value
14
10
  assert_value "foo", <<-END
@@ -90,17 +86,3 @@ class AssertValueTest < ( defined?(Minitest) ? Minitest::Test : Test::Unit::Test
90
86
  end
91
87
 
92
88
  end
93
-
94
- if RUBY_VERSION >= "1.9.0"
95
-
96
- class AssertValueMiniTest < (defined?(Minitest) ? Minitest::Test : MiniTest::Unit::TestCase)
97
-
98
- def test_basic_assert_value
99
- assert_value "foo", <<-END
100
- foo
101
- END
102
- end
103
-
104
- end
105
-
106
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assert_value
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: '1.3'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-17 00:00:00.000000000 Z
12
+ date: 2014-05-13 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: assert_value assertion
15
15
  email: support@pluron.com
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  version: '0'
54
54
  requirements: []
55
55
  rubyforge_project:
56
- rubygems_version: 1.8.23
56
+ rubygems_version: 1.8.23.2
57
57
  signing_key:
58
58
  specification_version: 3
59
59
  summary: Assert that checks that two values (strings, expected and actual) are same