Module: Suggest::Mixin
- Defined in:
- lib/suggest.rb
Instance Method Summary collapse
- #what_mutates?(expected, args: [], allow_not_public: false, **opts, &block) ⇒ Boolean
- #what_returns?(expected, args: [], allow_mutation: false, allow_not_public: false, &block) ⇒ Boolean
Instance Method Details
#what_mutates?(expected, args: [], allow_not_public: false, **opts, &block) ⇒ Boolean
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/suggest.rb', line 77 def what_mutates?(expected, args: [], allow_not_public: false, **opts, &block) methods.map(&method(:method)).select(&SELECTOR).select do |m| arity = m.arity next unless arity < 0 || arity == args.count post = clone next if block && UNSAFE_WITH_BLOCK.include?([m.owner, m.name]) result = post.__send__(allow_not_public ? :send : :public_send, m.name, *args, &block) rescue next next if opts.key?(:returns) && !Suggest.eq?(result, opts[:returns]) Suggest.eq?(post, expected) end.map(&:name) end |
#what_returns?(expected, args: [], allow_mutation: false, allow_not_public: false, &block) ⇒ Boolean
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/suggest.rb', line 57 def what_returns?(expected, args: [], allow_mutation: false, allow_not_public: false, &block) methods.map(&method(:method)).select(&SELECTOR).select do |m| arity = m.arity next unless arity < 0 || arity == args.count post = clone next if block && UNSAFE_WITH_BLOCK.include?([m.owner, m.name]) result = post.__send__(allow_not_public ? :send : :public_send, m.name, *args, &block) rescue next next unless allow_mutation || self == post if expected.is_a?(Proc) && expected.lambda? expected.call(result) rescue false else Suggest.eq?(result, expected) end end.map(&:name) end |