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

Methods

Included Modules

Spec::Plugins::MockFramework

Attributes

description_args  [R] 
description_text  [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 189
189:       def append_after(*args, &block)
190:         scope, options = scope_and_options(*args)
191:         parts = after_parts_from_scope(scope)
192:         parts << block
193:       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 171
171:       def append_before(*args, &block)
172:         scope, options = scope_and_options(*args)
173:         parts = before_parts_from_scope(scope)
174:         parts << block
175:       end
before(*args, &block)

Alias for append_before

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 35
35:       def describe(*args, &example_group_block)
36:         if example_group_block
37:           self.subclass("Subclass") do
38:             describe(*args)
39:             module_eval(&example_group_block)
40:           end
41:         else
42:           set_description(*args)
43:           before_eval
44:           self
45:         end
46:       end

[Source]

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

[Source]

     # File lib/spec/example/example_group_methods.rb, line 124
124:       def description
125:         ExampleGroupMethods.description_text(*description_parts)
126:       end

[Source]

    # File lib/spec/example/example_group_methods.rb, line 16
16:       def inherited(klass)
17:         super
18:         klass.register
19:       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 97
 97:       def it(description=nil, &implementation)
 98:         e = new(description, &implementation)
 99:         example_objects << e
100:         e
101:       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 50
50:       def it_should_behave_like(shared_example_group)
51:         case shared_example_group
52:         when SharedExampleGroup
53:           include shared_example_group
54:         else
55:           example_group = SharedExampleGroup.find_shared_example_group(shared_example_group)
56:           unless example_group
57:             raise RuntimeError.new("Shared Example Group '#{shared_example_group}' can not be found")
58:           end
59:           include(example_group)
60:         end
61:       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 91
91:       def predicate_matchers
92:         @predicate_matchers ||= {:an_instance_of => :is_a?}
93:       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 180
180:       def prepend_after(*args, &block)
181:         scope, options = scope_and_options(*args)
182:         parts = after_parts_from_scope(scope)
183:         parts.unshift(block)
184:       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 163
163:       def prepend_before(*args, &block)
164:         scope, options = scope_and_options(*args)
165:         parts = before_parts_from_scope(scope)
166:         parts.unshift(block)
167:       end

[Source]

     # File lib/spec/example/example_group_methods.rb, line 233
233:       def register
234:         rspec_options.add_example_group self
235:       end

[Source]

     # File lib/spec/example/example_group_methods.rb, line 195
195:       def remove_after(scope, &block)
196:         after_each_parts.delete(block)
197:       end

[Source]

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

[Source]

     # File lib/spec/example/example_group_methods.rb, line 247
247:       def run_after_each(example)
248:         execute_in_class_hierarchy(:superclass_first) do |example_group|
249:           example.eval_each_fail_slow(example_group.after_each_parts)
250:         end
251:       end

[Source]

     # File lib/spec/example/example_group_methods.rb, line 241
241:       def run_before_each(example)
242:         execute_in_class_hierarchy do |example_group|
243:           example.eval_each_fail_fast(example_group.before_each_parts)
244:         end
245:       end

[Source]

     # File lib/spec/example/example_group_methods.rb, line 140
140:       def set_description(*args)
141:         args, options = args_and_options(*args)
142:         @description_args = args
143:         @description_text = ExampleGroupMethods.description_text(*args)
144:         @spec_path = File.expand_path(options[:spec_path]) if options[:spec_path]
145:         if described_type.class == Module
146:           include described_type
147:         end
148:         self
149:       end

Deprecated. Use before(:each)

[Source]

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

Alias for it

Deprecated. Use after(:each)

[Source]

     # File lib/spec/example/example_group_methods.rb, line 205
205:       def teardown(&block)
206:         after(:each, &block)
207:       end

Use this to temporarily disable an example.

[Source]

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

[Validate]