Skip to content

Instantly share code, notes, and snippets.

@jonatas
Last active March 2, 2020 03:51
Show Gist options
  • Save jonatas/c1e580dcb74e20d4f2df4632ceb084ef to your computer and use it in GitHub Desktop.
Save jonatas/c1e580dcb74e20d4f2df4632ceb084ef to your computer and use it in GitHub Desktop.
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'ffast',
git: 'https://github.com/jonatas/fast.git',
require: 'fast'
end
Fast.class_eval do
# Captures class and method name when find syntax like:
# `allow(...).to receive(...)` that does not end with `.with(...)`
pattern_with_captures = <<~FAST
(send (send nil allow (const nil $_)) to
(send (send nil receive (sym $_)) !with))
FAST
pattern = expression(pattern_with_captures.tr('$',''))
ruby_files_from('spec').each do |file|
results = search_file(pattern, file) || [] rescue next
results.each do |n|
clazz, method = capture(n, pattern_with_captures)
if klazz = Object.const_get(clazz.to_s) rescue nil
if klazz.respond_to?(method)
params = klazz.method(method).parameters
if params.any?{|e|e.first == :req}
code = n.loc.expression
range = [code.first_line, code.last_line].uniq.join(",")
boom_message = "💥 #{clazz}.#{method} does not include the parameters!"
puts boom_message, "#{file}:#{range}", code.source
end
end
end
end
end
end
@jonatas
Copy link
Author

jonatas commented Mar 2, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment