Sha256: de09eacbda780957277ce0ee4643fb95d49190178232c09c911d64d4909eaaba
Contents?: true
Size: 1.11 KB
Versions: 2
Compression:
Stored size: 1.11 KB
Contents
module RSpec::RubyContentMatchers class HaveSubclass attr_reader :klass, :superclass, :type 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) 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 "Expected there to be the subclass #{klass} of #{superclass}" end def negative_failure_message "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.1 | lib/rspec_for_generators/matchers/content/have_subclass.rb |
generator-spec-0.4.0 | lib/rspec_for_generators/matchers/content/have_subclass.rb |