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:.
- #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
122 123 124 |
# File 'lib/spec/example/example_group_methods.rb', line 122 def described_class @described_class ||= Class === described_type ? described_type : nil end |
#described_type ⇒ Object
118 119 120 |
# File 'lib/spec/example/example_group_methods.rb', line 118 def described_type @described_type ||= description_parts.reverse.find {|part| part.is_a?(Module)} end |
#description ⇒ Object
114 115 116 |
# File 'lib/spec/example/example_group_methods.rb', line 114 def description @description ||= build_description_from(*description_parts) || to_s end |
#description_args ⇒ Object
126 127 128 |
# File 'lib/spec/example/example_group_methods.rb', line 126 def description_args @description_args ||= [] end |
#description_parts ⇒ Object
:nodoc:
130 131 132 133 134 |
# File 'lib/spec/example/example_group_methods.rb', line 130 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 example_description end |
#example_descriptions ⇒ Object
:nodoc:
136 137 138 |
# File 'lib/spec/example/example_group_methods.rb', line 136 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
152 153 154 |
# File 'lib/spec/example/example_group_methods.rb', line 152 def example_group_hierarchy @example_group_hierarchy ||= ExampleGroupHierarchy.new(self) end |
#example_implementations ⇒ Object
:nodoc:
140 141 142 |
# File 'lib/spec/example/example_group_methods.rb', line 140 def example_implementations # :nodoc: @example_implementations ||= {} end |
#examples(run_options = nil) ⇒ Object
:nodoc:
144 145 146 |
# File 'lib/spec/example/example_group_methods.rb', line 144 def examples(=nil) #:nodoc: ( && .reverse) ? example_descriptions.reverse : example_descriptions end |
#filtered_description(filter) ⇒ Object
156 157 158 159 160 161 162 |
# File 'lib/spec/example/example_group_methods.rb', line 156 def filtered_description(filter) build_description_from( *nested_descriptions.collect do |description| description =~ filter ? $1 : description end ) end |
#include_constants_in(mod) ⇒ Object
168 169 170 |
# File 'lib/spec/example/example_group_methods.rb', line 168 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
164 165 166 |
# File 'lib/spec/example/example_group_methods.rb', line 164 def nested_descriptions example_group_hierarchy.nested_descriptions end |
#notify(listener) ⇒ Object
:nodoc:
110 111 112 |
# File 'lib/spec/example/example_group_methods.rb', line 110 def notify(listener) # :nodoc: listener.add_example_group(self) end |
#number_of_examples ⇒ Object
:nodoc:
148 149 150 |
# File 'lib/spec/example/example_group_methods.rb', line 148 def number_of_examples #:nodoc: example_descriptions.length end |
#run(run_options) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/spec/example/example_group_methods.rb', line 90 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
103 104 105 106 107 108 |
# File 'lib/spec/example/example_group_methods.rb', line 103 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.
83 84 85 |
# File 'lib/spec/example/example_group_methods.rb', line 83 def xexample(description=nil, opts={}, &block) Kernel.warn("Example disabled: #{description}") end |