Class: RSpec::Mocks::ErrorGenerator
- Inherits:
-
Object
- Object
- RSpec::Mocks::ErrorGenerator
- Defined in:
- lib/rspec/mocks/error_generator.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#initialize(target, name, options = {}) ⇒ ErrorGenerator
constructor
A new instance of ErrorGenerator.
- #raise_block_failed_error(sym, detail) ⇒ Object
- #raise_expectation_error(sym, expected_received_count, actual_received_count, *args) ⇒ Object
- #raise_missing_block_error(args_to_yield) ⇒ Object
- #raise_out_of_order_error(sym) ⇒ Object
- #raise_similar_message_args_error(expectation, *args) ⇒ Object
- #raise_unexpected_message_args_error(expectation, *args) ⇒ Object
- #raise_unexpected_message_error(sym, *args) ⇒ Object
- #raise_wrong_arity_error(args_to_yield, arity) ⇒ Object
Constructor Details
#initialize(target, name, options = {}) ⇒ ErrorGenerator
Returns a new instance of ErrorGenerator.
6 7 8 9 10 |
# File 'lib/rspec/mocks/error_generator.rb', line 6 def initialize(target, name, ={}) @declared_as = [:__declared_as] || 'Mock' @target = target @name = name end |
Instance Attribute Details
#opts ⇒ Object
12 13 14 |
# File 'lib/rspec/mocks/error_generator.rb', line 12 def opts @opts ||= {} end |
Instance Method Details
#raise_block_failed_error(sym, detail) ⇒ Object
40 41 42 |
# File 'lib/rspec/mocks/error_generator.rb', line 40 def raise_block_failed_error(sym, detail) __raise "#{intro} received :#{sym} but passed block failed with: #{detail}" end |
#raise_expectation_error(sym, expected_received_count, actual_received_count, *args) ⇒ Object
32 33 34 |
# File 'lib/rspec/mocks/error_generator.rb', line 32 def raise_expectation_error(sym, expected_received_count, actual_received_count, *args) __raise "(#{intro}).#{sym}#{format_args(*args)}\n expected: #{(expected_received_count)}\n received: #{(actual_received_count)}" end |
#raise_missing_block_error(args_to_yield) ⇒ Object
44 45 46 |
# File 'lib/rspec/mocks/error_generator.rb', line 44 def raise_missing_block_error(args_to_yield) __raise "#{intro} asked to yield |#{arg_list(*args_to_yield)}| but no block was passed" end |
#raise_out_of_order_error(sym) ⇒ Object
36 37 38 |
# File 'lib/rspec/mocks/error_generator.rb', line 36 def raise_out_of_order_error(sym) __raise "#{intro} received :#{sym} out of order" end |
#raise_similar_message_args_error(expectation, *args) ⇒ Object
26 27 28 29 30 |
# File 'lib/rspec/mocks/error_generator.rb', line 26 def (expectation, *args) expected_args = format_args(*expectation.expected_args) actual_args = args.collect {|a| format_args(*a)}.join(", ") __raise "#{intro} received #{expectation.sym.inspect} with unexpected arguments\n expected: #{expected_args}\n got: #{actual_args}" end |
#raise_unexpected_message_args_error(expectation, *args) ⇒ Object
20 21 22 23 24 |
# File 'lib/rspec/mocks/error_generator.rb', line 20 def (expectation, *args) expected_args = format_args(*expectation.expected_args) actual_args = format_args(*args) __raise "#{intro} received #{expectation.sym.inspect} with unexpected arguments\n expected: #{expected_args}\n got: #{actual_args}" end |
#raise_unexpected_message_error(sym, *args) ⇒ Object
16 17 18 |
# File 'lib/rspec/mocks/error_generator.rb', line 16 def (sym, *args) __raise "#{intro} received unexpected message :#{sym}#{(*args)}" end |
#raise_wrong_arity_error(args_to_yield, arity) ⇒ Object
48 49 50 |
# File 'lib/rspec/mocks/error_generator.rb', line 48 def raise_wrong_arity_error(args_to_yield, arity) __raise "#{intro} yielded |#{arg_list(*args_to_yield)}| to block with arity of #{arity}" end |