Module: RSpec::Mocks::Methods
- Defined in:
- lib/what_the/rspec_mocks_validation.rb
Instance Method Summary collapse
- #should_not_receive_with_validation(sym, &block) ⇒ Object
- #should_receive_with_validation(sym, opts = {}, &block) ⇒ Object
- #stub_with_validation(sym_or_hash, opts = {}, &block) ⇒ Object
- #validate_method_exists(method_name) ⇒ Object
Instance Method Details
#should_not_receive_with_validation(sym, &block) ⇒ Object
16 17 18 19 |
# File 'lib/what_the/rspec_mocks_validation.rb', line 16 def should_not_receive_with_validation(sym, &block) validate_method_exists(sym) should_not_receive_without_validation(sym, &block) end |
#should_receive_with_validation(sym, opts = {}, &block) ⇒ Object
11 12 13 14 |
# File 'lib/what_the/rspec_mocks_validation.rb', line 11 def should_receive_with_validation(sym, opts={}, &block) validate_method_exists(sym) should_receive_without_validation(sym, opts, &block) end |
#stub_with_validation(sym_or_hash, opts = {}, &block) ⇒ Object
21 22 23 24 |
# File 'lib/what_the/rspec_mocks_validation.rb', line 21 def stub_with_validation(sym_or_hash, opts={}, &block) validate_method_exists(sym_or_hash) unless sym_or_hash.instance_of?(Hash) stub_without_validation(sym_or_hash, opts, &block) end |
#validate_method_exists(method_name) ⇒ Object
6 7 8 9 |
# File 'lib/what_the/rspec_mocks_validation.rb', line 6 def validate_method_exists(method_name) return if self.is_a?(RSpec::Mocks::Mock) raise "Attempted to stub #{method_name} which doesn't exist on #{self}" unless self.respond_to?(method_name.to_sym) end |