Class Spec::DSL::Behaviour
In: lib/spec/dsl/behaviour.rb
Parent: Object

Methods

Included Modules

BehaviourEval::InstanceMethods Spec::Plugins::MockFramework

Public Class methods

[Source]

    # File lib/spec/dsl/behaviour.rb, line 8
 8:         def add_shared_behaviour(behaviour)
 9:           return if behaviour.equal?(found_behaviour = find_shared_behaviour(behaviour.description))
10:           raise ArgumentError.new("Shared Behaviour '#{behaviour.description}' already exists") if found_behaviour
11:           shared_behaviours << behaviour
12:         end

[Source]

    # File lib/spec/dsl/behaviour.rb, line 14
14:         def find_shared_behaviour(behaviour_description)
15:           shared_behaviours.find { |b| b.description == behaviour_description }
16:         end

[Source]

    # File lib/spec/dsl/behaviour.rb, line 26
26:       def initialize(*args, &behaviour_block)
27:         init_description(*args)
28:         init_eval_module
29:         before_eval
30:         eval_behaviour(&behaviour_block)
31:       end

[Source]

    # File lib/spec/dsl/behaviour.rb, line 18
18:         def shared_behaviours
19:           # TODO - this needs to be global, or at least accessible from
20:           # from subclasses of Behaviour in a centralized place. I'm not loving
21:           # this as a solution, but it works for now.
22:           $shared_behaviours ||= []
23:         end

Public Instance methods

Includes modules in the Behaviour (the describe block).

[Source]

     # File lib/spec/dsl/behaviour.rb, line 116
116:       def include(*args)
117:         args << {} unless Hash === args.last
118:         modules, options = args_and_options(*args)
119:         required_behaviour_type = options[:behaviour_type]
120:         if required_behaviour_type.nil? || required_behaviour_type.to_sym == behaviour_type.to_sym
121:           @eval_module.include(*modules)
122:         end
123:       end

[Source]

    # File lib/spec/dsl/behaviour.rb, line 88
88:       def matches?(specified_examples)
89:         matcher ||= ExampleMatcher.new(description)
90: 
91:         examples.each do |example|
92:           return true if example.matches?(matcher, specified_examples)
93:         end
94:         return false
95:       end

[Source]

     # File lib/spec/dsl/behaviour.rb, line 109
109:       def methods
110:         my_methods = super
111:         my_methods |= @eval_module.methods
112:         my_methods
113:       end

[Source]

    # File lib/spec/dsl/behaviour.rb, line 84
84:       def number_of_examples
85:         examples.length
86:       end

[Source]

     # File lib/spec/dsl/behaviour.rb, line 101
101:       def retain_examples_matching!(specified_examples)
102:         return if specified_examples.index(description)
103:         matcher = ExampleMatcher.new(description)
104:         examples.reject! do |example|
105:           !example.matches?(matcher, specified_examples)
106:         end
107:       end

[Source]

    # File lib/spec/dsl/behaviour.rb, line 63
63:       def run(reporter, dry_run=false, reverse=false, timeout=nil)
64:         raise "shared behaviours should never run" if shared?
65:         reporter.add_behaviour(description)
66:         prepare_execution_context_class
67:         errors = run_before_all(reporter, dry_run)
68: 
69:         specs = reverse ? examples.reverse : examples
70:         example_execution_context = nil
71:          
72:         if errors.empty?
73:           specs.each do |example|
74:             example_execution_context = execution_context(example)
75:             example_execution_context.copy_instance_variables_from(@before_and_after_all_context_instance) unless before_all_proc(behaviour_type).nil?
76:             example.run(reporter, before_each_proc(behaviour_type), after_each_proc(behaviour_type), dry_run, example_execution_context, timeout)
77:           end
78:         end
79:         
80:         @before_and_after_all_context_instance.copy_instance_variables_from(example_execution_context) unless after_all_proc(behaviour_type).nil?
81:         run_after_all(reporter, dry_run)
82:       end

[Source]

    # File lib/spec/dsl/behaviour.rb, line 97
97:       def shared?
98:         @description[:shared]
99:       end

Protected Instance methods

[Source]

    # File lib/spec/dsl/behaviour.rb, line 58
58:       def before_eval
59:       end

[Source]

     # File lib/spec/dsl/behaviour.rb, line 203
203:       def described_type
204:         @description.described_type
205:       end

[Source]

     # File lib/spec/dsl/behaviour.rb, line 199
199:       def description
200:         @description.to_s
201:       end

[Source]

     # File lib/spec/dsl/behaviour.rb, line 158
158:       def execution_context(example)
159:         execution_context_class.new(example)
160:       end

Messages that this class does not understand are passed directly to the @eval_module.

[Source]

     # File lib/spec/dsl/behaviour.rb, line 133
133:       def method_missing(sym, *args, &block)
134:         @eval_module.send(sym, *args, &block)
135:       end

[Source]

     # File lib/spec/dsl/behaviour.rb, line 189
189:       def plugin_mock_framework
190:         case mock_framework = Spec::Runner.configuration.mock_framework
191:         when Module
192:           include mock_framework
193:         else
194:           require Spec::Runner.configuration.mock_framework
195:           include Spec::Plugins::MockFramework
196:         end
197:       end

[Source]

     # File lib/spec/dsl/behaviour.rb, line 137
137:       def prepare_execution_context_class
138:         plugin_mock_framework
139:         weave_in_included_modules
140:         define_predicate_matchers #this is in behaviour_eval
141:         execution_context_class
142:       end

[Source]

     # File lib/spec/dsl/behaviour.rb, line 177
177:       def run_after_all(reporter, dry_run)
178:         unless dry_run
179:           begin 
180:             @before_and_after_all_context_instance ||= execution_context(nil) 
181:             @before_and_after_all_context_instance.instance_eval(&after_all_proc(behaviour_type)) 
182:           rescue => e
183:             location = "after(:all)"
184:             reporter.example_finished(location, e, location) if reporter
185:           end
186:         end
187:       end

[Source]

     # File lib/spec/dsl/behaviour.rb, line 162
162:       def run_before_all(reporter, dry_run)
163:         errors = []
164:         unless dry_run
165:           begin
166:             @before_and_after_all_context_instance = execution_context(nil)
167:             @before_and_after_all_context_instance.instance_eval(&before_all_proc(behaviour_type))
168:           rescue => e
169:             errors << e
170:             location = "before(:all)"
171:             reporter.example_finished(location, e, location) if reporter
172:           end
173:         end
174:         errors
175:       end

[Source]

     # File lib/spec/dsl/behaviour.rb, line 144
144:       def weave_in_included_modules
145:         mods = included_modules
146:         eval_module = @eval_module
147:         execution_context_class.class_eval do
148:           include eval_module
149:           Spec::Runner.configuration.included_modules.each do |mod|
150:             include mod
151:           end
152:           mods.each do |mod|
153:             include mod
154:           end
155:         end
156:       end

[Validate]