Sha256: 91dd10ef829f364eb8e5b8f24aa2cb6c65028f44c9ed0f97a599599d4e3b4a14

Contents?: true

Size: 1.42 KB

Versions: 46

Compression:

Stored size: 1.42 KB

Contents

module ActiveSupport
  module Testing
    module Declarative

      def self.extended(klass) #:nodoc:
        klass.class_eval do

          unless method_defined?(:describe)
            def self.describe(text)
              if block_given?
                super
              else
                message = "`describe` without a block is deprecated, please switch to: `def self.name; #{text.inspect}; end`\n"
                ActiveSupport::Deprecation.warn message

                class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
                  def self.name
                    "#{text}"
                  end
                RUBY_EVAL
              end
            end
          end

        end
      end

      unless defined?(Spec)
        # Helper to define a test method using a String. Under the hood, it replaces
        # spaces with underscores and defines the test method.
        #
        #   test "verify something" do
        #     ...
        #   end
        def test(name, &block)
          test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
          defined = instance_method(test_name) rescue false
          raise "#{test_name} is already defined in #{self}" if defined
          if block_given?
            define_method(test_name, &block)
          else
            define_method(test_name) do
              flunk "No implementation provided for #{name}"
            end
          end
        end
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 4 rubygems

Version Path
activesupport-4.1.16 lib/active_support/testing/declarative.rb
activesupport-4.1.16.rc1 lib/active_support/testing/declarative.rb
activesupport-4.1.15 lib/active_support/testing/declarative.rb
activesupport-4.1.15.rc1 lib/active_support/testing/declarative.rb
activesupport-4.1.14.2 lib/active_support/testing/declarative.rb
activesupport-4.1.14.1 lib/active_support/testing/declarative.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/activesupport-4.1.13/lib/active_support/testing/declarative.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/activesupport-4.1.13/lib/active_support/testing/declarative.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/activesupport-4.1.13/lib/active_support/testing/declarative.rb
activesupport-4.1.14 lib/active_support/testing/declarative.rb
activesupport-4.1.14.rc2 lib/active_support/testing/declarative.rb
activesupport-4.1.14.rc1 lib/active_support/testing/declarative.rb
activesupport-4.1.13 lib/active_support/testing/declarative.rb
activesupport-4.1.13.rc1 lib/active_support/testing/declarative.rb
activesupport-4.1.12 lib/active_support/testing/declarative.rb
activesupport-4.1.12.rc1 lib/active_support/testing/declarative.rb
activesupport-4.1.11 lib/active_support/testing/declarative.rb
activesupport-4.1.10 lib/active_support/testing/declarative.rb
activesupport-4.1.10.rc4 lib/active_support/testing/declarative.rb
activesupport-4.1.10.rc3 lib/active_support/testing/declarative.rb