# This method tries to see if a specific method is contained in the generated file. # It can operate (should) on either a file name or the raw content # # generated_file_name.should have_method "hello" # 'my/path/say_hello.rb'.should have_method "hello" # # say_hello_file_content.should have_method "hello" # module RSpec::RubyContentMatchers class HaveCall < RSpec::RubyContentMatcher attr_reader :method, :args def initialize(method, args = nil) @method = method.to_s @args = args end def matches?(content) super (content =~ /#{method}#{args_expr}/m) != nil end def failure_message super return "Expected there to be a call to #{method} with args #{args}, but there wasn't" if args "Expected there to be a call to #{method}, but there wasn't" end def negative_failure_message super return "Did not expect there to be a call to #{method} with args #{args}, but there was" if args "Did not expect there to be a call to #{method}, but there was" end protected def args_expr args ? "\s+(\()?\s*#{args}\s*(\))?" : '' end end def have_call(method, args = nil) HaveCall.new(method, args) end end