Class: Bacon::Context
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#after(&block) ⇒ Object
-
#before(&block) ⇒ Object
-
#behaves_like(*names) ⇒ Object
-
#change?(*args, &block) ⇒ Boolean
-
#describe(*args, &block) ⇒ Object
-
#focus(spec_str) ⇒ Object
-
#focus_context(context_str) ⇒ Object
-
#freeze_time(*args, &block) ⇒ Object
-
#initialize(name, toplevel = false, &block) ⇒ Context
constructor
A new instance of Context.
-
#it(description, &block) ⇒ Object
-
#raise?(*args, &block) ⇒ Boolean
-
#should(label, *args, &block) ⇒ Object
-
#throw?(*args, &block) ⇒ Boolean
#create_context, #execute_spec, #run, #run_requirement
Constructor Details
#initialize(name, toplevel = false, &block) ⇒ Context
Returns a new instance of Context.
175
176
177
178
179
180
|
# File 'lib/bacon.rb', line 175
def initialize(name, toplevel = false, &block)
@name = name
@before, @after = [], []
@block = block
@toplevel = toplevel
end
|
Instance Attribute Details
Returns the value of attribute block.
171
172
173
|
# File 'lib/bacon.rb', line 171
def block
@block
end
|
Returns the value of attribute name.
171
172
173
|
# File 'lib/bacon.rb', line 171
def name
@name
end
|
Returns the value of attribute toplevel.
171
172
173
|
# File 'lib/bacon.rb', line 171
def toplevel
@toplevel
end
|
Instance Method Details
#after(&block) ⇒ Object
183
|
# File 'lib/bacon.rb', line 183
def after(&block); @after << block; end
|
#before(&block) ⇒ Object
182
|
# File 'lib/bacon.rb', line 182
def before(&block); @before << block; end
|
#behaves_like(*names) ⇒ Object
185
186
187
|
# File 'lib/bacon.rb', line 185
def behaves_like(*names)
names.each { |name| instance_eval(&Shared[name]) }
end
|
#change?(*args, &block) ⇒ Boolean
230
|
# File 'lib/bacon.rb', line 230
def change?(*args, &block); block.change?(*args); end
|
#describe(*args, &block) ⇒ Object
197
198
199
200
201
202
203
204
205
206
207
208
|
# File 'lib/bacon.rb', line 197
def describe(*args, &block)
context = create_context(args.join(' '), &block)
(parent_context = self).methods(false).each {|e|
class<<context; self end.send(:define_method, e) {|*args| parent_context.send(e, *args)}
}
@before.each { |b| context.before(&b) }
@after.each { |b| context.after(&b) }
context.run
end
|
#focus(spec_str) ⇒ Object
210
211
212
213
|
# File 'lib/bacon.rb', line 210
def focus(spec_str)
raise "focused test forbidden" unless Bacon::allow_focused_run?
Bacon::focus_name_regexp = %r{#{spec_str}}
end
|
#focus_context(context_str) ⇒ Object
215
216
217
218
|
# File 'lib/bacon.rb', line 215
def focus_context(context_str)
raise "focused test forbidden" unless Bacon::allow_focused_run?
Bacon::focus_context_regexp = %r{#{context_str}}
end
|
#freeze_time(*args, &block) ⇒ Object
23
24
25
|
# File 'lib/bacon/ext/mocha.rb', line 23
def freeze_time(*args, &block)
Bacon.freeze_time(*args, &block)
end
|
#it(description, &block) ⇒ Object
220
221
222
223
224
225
226
|
# File 'lib/bacon.rb', line 220
def it(description, &block)
return unless name =~ Bacon::focus_context_regexp
return unless description =~ Bacon::focus_name_regexp
block ||= lambda { should.flunk "not implemented" }
Counter[:specifications] += 1
run_requirement description, block
end
|
#raise?(*args, &block) ⇒ Boolean
228
|
# File 'lib/bacon.rb', line 228
def raise?(*args, &block); block.raise?(*args); end
|
#should(label, *args, &block) ⇒ Object
189
190
191
192
193
194
195
|
# File 'lib/bacon.rb', line 189
def should(label, *args, &block)
if Counter[:depth]==0
it("should #{label}",&block)
else
super(label, *args,&block)
end
end
|
#throw?(*args, &block) ⇒ Boolean
229
|
# File 'lib/bacon.rb', line 229
def throw?(*args, &block); block.throw?(*args); end
|