Sha256: c0179acfce9f2ea4025ae97f1578f4ede20e50b3ad269bc66846d942999dccf5

Contents?: true

Size: 1.42 KB

Versions: 10

Compression:

Stored size: 1.42 KB

Contents

# Extracted from generator_spec https://github.com/stevehodgkiss/generator_spec
# But `RSpec::Rails::RailsExampleGroup` loads a truckload of things from rails and rspec-rails
# That we don't need.

module Generators
  module TestCase
    extend ActiveSupport::Concern
    include FileUtils

    included do
      cattr_accessor :test_case, :test_case_instance

      self.test_case = Class.new(Rails::Generators::TestCase) do
        def fake_test_case; end
        def add_assertion; end
      end
      self.test_case_instance = self.test_case.new(:fake_test_case)
      self.test_case.tests described_class

      before do
        prepare_destination
        create_routes
        run_generator
      end

      destination File.expand_path("../tmp", __FILE__)
    end

    module ClassMethods
      def tests(klass)
        self.test_case.generator_class = klass
      end

      def arguments(array)
        self.test_case.default_arguments = array
      end

      def destination(path)
        self.test_case.destination_root = path
      end
    end

    def file(relative)
      File.expand_path(relative, destination_root)
    end

    def method_missing(method_sym, *arguments, &block)
      self.test_case_instance.send(method_sym, *arguments, &block)
    end

    def respond_to?(method_sym, include_private = false)
      if self.test_case_instance.respond_to?(method_sym)
        true
      else
        super
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
stylus-1.0.0.beta spec/support/generators/test_case.rb
stylus-0.7.2 spec/support/generators/test_case.rb
stylus-0.7.1 spec/support/generators/test_case.rb
stylus-0.7.0 spec/support/generators/test_case.rb
stylus-0.6.2 spec/support/generators/test_case.rb
stylus-0.6.0 spec/support/generators/test_case.rb
stylus-0.5.1 spec/support/generators/test_case.rb
stylus-0.5.0 spec/support/generators/test_case.rb
stylus-0.4.2 spec/support/generators/test_case.rb
stylus-0.4.1 spec/support/generators/test_case.rb