Module: Suggest::Mixin
- Defined in:
- lib/suggest.rb
Instance Method Summary collapse
- #what_mutates?(expected, opts = {}) ⇒ Boolean
- #what_returns?(expected, args: [], allow_mutation: false) ⇒ Boolean
Instance Method Details
#what_mutates?(expected, opts = {}) ⇒ Boolean
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/suggest.rb', line 78 def what_mutates?(expected, opts = {}) args = opts[:args] || [] block = Proc.new if block_given? applicable_methods = self.methods.map(&method(:method)).select do |m| SUGGEST_MODS.include?(m.owner) && !INCONSISTENT.include?([m.owner, m.name]) && !TOO_COMPLICATED.include?([m.owner, m.name]) end applicable_methods.select do |m| arity = m.arity next unless arity == -1 || arity == args.count post = clone if block next if UNSAFE_WITH_BLOCK.include?([m.owner, m.name]) result = post.public_send(m.name, *args, &block) rescue next else result = post.public_send(m.name, *args) rescue next end if opts.key?(:returns) next unless Suggest.eq?(result, opts[:returns]) end Suggest.eq?(post, expected) end.map(&:name) end |
#what_returns?(expected, args: [], allow_mutation: false) ⇒ Boolean
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/suggest.rb', line 51 def what_returns?(expected, args: [], allow_mutation: false) block = Proc.new if block_given? applicable_methods = self.methods.map(&method(:method)).select do |m| SUGGEST_MODS.include?(m.owner) && !INCONSISTENT.include?([m.owner, m.name]) && !TOO_COMPLICATED.include?([m.owner, m.name]) end applicable_methods.select do |m| arity = m.arity next unless arity == -1 || arity == args.count post = clone if block next if UNSAFE_WITH_BLOCK.include?([m.owner, m.name]) result = post.public_send(m.name, *args, &block) rescue next else result = post.public_send(m.name, *args) rescue next end next unless allow_mutation || self == post Suggest.eq?(result, expected) end.map(&:name) end |