Sha256: 23dc49f6ef525bb023c276e56ee3a237384d2de7c16410e16a16fb73e319ba6b
Contents?: true
Size: 1.4 KB
Versions: 2
Compression:
Stored size: 1.4 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, :content def initialize(method, args = nil) @method = method.to_s @args = args end def matches?(content) @content = content (content =~ /#{method}#{args_expr}/m) != nil end def failure_message puts "Content: #{content}" if RSpec::Generator.debug? 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 puts "Content: #{content}" if RSpec::Generator.debug? 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
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
generator-spec-0.4.3 | lib/rspec_for_generators/matchers/content/have_call.rb |
generator-spec-0.4.2 | lib/rspec_for_generators/matchers/content/have_call.rb |