Skip to content

Instantly share code, notes, and snippets.

@skwp
Created December 7, 2013 00:44
Show Gist options
  • Select an option

  • Save skwp/7835764 to your computer and use it in GitHub Desktop.

Select an option

Save skwp/7835764 to your computer and use it in GitHub Desktop.
Fail your build for user-defined style rules.
require 'spec/support/grep_matcher'
describe do
disallow_presence_of pattern: "send(.*#",
location: "app/",
description: "Do not use dynamic method invocations",
failure: "Please change dynamic method call to something more sane."
end
# Soon to be open sourced as a gem
module Reverb
module RSpec
module GrepMatcher
module ClassMethods
def disallow_presence_of(description:nil, pattern:nil, location:nil, failure:nil)
it(description) do
results = `grep -rn '#{pattern}' #{location}`
results.should eq(""), failure
end
end
end
end
end
end
RSpec::Core::ExampleGroup.extend(Reverb::RSpec::GrepMatcher::ClassMethods)
@ClayShentrup
Copy link
Copy Markdown

<3

@vassilevsky
Copy link
Copy Markdown

You can make these tests faster with https://github.com/ggreer/the_silver_searcher

@mezis
Copy link
Copy Markdown

mezis commented Dec 20, 2013

Or, simply, git grep.

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