Module: Spec::Example::ExampleGroupMethods
- Included in:
- ExampleGroup, SharedExampleGroup, Test::Unit::TestCase
- Defined in:
- lib/spec/example/example_group_methods.rb
Class Attribute Summary collapse
-
.matcher_class ⇒ Object
Returns the value of attribute matcher_class.
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#spec_path ⇒ Object
readonly
Returns the value of attribute spec_path.
Instance Method Summary collapse
-
#backtrace ⇒ Object
Provides the backtrace up to where this example_group was declared.
-
#describe(*args, &example_group_block) ⇒ Object
(also: #context)
Makes the describe/it syntax available from a class.
- #described_class ⇒ Object
- #described_type ⇒ Object
- #description ⇒ Object
- #description_args ⇒ Object
-
#description_parts ⇒ Object
:nodoc:.
-
#example(description = nil, options = {}, backtrace = nil, &implementation) ⇒ Object
(also: #it, #specify)
Creates an instance of the current example group class and adds it to a collection of examples of the current example group.
-
#example_descriptions ⇒ Object
:nodoc:.
-
#example_group_backtrace ⇒ Object
Deprecated - use backtrace().
- #example_group_hierarchy ⇒ Object
-
#example_implementations ⇒ Object
:nodoc:.
-
#examples(run_options = nil) ⇒ Object
:nodoc:.
- #filtered_description(filter) ⇒ Object
- #include_constants_in(mod) ⇒ Object
-
#inherited(klass) ⇒ Object
:nodoc:.
-
#it_should_behave_like(*shared_example_groups) ⇒ Object
Use this to pull in examples from shared example groups.
- #nested_descriptions ⇒ Object
-
#notify(listener) ⇒ Object
:nodoc:.
-
#number_of_examples ⇒ Object
:nodoc:.
- #pending_implementation ⇒ Object
- #run(run_options) ⇒ Object
- #set_description(*args) ⇒ Object
-
#xexample(description = nil, opts = {}, &block) ⇒ Object
(also: #xit, #xspecify)
Use this to temporarily disable an example.
Methods included from PredicateMatchers
#define_methods_from_predicate_matchers, #predicate_matchers
Methods included from Subject::ExampleGroupMethods
Methods included from BeforeAndAfterHooks
#after_all_parts, #after_each_parts, after_suite_parts, #after_suite_parts, #append_after, #append_before, #before_all_parts, #before_each_parts, before_suite_parts, #before_suite_parts, #prepend_after, #prepend_before
Class Attribute Details
.matcher_class ⇒ Object
Returns the value of attribute matcher_class.
6 7 8 |
# File 'lib/spec/example/example_group_methods.rb', line 6 def matcher_class @matcher_class end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/spec/example/example_group_methods.rb', line 13 def @options end |
#spec_path ⇒ Object (readonly)
Returns the value of attribute spec_path.
13 14 15 |
# File 'lib/spec/example/example_group_methods.rb', line 13 def spec_path @spec_path end |
Instance Method Details
#backtrace ⇒ Object
Provides the backtrace up to where this example_group was declared.
21 22 23 |
# File 'lib/spec/example/example_group_methods.rb', line 21 def backtrace @backtrace end |
#describe(*args, &example_group_block) ⇒ Object Also known as: context
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
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/spec/example/example_group_methods.rb', line 48 def describe(*args, &example_group_block) if example_group_block Spec::Example::add_spec_path_to(args) = args.last if [: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 ⇒ Object
127 128 129 |
# File 'lib/spec/example/example_group_methods.rb', line 127 def described_class @described_class ||= Class === described_type ? described_type : nil end |
#described_type ⇒ Object
123 124 125 |
# File 'lib/spec/example/example_group_methods.rb', line 123 def described_type @described_type ||= description_parts.reverse.find {|part| part.is_a?(Module)} end |
#description ⇒ Object
119 120 121 |
# File 'lib/spec/example/example_group_methods.rb', line 119 def description @description ||= build_description_from(*description_parts) || to_s end |
#description_args ⇒ Object
131 132 133 |
# File 'lib/spec/example/example_group_methods.rb', line 131 def description_args @description_args ||= [] end |
#description_parts ⇒ Object
:nodoc:
135 136 137 138 139 |
# File 'lib/spec/example/example_group_methods.rb', line 135 def description_parts #:nodoc: @description_parts ||= example_group_hierarchy.inject([]) do |parts, example_group_class| [parts << example_group_class.description_args].flatten end end |
#example(description = nil, options = {}, backtrace = nil, &implementation) ⇒ Object Also known as: it, specify
Creates an instance of the current example group class and adds it to a collection of examples of the current example group.
72 73 74 75 76 77 |
# File 'lib/spec/example/example_group_methods.rb', line 72 def example(description=nil, ={}, backtrace=nil, &implementation) example_description = ExampleDescription.new(description, , backtrace || caller(0)[1]) example_descriptions << example_description example_implementations[example_description] = implementation || pending_implementation example_description end |
#example_descriptions ⇒ Object
:nodoc:
141 142 143 |
# File 'lib/spec/example/example_group_methods.rb', line 141 def example_descriptions # :nodoc: @example_descriptions ||= [] end |
#example_group_backtrace ⇒ Object
Deprecated - use backtrace()
26 27 28 29 30 31 32 |
# File 'lib/spec/example/example_group_methods.rb', line 26 def example_group_backtrace Kernel.warn <<-WARNING ExampleGroupMethods#example_group_backtrace is deprecated and will be removed from a future version. Please use ExampleGroupMethods#backtrace instead. WARNING backtrace end |
#example_group_hierarchy ⇒ Object
157 158 159 |
# File 'lib/spec/example/example_group_methods.rb', line 157 def example_group_hierarchy @example_group_hierarchy ||= ExampleGroupHierarchy.new(self) end |
#example_implementations ⇒ Object
:nodoc:
145 146 147 |
# File 'lib/spec/example/example_group_methods.rb', line 145 def example_implementations # :nodoc: @example_implementations ||= {} end |
#examples(run_options = nil) ⇒ Object
:nodoc:
149 150 151 |
# File 'lib/spec/example/example_group_methods.rb', line 149 def examples(=nil) #:nodoc: ( && .reverse) ? example_descriptions.reverse : example_descriptions end |
#filtered_description(filter) ⇒ Object
161 162 163 164 165 166 167 |
# File 'lib/spec/example/example_group_methods.rb', line 161 def filtered_description(filter) build_description_from( *nested_descriptions.collect do |description| description =~ filter ? $1 : description end ) end |
#include_constants_in(mod) ⇒ Object
173 174 175 |
# File 'lib/spec/example/example_group_methods.rb', line 173 def include_constants_in(mod) include mod if (Spec::Ruby.version.to_f >= 1.9) & (Module === mod) & !(Class === mod) end |
#inherited(klass) ⇒ Object
:nodoc:
15 16 17 18 |
# File 'lib/spec/example/example_group_methods.rb', line 15 def inherited(klass) # :nodoc: super ExampleGroupFactory.register_example_group(klass) end |
#it_should_behave_like(*shared_example_groups) ⇒ Object
Use this to pull in examples from shared example groups.
64 65 66 67 68 |
# 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 |
#nested_descriptions ⇒ Object
169 170 171 |
# File 'lib/spec/example/example_group_methods.rb', line 169 def nested_descriptions example_group_hierarchy.nested_descriptions end |
#notify(listener) ⇒ Object
:nodoc:
115 116 117 |
# File 'lib/spec/example/example_group_methods.rb', line 115 def notify(listener) # :nodoc: listener.add_example_group(self) end |
#number_of_examples ⇒ Object
:nodoc:
153 154 155 |
# File 'lib/spec/example/example_group_methods.rb', line 153 def number_of_examples #:nodoc: example_descriptions.length end |
#pending_implementation ⇒ Object
79 80 81 82 |
# File 'lib/spec/example/example_group_methods.rb', line 79 def pending_implementation error = Spec::Example::NotYetImplementedError.new(caller) lambda { raise(error) } end |
#run(run_options) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/spec/example/example_group_methods.rb', line 95 def run() examples = examples_to_run() notify(.reporter) unless examples.empty? return true if examples.empty? return dry_run(examples, ) if .dry_run? define_methods_from_predicate_matchers success, before_all_instance_variables = run_before_all() success, after_all_instance_variables = execute_examples(success, before_all_instance_variables, examples, ) success = run_after_all(success, after_all_instance_variables, ) end |
#set_description(*args) ⇒ Object
108 109 110 111 112 113 |
# File 'lib/spec/example/example_group_methods.rb', line 108 def set_description(*args) @description_args, @options = Spec::Example.(*args) @backtrace = caller(1) @spec_path = File.([:spec_path]) if [:spec_path] self end |
#xexample(description = nil, opts = {}, &block) ⇒ Object Also known as: xit, xspecify
Use this to temporarily disable an example.
88 89 90 |
# File 'lib/spec/example/example_group_methods.rb', line 88 def xexample(description=nil, opts={}, &block) Kernel.warn("Example disabled: #{description}") end |