lib/assert_value.rb in assert_value-1.5.3 vs lib/assert_value.rb in assert_value-1.5.4
- old
+ new
@@ -1,7 +1,6 @@
# Copyright (c) 2010-2015 Pluron, Inc.
-
# there're 4 types of test frameworks we support
# 1) Test::Unit from Ruby <= 1.8.7 and Ruby >= 2.2.2
# 2) Minitest 2.x-4.x, either bundled with Ruby 1.9 - 2.1 or installed via gem
# 3) Minitest > 5.0 bundles with Ruby >= 2.2.2 or installed via gem
# 4) RSpec
@@ -69,11 +68,11 @@
end
#Use this to raise internal error with a given message
#You can define your own method for your application
-unless defined? internal_error
+unless defined?(internal_error)
def internal_error(message = 'internal error')
raise message
end
end
@@ -188,11 +187,11 @@
# assert_value, run tests and they will fill expected values for you automatically
def assert_value(*args)
if block_given?
# rspec passes block to the expect() function, not to the matcher
# so string substitution should work as if assert_value is called with a string
- mode = @rspec_matcher ? :scalar : :block
+ mode = defined?(@rspec_matcher) ? :scalar : :block
expected = args[0]
actual = ""
begin
actual = yield.to_s
rescue Exception => e
@@ -210,11 +209,11 @@
elsif expected.class == String
change = :update_expected_string
elsif expected.class == Hash
raise ":log key is missing" unless expected.has_key? :log
log_file = expected[:log]
- if defined? RAILS_ROOT
+ if defined?(RAILS_ROOT)
log_file = File.expand_path(log_file, RAILS_ROOT)
else
log_file = File.expand_path(log_file, Dir.pwd)
end
expected = File.exist?(log_file) ? File.read(log_file) : ""
@@ -283,21 +282,23 @@
increment_assertion_count
true
end
def increment_assertion_count
- return if @rspec_matcher or self.class.name =~ /RSpec/
+ return if defined?(@rspec_matcher) or self.class.name =~ /RSpec/
case ASSERT_VALUE_TEST_FRAMEWORK
when :new_minitest then self.assertions += 1
when :old_minitest then self._assertions += 1
when :test_unit then add_assertion
end
end
def soft_fail(diff)
if [:new_minitest, :old_minitest].include?(ASSERT_VALUE_TEST_FRAMEWORK)
failure = MiniTest::Assertion.new(diff)
+ elsif [:rspec_only].include?(ASSERT_VALUE_TEST_FRAMEWORK)
+ failure = diff
else
failure = Test::Unit::Failure.new(name, filter_backtrace(caller(0)), diff)
end
puts "\n#{failure}"
end
@@ -313,11 +314,11 @@
# actual - actual value of the scalar or result of the executed block
# change - what to do with expected value (:create_expected_string or :update_expected_string)
# mode - describes signature of assert_value call by type of main argument (:block or :scalar)
def accept_string(actual, change, mode)
- depth = @rspec_matcher ? 6 : 3
- file, method, line = get_caller_location(:depth => depth)
+ depth = @rspec_matcher ? 8 : 3
+ file, _, line = get_caller_location(:depth => depth)
# read source file, construct the new source, replacing everything
# between "do" and "end" in assert_value's block
# using File::expand_path here because "file" can be either
# absolute path (when test is run with "rake test" runs)