Sha256: 5c2a2a58ff1b5de6e14d792f9dca67683867e675828e3e1119cb627973b451cf
Contents?: true
Size: 1.23 KB
Versions: 1
Compression:
Stored size: 1.23 KB
Contents
# 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 attr_reader :method, :args def initialize(method, args = nil) @method = method.to_s @args = args end def matches?(content) content =~ /#{method}\s+#{args_expr}/m end def failure_message return "Expected there to be the call to #{method} with args #{args}, but there wasn't" if args "Expected there to be the call to #{method}, but there wasn't" end def negative_failure_message return "Did not expect there to be the call to #{method} with args #{args}, but there was" if args "Did not expect there to be the call to #{method}, but there was" end protected def args_expr args ? "\(?\s*#{args}\s*\)?\s+" : '' end end def have_call(method, args = nil) HaveCall.new(method, args) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
generator-spec-0.3.3 | lib/rspec_for_generators/matchers/content/have_call.rb |