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

Methods

Included Modules

Spec::Plugins::MockFramework

Attributes

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

Public Class methods

[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

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 207
207:       def append_after(*args, &block)
208:         scope, options = scope_and_options(*args)
209:         parts = after_parts_from_scope(scope)
210:         parts << block
211:       end

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 189
189:       def append_before(*args, &block)
190:         scope, options = scope_and_options(*args)
191:         parts = before_parts_from_scope(scope)
192:         parts << block
193:       end
before(*args, &block)

Alias for append_before

context(*args, &example_group_block)

Alias for describe

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:         args << {} unless Hash === args.last
38:         if example_group_block
39:           params = args.last
40:           params[:spec_path] = eval("caller(0)[1]", example_group_block) unless params[:spec_path]
41:           if params[:shared]
42:             SharedExampleGroup.new(*args, &example_group_block)
43:           else
44:             self.subclass("Subclass") do
45:               describe(*args)
46:               module_eval(&example_group_block)
47:             end
48:           end
49:         else
50:           set_description(*args)
51:           before_eval
52:           self
53:         end
54:       end

[Source]

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

[Source]

     # File lib/spec/example/example_group_methods.rb, line 134
134:       def description
135:         result = ExampleGroupMethods.description_text(*description_parts)
136:         if result.nil? || result == ""
137:           return to_s
138:         else
139:           result
140:         end
141:       end

[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

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 106
106:       def it(description=nil, &implementation)
107:         e = new(description, &implementation)
108:         example_objects << e
109:         e
110:       end

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 59
59:       def it_should_behave_like(shared_example_group)
60:         case shared_example_group
61:         when SharedExampleGroup
62:           include shared_example_group
63:         else
64:           example_group = SharedExampleGroup.find_shared_example_group(shared_example_group)
65:           unless example_group
66:             raise RuntimeError.new("Shared Example Group '#{shared_example_group}' can not be found")
67:           end
68:           include(example_group)
69:         end
70:       end

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 100
100:       def predicate_matchers
101:         @predicate_matchers ||= {:an_instance_of => :is_a?}
102:       end

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 198
198:       def prepend_after(*args, &block)
199:         scope, options = scope_and_options(*args)
200:         parts = after_parts_from_scope(scope)
201:         parts.unshift(block)
202:       end

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 181
181:       def prepend_before(*args, &block)
182:         scope, options = scope_and_options(*args)
183:         parts = before_parts_from_scope(scope)
184:         parts.unshift(block)
185:       end

[Source]

     # File lib/spec/example/example_group_methods.rb, line 251
251:       def register(&registration_binding_block)
252:         @registration_binding_block = registration_binding_block
253:         rspec_options.add_example_group self
254:       end

[Source]

     # File lib/spec/example/example_group_methods.rb, line 260
260:       def registration_backtrace
261:         eval("caller", registration_binding_block.binding)
262:       end

[Source]

     # File lib/spec/example/example_group_methods.rb, line 213
213:       def remove_after(scope, &block)
214:         after_each_parts.delete(block)
215:       end

[Source]

     # File lib/spec/example/example_group_methods.rb, line 120
120:       def run
121:         examples = examples_to_run
122:         reporter.add_example_group(self)
123:         return true if examples.empty?
124:         return dry_run(examples) if dry_run?
125: 
126:         plugin_mock_framework
127:         define_methods_from_predicate_matchers
128: 
129:         success, before_all_instance_variables = run_before_all
130:         success, after_all_instance_variables  = execute_examples(success, before_all_instance_variables, examples)
131:         success                                = run_after_all(success, after_all_instance_variables)
132:       end

[Source]

     # File lib/spec/example/example_group_methods.rb, line 270
270:       def run_after_each(example)
271:         execute_in_class_hierarchy(:superclass_first) do |example_group|
272:           example.eval_each_fail_slow(example_group.after_each_parts)
273:         end
274:       end

[Source]

     # File lib/spec/example/example_group_methods.rb, line 264
264:       def run_before_each(example)
265:         execute_in_class_hierarchy do |example_group|
266:           example.eval_each_fail_fast(example_group.before_each_parts)
267:         end
268:       end

[Source]

     # File lib/spec/example/example_group_methods.rb, line 155
155:       def set_description(*args)
156:         args, options = args_and_options(*args)
157:         @description_args = args
158:         @description_options = options
159:         @description_text = ExampleGroupMethods.description_text(*args)
160:         @spec_path = File.expand_path(options[:spec_path]) if options[:spec_path]
161:         if described_type.class == Module
162:           @described_module = described_type
163:         end
164:         self
165:       end

Deprecated. Use before(:each)

[Source]

     # File lib/spec/example/example_group_methods.rb, line 218
218:       def setup(&block)
219:         before(:each, &block)
220:       end
specify(description=nil, &implementation)

Alias for it

Deprecated. Use after(:each)

[Source]

     # File lib/spec/example/example_group_methods.rb, line 223
223:       def teardown(&block)
224:         after(:each, &block)
225:       end

Use this to temporarily disable an example.

[Source]

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

Alias for xit

[Validate]