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
-
#location ⇒ Object
readonly
Returns the value of attribute location.
Attributes included from Subject::ExampleGroupMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#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_group_hierarchy ⇒ Object
-
#example_implementations ⇒ Object
:nodoc:.
-
#example_proxies ⇒ Object
:nodoc:.
-
#examples(run_options = nil) ⇒ Object
:nodoc:.
- #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.
- #let(name, &block) ⇒ Object
- #nested_descriptions ⇒ Object
-
#notify(reporter) ⇒ Object
:nodoc:.
-
#number_of_examples ⇒ Object
:nodoc:.
-
#options ⇒ 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 ArgsAndOptions
#add_options, #args_and_options, #set_location
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
#location ⇒ Object (readonly)
Returns the value of attribute location.
22 23 24 |
# File 'lib/spec/example/example_group_methods.rb', line 22 def location @location end |
Class Method Details
.build_description_from(*args) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/spec/example/example_group_methods.rb', line 8 def build_description_from(*args) text = args.inject("") do |description, arg| description << " " unless (description == "" || arg.to_s =~ /^(\s|\.|#)/) description << arg.to_s end text == "" ? nil : text end |
Instance Method Details
#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
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/spec/example/example_group_methods.rb', line 47 def describe(*args, &example_group_block) raise Spec::Example::NoDescriptionError.new("example group", caller(0)[1]) if args.empty? if example_group_block = (args) set_location(, caller(0)[1]) 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
126 127 128 |
# File 'lib/spec/example/example_group_methods.rb', line 126 def described_class @described_class ||= Class === described_type ? described_type : nil end |
#described_type ⇒ Object
122 123 124 |
# File 'lib/spec/example/example_group_methods.rb', line 122 def described_type @described_type ||= description_parts.reverse.find {|part| part.is_a?(Module)} end |
#description ⇒ Object
118 119 120 |
# File 'lib/spec/example/example_group_methods.rb', line 118 def description @description ||= ExampleGroupMethods.build_description_from(*description_parts) || to_s end |
#description_args ⇒ Object
130 131 132 |
# File 'lib/spec/example/example_group_methods.rb', line 130 def description_args @description_args ||= [] end |
#description_parts ⇒ Object
:nodoc:
134 135 136 137 138 |
# File 'lib/spec/example/example_group_methods.rb', line 134 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_proxy = ExampleProxy.new(description, , backtrace || caller(0)[1]) example_proxies << example_proxy example_implementations[example_proxy] = implementation || pending_implementation example_proxy end |
#example_group_hierarchy ⇒ Object
156 157 158 |
# File 'lib/spec/example/example_group_methods.rb', line 156 def example_group_hierarchy @example_group_hierarchy ||= ExampleGroupHierarchy.new(self) end |
#example_implementations ⇒ Object
:nodoc:
144 145 146 |
# File 'lib/spec/example/example_group_methods.rb', line 144 def example_implementations # :nodoc: @example_implementations ||= {} end |
#example_proxies ⇒ Object
:nodoc:
140 141 142 |
# File 'lib/spec/example/example_group_methods.rb', line 140 def example_proxies # :nodoc: @example_proxies ||= [] end |
#examples(run_options = nil) ⇒ Object
:nodoc:
148 149 150 |
# File 'lib/spec/example/example_group_methods.rb', line 148 def examples(=nil) #:nodoc: ( && .reverse) ? example_proxies.reverse : example_proxies end |
#include_constants_in(mod) ⇒ Object
164 165 166 |
# File 'lib/spec/example/example_group_methods.rb', line 164 def include_constants_in(mod) include mod if (Spec::Ruby.version.to_f >= 1.9) & (Module === mod) & !(Class === mod) end |
#inherited(klass) ⇒ Object
:nodoc:
28 29 30 31 |
# File 'lib/spec/example/example_group_methods.rb', line 28 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 |
#let(name, &block) ⇒ Object
168 169 170 171 172 173 |
# File 'lib/spec/example/example_group_methods.rb', line 168 def let(name, &block) define_method name do @assignments ||= {} @assignments[name] ||= instance_eval(&block) end end |
#nested_descriptions ⇒ Object
160 161 162 |
# File 'lib/spec/example/example_group_methods.rb', line 160 def nested_descriptions example_group_hierarchy.nested_descriptions end |
#notify(reporter) ⇒ Object
:nodoc:
114 115 116 |
# File 'lib/spec/example/example_group_methods.rb', line 114 def notify(reporter) # :nodoc: reporter.example_group_started(ExampleGroupProxy.new(self)) end |
#number_of_examples ⇒ Object
:nodoc:
152 153 154 |
# File 'lib/spec/example/example_group_methods.rb', line 152 def number_of_examples #:nodoc: example_proxies.length end |
#options ⇒ Object
:nodoc:
24 25 26 |
# File 'lib/spec/example/example_group_methods.rb', line 24 def # :nodoc: @options ||= {} end |
#pending_implementation ⇒ Object
79 80 81 |
# File 'lib/spec/example/example_group_methods.rb', line 79 def pending_implementation lambda { raise(Spec::Example::NotYetImplementedError) } end |
#run(run_options) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/spec/example/example_group_methods.rb', line 94 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 = run_examples(success, before_all_instance_variables, examples, ) success = run_after_all(success, after_all_instance_variables, ) end |
#set_description(*args) ⇒ Object
107 108 109 110 111 112 |
# File 'lib/spec/example/example_group_methods.rb', line 107 def set_description(*args) @description_args, @options = (*args) @backtrace = caller(1) @location = File.([:location]) if [:location] self end |