Sha256: bc24162a13e84c2bfc8226100235060c5fc84cff0a6798b350fcbefbd403e368
Contents?: true
Size: 1.27 KB
Versions: 2
Compression:
Stored size: 1.27 KB
Contents
module RSpec::RubyContentMatchers class HaveSubclass attr_reader :klass, :superclass, :type, :content def initialize(klass, superclass, type=nil) @klass = klass.to_s.camelize @superclass = superclass.to_s.camelize @type = type.to_s.camelize if type end def matches?(content) @content = content match_res = (content =~ /class\s+#{klass}#{type}\s+<\s+#{superclass}(.*)end$/m) if block_given? && $1 ruby_content = $1.strip.extend(RSpec::RubyContent::Helpers) yield ruby_content else match_res end end def failure_message puts "Content: #{content}" if RSpec::Generator.debug? "Expected there to be the subclass #{klass} of #{superclass}" end def negative_failure_message puts "Content: #{content}" if RSpec::Generator.debug? "Did no expected there to be the subclass #{klass} of #{superclass}" end end def have_migration(klass, superclass, type=nil) HaveSubclass.new(klass, superclass, type) end def have_observer_class(klass) HaveSubclass.new(klass, 'ActiveRecord::Observer', :observer) end def have_migration(klass) HaveSubclass.new(klass, 'ActiveRecord::Migration') 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_subclass.rb |
generator-spec-0.4.2 | lib/rspec_for_generators/matchers/content/have_subclass.rb |