Skip to content

Instantly share code, notes, and snippets.

@skwp
Created December 7, 2013 00:44

Revisions

  1. skwp created this gist Dec 7, 2013.
    8 changes: 8 additions & 0 deletions dynamic_method_spec.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    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
    17 changes: 17 additions & 0 deletions grep_matcher.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    # 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)