class Facon::ErrorGenerator
A helper class for generating errors for expectation errors on mocks.
Public Class Methods
new(target, name)
click to toggle source
# File lib/facon/error_generator.rb, line 4 def initialize(target, name) @target, @name = target, name end
Public Instance Methods
raise_block_failed_error(method, exception_message)
click to toggle source
# File lib/facon/error_generator.rb, line 22 def raise_block_failed_error(method, exception_message) message = "#{target_name} received :#{method} but passed block failed with: #{exception_message}" raise(Facon::MockExpectationError, message) end
raise_expectation_error(expectation)
click to toggle source
# File lib/facon/error_generator.rb, line 8 def raise_expectation_error(expectation) message = "#{target_name} expected :#{expectation.method} with #{format_args(*expectation.argument_expectation)} #{format_count(expectation.expected_received_count)}, but received it #{format_count(expectation.actual_received_count)}" raise(Facon::MockExpectationError, message) end
raise_unexpected_message_args_error(expectation, *args)
click to toggle source
# File lib/facon/error_generator.rb, line 17 def raise_unexpected_message_args_error(expectation, *args) message = "#{target_name} expected :#{expectation.method} with #{format_args(*expectation.argument_expectation)}, but received it with #{format_args(*args)}" raise(Facon::MockExpectationError, message) end
raise_unexpected_message_error(method, *args)
click to toggle source
# File lib/facon/error_generator.rb, line 13 def raise_unexpected_message_error(method, *args) raise(Facon::MockExpectationError, "#{target_name} received unexpected message :#{method} with #{format_args(*args)}") end
Private Instance Methods
format_args(*args)
click to toggle source
# File lib/facon/error_generator.rb, line 32 def format_args(*args) return '(no args)' if args.empty? return '(any args)' if args == [:any] "(#{args.map { |a| a.inspect }.join(', ')})" end
format_count(count)
click to toggle source
# File lib/facon/error_generator.rb, line 38 def format_count(count) count == 1 ? '1 time' : "#{count} times" end
target_name()
click to toggle source
# File lib/facon/error_generator.rb, line 28 def target_name @name ? "Mock '#{@name}'" : @target.inspect end