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:           return if found_behaviour and behaviour.description[:spec_path] == found_behaviour.description[:spec_path]
11:           raise ArgumentError.new("Shared Behaviour '#{behaviour.description}' already exists") if found_behaviour
12:           shared_behaviours << behaviour
13:         end

[Source]

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

[Source]

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

[Source]

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

Public Instance methods

Includes modules in the Behaviour (the describe block).

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

Protected Instance methods

[Source]

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

[Source]

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

[Source]

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

[Source]

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

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Validate]