summaryrefslogtreecommitdiff
path: root/spec/mspec/lib/mspec/runner/context.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/mspec/lib/mspec/runner/context.rb')
-rw-r--r--spec/mspec/lib/mspec/runner/context.rb33
1 files changed, 14 insertions, 19 deletions
diff --git a/spec/mspec/lib/mspec/runner/context.rb b/spec/mspec/lib/mspec/runner/context.rb
index d55b0dcd9e..62483590bb 100644
--- a/spec/mspec/lib/mspec/runner/context.rb
+++ b/spec/mspec/lib/mspec/runner/context.rb
@@ -12,15 +12,14 @@
class ContextState
attr_reader :state, :parent, :parents, :children, :examples, :to_s
- def initialize(mod, options = nil)
- @to_s = mod.to_s
- if options.is_a? Hash
- @options = options
- else
- @to_s += "#{".:#".include?(options[0,1]) ? "" : " "}#{options}" if options
- @options = { }
- end
- @options[:shared] ||= false
+ MOCK_VERIFY = -> { Mock.verify_count }
+ MOCK_CLEANUP = -> { Mock.cleanup }
+ EXPECTATION_MISSING = -> { raise SpecExpectationNotFoundError }
+
+ def initialize(description, options = nil)
+ raise "#describe options should be a Hash or nil" unless Hash === options or options.nil?
+ @to_s = description.to_s
+ @shared = options && options[:shared]
@parsed = false
@before = { :all => [], :each => [] }
@@ -32,10 +31,6 @@ class ContextState
@parent = nil
@parents = [self]
@children = []
-
- @mock_verify = Proc.new { Mock.verify_count }
- @mock_cleanup = Proc.new { Mock.cleanup }
- @expectation_missing = Proc.new { raise SpecExpectationNotFoundError }
end
# Remove caching when a ContextState is dup'd for shared specs.
@@ -47,7 +42,7 @@ class ContextState
# Returns true if this is a shared +ContextState+. Essentially, when
# created with: describe "Something", :shared => true { ... }
def shared?
- return @options[:shared]
+ @shared
end
# Set the parent (enclosing) +ContextState+ for this state. Creates
@@ -207,7 +202,7 @@ class ContextState
if protect "before :all", pre(:all)
@examples.each do |state|
MSpec.repeat do
- @state = state
+ @state = state
example = state.example
MSpec.actions :before, state
@@ -216,20 +211,20 @@ class ContextState
if example
passed = protect nil, example
MSpec.actions :example, state, example
- protect nil, @expectation_missing if !MSpec.expectation? and passed
+ protect nil, EXPECTATION_MISSING if !MSpec.expectation? and passed
end
end
protect "after :each", post(:each)
- protect "Mock.verify_count", @mock_verify
+ protect "Mock.verify_count", MOCK_VERIFY
- protect "Mock.cleanup", @mock_cleanup
+ protect "Mock.cleanup", MOCK_CLEANUP
MSpec.actions :after, state
@state = nil
end
end
protect "after :all", post(:all)
else
- protect "Mock.cleanup", @mock_cleanup
+ protect "Mock.cleanup", MOCK_CLEANUP
end
MSpec.actions :leave