spec/helpers.rb in convolver-0.3.1 vs spec/helpers.rb in convolver-0.3.2
- old
+ new
@@ -1,21 +1,24 @@
# convolver/spec/helpers.rb
+require 'coveralls'
+
+Coveralls.wear!
+
require 'convolver'
-require 'mocha/api'
# Matcher compares NArrays numerically
-RSpec::Matchers.define :be_narray_like do |expected_narray|
+RSpec::Matchers.define :be_narray_like do |expected_narray, mse = 1e-9|
match do |given|
@error = nil
if ! given.is_a?(NArray)
@error = "Wrong class."
elsif given.shape != expected_narray.shape
@error = "Shapes are different."
else
d = given - expected_narray
difference = ( d * d ).sum / d.size
- if difference > 1e-9
+ if difference > mse
@error = "Numerical difference with mean square error #{difference}"
end
end
@given = given.clone
@@ -24,16 +27,16 @@
end
! @error
end
- failure_message_for_should do
+ failure_message do
"NArray does not match supplied example. #{@error}
Expected: #{@expected.inspect}
Got: #{@given.inspect}"
end
- failure_message_for_should_not do
+ failure_message_when_negated do
"NArray is too close to unwanted example.
Unwanted: #{@given.inspect}"
end
description do |given, expected|