Module: Spec::Example::ExampleGroupMethods

Module | Spec::Example::ExampleGroupMethods
In: | lib/spec/example/example_group_methods.rb

### Methods

after append_after append_before before describe described_type description description_text inherited it it_should_behave_like predicate_matchers prepend_after prepend_before register registration_backtrace remove_after run run_after_each run_before_each set_description setup specify teardown xit

### Included Modules

Spec::Plugins::MockFramework

### Attributes

description_args | [R] |
description_options | [R] |
description_text | [R] |
registration_binding_block | [R] |
spec_path | [R] |

### Public Class methods

description_text(*args)

[Source]

        # File lib/spec/example/example_group_methods.rb, line 6
     6:         def description_text(*args)
     7:           args.inject("") do |result, arg|
     8:             result << " " unless (result == "" || arg.to_s =~ /^(\s|\.|#)/)
     9:             result << arg.to_s
    10:           end
    11:         end

### Public Instance methods

after(*args, &block)

Alias for prepend_after

append_after(*args, &block)

Registers a block to be executed after each example. This method appends `block` to existing after blocks.

[Source]

         # File lib/spec/example/example_group_methods.rb, line 196
    196:       def append_after(*args, &block)
    197:         scope, options = scope_and_options(*args)
    198:         parts = after_parts_from_scope(scope)
    199:         parts << block
    200:       end

append_before(*args, &block)

Registers a block to be executed before each example. This method appends `block` to existing before blocks.

[Source]

         # File lib/spec/example/example_group_methods.rb, line 178
    178:       def append_before(*args, &block)
    179:         scope, options = scope_and_options(*args)
    180:         parts = before_parts_from_scope(scope)
    181:         parts << block
    182:       end

before(*args, &block)

Alias for append_before

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

[Source]

        # File lib/spec/example/example_group_methods.rb, line 36
    36:       def describe(*args, &example_group_block)
    37:         if example_group_block
    38:           self.subclass("Subclass") do
    39:             describe(*args)
    40:             module_eval(&example_group_block)
    41:           end
    42:         else
    43:           set_description(*args)
    44:           before_eval
    45:           self
    46:         end
    47:       end

described_type()

[Source]

         # File lib/spec/example/example_group_methods.rb, line 134
    134:       def described_type
    135:         description_parts.find {|part| part.is_a?(Module)}
    136:       end

description()

[Source]

         # File lib/spec/example/example_group_methods.rb, line 125
    125:       def description
    126:         result = ExampleGroupMethods.description_text(*description_parts)
    127:         if result.nil? || result == ""
    128:           return to_s
    129:         else
    130:           result
    131:         end
    132:       end

inherited(klass)

[Source]

        # File lib/spec/example/example_group_methods.rb, line 16
    16:       def inherited(klass)
    17:         super
    18:         klass.register {}
    19:         Spec::Runner.register_at_exit_hook
    20:       end

it(description=nil, &implementation)

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

[Source]

         # File lib/spec/example/example_group_methods.rb, line 98
     98:       def it(description=nil, &implementation)
     99:         e = new(description, &implementation)
    100:         example_objects << e
    101:         e
    102:       end

it_should_behave_like(shared_example_group)

Use this to pull in examples from shared example groups. See Spec::Runner for information about shared example groups.

[Source]

        # File lib/spec/example/example_group_methods.rb, line 51
    51:       def it_should_behave_like(shared_example_group)
    52:         case shared_example_group
    53:         when SharedExampleGroup
    54:           include shared_example_group
    55:         else
    56:           example_group = SharedExampleGroup.find_shared_example_group(shared_example_group)
    57:           unless example_group
    58:             raise RuntimeError.new("Shared Example Group '#{shared_example_group}' can not be found")
    59:           end
    60:           include(example_group)
    61:         end
    62:       end

predicate_matchers[matcher_name] = method_on_object
predicate_matchers[matcher_name] = [method1_on_object, method2_on_object]

Dynamically generates a custom matcher that will match a predicate on your class. RSpec provides a couple of these out of the box:

      exist (or state expectations)
        File.should exist("path/to/file")

      an_instance_of (for mock argument constraints)
        mock.should_receive(:message).with(an_instance_of(String))

## Examples

      class Fish
        def can_swim?
          true
        end
      end

      describe Fish do
        predicate_matchers[:swim] = :can_swim?
        it "should swim" do
          Fish.new.should swim
        end
      end

[Source]

        # File lib/spec/example/example_group_methods.rb, line 92
    92:       def predicate_matchers
    93:         @predicate_matchers ||= {:an_instance_of => :is_a?}
    94:       end

prepend_after(*args, &block)

Registers a block to be executed after each example. This method prepends `block` to existing after blocks.

[Source]

         # File lib/spec/example/example_group_methods.rb, line 187
    187:       def prepend_after(*args, &block)
    188:         scope, options = scope_and_options(*args)
    189:         parts = after_parts_from_scope(scope)
    190:         parts.unshift(block)
    191:       end

prepend_before(*args, &block)

Registers a block to be executed before each example. This method prepends `block` to existing before blocks.

[Source]

         # File lib/spec/example/example_group_methods.rb, line 170
    170:       def prepend_before(*args, &block)
    171:         scope, options = scope_and_options(*args)
    172:         parts = before_parts_from_scope(scope)
    173:         parts.unshift(block)
    174:       end

register(&registration_binding_block)

[Source]

         # File lib/spec/example/example_group_methods.rb, line 240
    240:       def register(&registration_binding_block)
    241:         @registration_binding_block = registration_binding_block
    242:         rspec_options.add_example_group self
    243:       end

registration_backtrace()

[Source]

         # File lib/spec/example/example_group_methods.rb, line 249
    249:       def registration_backtrace
    250:         eval("caller", registration_binding_block.binding)
    251:       end

remove_after(scope, &block)

[Source]

         # File lib/spec/example/example_group_methods.rb, line 202
    202:       def remove_after(scope, &block)
    203:         after_each_parts.delete(block)
    204:       end

run()

[Source]

         # File lib/spec/example/example_group_methods.rb, line 111
    111:       def run
    112:         examples = examples_to_run
    113:         return true if examples.empty?
    114:         reporter.add_example_group(self)
    115:         return dry_run(examples) if dry_run?
    116:
    117:         plugin_mock_framework
    118:         define_methods_from_predicate_matchers
    119:
    120:         success, before_all_instance_variables = run_before_all
    121:         success, after_all_instance_variables  = execute_examples(success, before_all_instance_variables, examples)
    122:         success                                = run_after_all(success, after_all_instance_variables)
    123:       end

run_after_each(example)

[Source]

         # File lib/spec/example/example_group_methods.rb, line 259
    259:       def run_after_each(example)
    260:         execute_in_class_hierarchy(:superclass_first) do |example_group|
    261:           example.eval_each_fail_slow(example_group.after_each_parts)
    262:         end
    263:       end

run_before_each(example)

[Source]

         # File lib/spec/example/example_group_methods.rb, line 253
    253:       def run_before_each(example)
    254:         execute_in_class_hierarchy do |example_group|
    255:           example.eval_each_fail_fast(example_group.before_each_parts)
    256:         end
    257:       end

set_description(*args)

[Source]

         # File lib/spec/example/example_group_methods.rb, line 146
    146:       def set_description(*args)
    147:         args, options = args_and_options(*args)
    148:         @description_args = args
    149:         @description_options = options
    150:         @description_text = ExampleGroupMethods.description_text(*args)
    151:         @spec_path = File.expand_path(options[:spec_path]) if options[:spec_path]
    152:         if described_type.class == Module
    153:           include described_type
    154:         end
    155:         self
    156:       end

setup(&block)

Deprecated. Use before(:each)

[Source]

         # File lib/spec/example/example_group_methods.rb, line 207
    207:       def setup(&block)
    208:         before(:each, &block)
    209:       end

specify(description=nil, &implementation)

Alias for it

teardown(&block)

Deprecated. Use after(:each)

[Source]

         # File lib/spec/example/example_group_methods.rb, line 212
    212:       def teardown(&block)
    213:         after(:each, &block)
    214:       end

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

Use this to temporarily disable an example.

[Source]

         # File lib/spec/example/example_group_methods.rb, line 107
    107:       def xit(description=nil, opts={}, &block)
    108:         Kernel.warn("Example disabled: #{description}")
    109:       end

[Validate]