Sha256: 53c30b8cb6bfd1bb19bd49a1334d4b5f62e658c5890d69ccaf9abe7350cfc5b1

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 KB

Contents

# This method manipulates the given path and tries to find any migration which
# matches the migration name. For example, the call above is converted to:
#
#   generator.should generate_migration "db/migrate/003_create_products.rb"
#
# Consequently it accepts the same arguments as the matcher have_file.

module RSpec
  module FileMatchers
    class GenerateMigration

      def initialize(relative)
        @relative = relative      
      end

      def matches?(generator)      
        migration_file_name(relative, generator)        
      end          
    
      def failure_message
        "Expected migration #{relative} to have been generated, but it was not"
      end

      def negative_failure_message
        "Did not expect migration #{relative} to have been generated, but it was"
      end
      
      protected
      
      def migration_file_name(relative, generator) #:nodoc:
        absolute = File.expand_path(relative, generator.class.destination_root)
        dirname, file_name = File.dirname(absolute), File.basename(absolute).sub(/\.rb$/, '')
        Dir.glob("#{dirname}/[0-9]*_*.rb").grep(/\d+_#{file_name}.rb$/).first
      end
      
    end
  
    def generate_migration(relative)
      GenerateMigration.new(relative)
    end

  end   
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rspec_for_generators-0.3.1 lib/rspec_for_generators/matchers/file/generate_migration.rb
rspec_for_generators-0.3.0 lib/rspec_for_generators/matchers/file/generate_migration.rb
rspec_for_generators-0.2.1 lib/rspec_for_generators/matchers/file/generate_migration.rb
rspec_for_generators-0.2.0 lib/rspec_for_generators/matchers/file/generate_migration.rb