- after
- append_after
- append_before
- before
- context
- 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
- xspecify
- Spec::Plugins::MockFramework
| [R] | description_args | |
| [R] | description_options | |
| [R] | description_text | |
| [R] | registration_binding_block | |
| [R] | spec_path |
[ show 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
Alias for prepend_after
Registers a block to be executed after each example. This method appends block to existing after blocks.
[ show source ]
# File lib/spec/example/example_group_methods.rb, line 205
205: def append_after(*args, &block)
206: scope, options = scope_and_options(*args)
207: parts = after_parts_from_scope(scope)
208: parts << block
209: end
Registers a block to be executed before each example. This method appends block to existing before blocks.
[ show source ]
# File lib/spec/example/example_group_methods.rb, line 187
187: def append_before(*args, &block)
188: scope, options = scope_and_options(*args)
189: parts = before_parts_from_scope(scope)
190: parts << block
191: end
Alias for append_before
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
[ show 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
[ show 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
[ show 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
[ show 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.
[ show 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.
[ show 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
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
[ show 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.
[ show source ]
# File lib/spec/example/example_group_methods.rb, line 196
196: def prepend_after(*args, &block)
197: scope, options = scope_and_options(*args)
198: parts = after_parts_from_scope(scope)
199: parts.unshift(block)
200: end
Registers a block to be executed before each example. This method prepends block to existing before blocks.
[ show source ]
# File lib/spec/example/example_group_methods.rb, line 179
179: def prepend_before(*args, &block)
180: scope, options = scope_and_options(*args)
181: parts = before_parts_from_scope(scope)
182: parts.unshift(block)
183: end
[ show source ]
# File lib/spec/example/example_group_methods.rb, line 249
249: def register(®istration_binding_block)
250: @registration_binding_block = registration_binding_block
251: rspec_options.add_example_group self
252: end
[ show source ]
# File lib/spec/example/example_group_methods.rb, line 258
258: def registration_backtrace
259: eval("caller", registration_binding_block.binding)
260: end
[ show source ]
# File lib/spec/example/example_group_methods.rb, line 211
211: def remove_after(scope, &block)
212: after_each_parts.delete(block)
213: end
[ show source ]
# File lib/spec/example/example_group_methods.rb, line 120
120: def run
121: examples = examples_to_run
122: return true if examples.empty?
123: reporter.add_example_group(self)
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
[ show source ]
# File lib/spec/example/example_group_methods.rb, line 268
268: def run_after_each(example)
269: execute_in_class_hierarchy(:superclass_first) do |example_group|
270: example.eval_each_fail_slow(example_group.after_each_parts)
271: end
272: end
[ show source ]
# File lib/spec/example/example_group_methods.rb, line 262
262: def run_before_each(example)
263: execute_in_class_hierarchy do |example_group|
264: example.eval_each_fail_fast(example_group.before_each_parts)
265: end
266: end
[ show 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: include described_type
163: end
164: self
165: end
Deprecated. Use before(:each)
[ show source ]
# File lib/spec/example/example_group_methods.rb, line 216
216: def setup(&block)
217: before(:each, &block)
218: end
Alias for it
Deprecated. Use after(:each)
[ show source ]
# File lib/spec/example/example_group_methods.rb, line 221
221: def teardown(&block)
222: after(:each, &block)
223: end
Use this to temporarily disable an example.
[ show 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
Alias for xit