Module Spec::Example::ExampleGroupMethods

  1. lib/spec/example/example_group_methods.rb

Attributes

location [R]
matcher_class [RW]

Public class methods

build_description_from (*args)
[show source]
# File lib/spec/example/example_group_methods.rb, line 8
        def build_description_from(*args)
          text = args.inject("") do |description, arg|
            description << " " unless (description == "" || arg.to_s =~ /^(\s|\.|#)/)
            description << arg.to_s
          end
          text == "" ? nil : text
        end

Public instance methods

context (*args, &example_group_block)

Alias for describe

describe (*args, &example_group_block)

Makes the describe/it syntax available from a class. For example:

class StackSpec < Spec::ExampleGroup
  describe Stack, "with no elements"

  before
    @stack = Stack.new
  end

  it "should raise on pop" do
    lambda{ @stack.pop }.should raise_error
  end
end
[show source]
# File lib/spec/example/example_group_methods.rb, line 47
      def describe(*args, &example_group_block)
        raise Spec::Example::NoDescriptionError.new("example group", caller(0)[1]) if args.empty?
        if example_group_block
          options = add_options(args)
          set_location(options, caller(0)[1])
          if options[:shared]
            ExampleGroupFactory.create_shared_example_group(*args, &example_group_block)
          else
            subclass(*args, &example_group_block)
          end
        else
          set_description(*args)
        end
      end
described_class ()
[show source]
# File lib/spec/example/example_group_methods.rb, line 126
      def described_class
        @described_class ||= Class === described_type ? described_type : nil
      end
described_type ()
[show source]
# File lib/spec/example/example_group_methods.rb, line 122
      def described_type
        @described_type ||= description_parts.reverse.find {|part| part.is_a?(Module)}
      end
description ()
[show source]
# File lib/spec/example/example_group_methods.rb, line 118
      def description
        @description ||= ExampleGroupMethods.build_description_from(*description_parts) || to_s
      end
description_args ()
[show source]
# File lib/spec/example/example_group_methods.rb, line 130
      def description_args
        @description_args ||= []
      end
example (description=nil, options={}, backtrace=nil, &implementation)

Creates an instance of the current example group class and adds it to a collection of examples of the current example group.

[show source]
# File lib/spec/example/example_group_methods.rb, line 72
      def example(description=nil, options={}, backtrace=nil, &implementation)
        example_proxy = ExampleProxy.new(description, options, backtrace || caller(0)[1])
        example_proxies << example_proxy
        example_implementations[example_proxy] = implementation || pending_implementation
        example_proxy
      end
example_group_hierarchy ()
[show source]
# File lib/spec/example/example_group_methods.rb, line 156
      def example_group_hierarchy
        @example_group_hierarchy ||= ExampleGroupHierarchy.new(self)
      end
include_constants_in (mod)
[show source]
# File lib/spec/example/example_group_methods.rb, line 164
      def include_constants_in(mod)
        include mod if (Spec::Ruby.version.to_f >= 1.9) & (Module === mod) & !(Class === mod)
      end
it (description=nil, options={}, backtrace=nil, &implementation)

Alias for example

it_should_behave_like (*shared_example_groups)

Use this to pull in examples from shared example groups.

[show source]
# File lib/spec/example/example_group_methods.rb, line 64
      def it_should_behave_like(*shared_example_groups)
        shared_example_groups.each do |group|
          include_shared_example_group(group)
        end
      end
let (name, &block)
[show source]
# File lib/spec/example/example_group_methods.rb, line 168
      def let(name, &block)
        define_method name do
          @assignments ||= {}
          @assignments[name] ||= instance_eval(&block)
        end
      end
nested_descriptions ()
[show source]
# File lib/spec/example/example_group_methods.rb, line 160
      def nested_descriptions
        example_group_hierarchy.nested_descriptions
      end
pending_implementation ()
[show source]
# File lib/spec/example/example_group_methods.rb, line 79
      def pending_implementation
        lambda { raise(Spec::Example::NotYetImplementedError) }
      end
run (run_options)
[show source]
# File lib/spec/example/example_group_methods.rb, line 94
      def run(run_options)
        examples = examples_to_run(run_options)
        notify(run_options.reporter) unless examples.empty?
        return true if examples.empty?
        return dry_run(examples, run_options) if run_options.dry_run?

        define_methods_from_predicate_matchers

        success, before_all_instance_variables = run_before_all(run_options)
        success, after_all_instance_variables  = run_examples(success, before_all_instance_variables, examples, run_options)
        success                                = run_after_all(success, after_all_instance_variables, run_options)
      end
set_description (*args)
[show source]
# File lib/spec/example/example_group_methods.rb, line 107
      def set_description(*args)
        @description_args, @options = args_and_options(*args)
        @backtrace = caller(1)
        @location = File.expand_path(options[:location]) if options[:location]
        self
      end
specify (description=nil, options={}, backtrace=nil, &implementation)

Alias for example

xexample (description=nil, opts={}, &block)

Use this to temporarily disable an example.

[show source]
# File lib/spec/example/example_group_methods.rb, line 87
      def xexample(description=nil, opts={}, &block)
        Kernel.warn("Example disabled: #{description}")
      end
xit (description=nil, opts={}, &block)

Alias for xexample

xspecify (description=nil, opts={}, &block)

Alias for xexample